# Search Files — Google Drive

> Search for files and folders in Google Drive using the Drive query language. This is the primary tool for finding files, folders, spreadsheets, forms, and any other Drive item. Returns matching files with their IDs, names, MIME types, and…

- Key: `google_drive-search-files`
- Type: Action (Read-only)
- Version: 0.0.4
- App: Google Drive (`google_drive`) — https://pipedream.com/apps/google-drive.md
- This page (HTML): https://pipedream.com/apps/google-drive/actions/search-files
- Hints: read-only · open-world
- Source: https://github.com/PipedreamHQ/pipedream/blob/master/components/google_drive/actions/search-files/search-files.mjs

## Description

Search for files and folders in Google Drive using the Drive query language. This is the primary tool for finding files, folders, spreadsheets, forms, and any other Drive item. Returns matching files with their IDs, names, MIME types, and parent folder IDs.

**Query syntax** — pass a Drive search query string. Examples:
- Find by name: `name contains 'Budget'`
- Exact name match: `name = 'Q4 Report'`
- Folders only: `mimeType = 'application/vnd.google-apps.folder'`
- Google Docs: `mimeType = 'application/vnd.google-apps.document'`
- Spreadsheets: `mimeType = 'application/vnd.google-apps.spreadsheet'`
- Files in a folder: `'FOLDER_ID' in parents`
- Not trashed: `trashed = false`
- Modified after date: `modifiedTime > '2024-01-01T00:00:00'`
- Combine with AND: `name contains 'Report' and mimeType = 'application/vnd.google-apps.document'`
- Owner filter: `'user@example.com' in owners`

When the user says 'my files', use **Get User Details** first to get the owner email. To scope to a shared drive, pass the `driveId` from **List Shared Drives**. [See the documentation](https://developers.google.com/drive/api/v3/search-files)

## Props

| Prop | Type | Required | Description |
|---|---|---|---|
| `query` | `string` | Yes | A Drive search query string. See the tool description for syntax examples. Common queries: name contains 'keyword', mimeType = 'application/vnd.google-apps.folder', 'FOLDER_ID' in parents, trashed = false. |
| `driveId` | `string` | No | Optional. Scope the search to a specific shared drive. Use List Shared Drives to find available drive IDs. Omit to search My Drive. |
| `includeItemsFromAllDrives` | `boolean` | No | If true, include results from all drives (My Drive and shared drives). Defaults to false. |

## Run it

**MCP**

```ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js"
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const accessToken = await pd.rawAccessToken

const transport = new StreamableHTTPClientTransport(
  new URL("https://remote.mcp.pipedream.net/v3"),
  {
    requestInit: {
      headers: {
        Authorization: `Bearer ${accessToken}`,
        "x-pd-project-id": process.env.PIPEDREAM_PROJECT_ID!,
        "x-pd-environment": "production",
        "x-pd-external-user-id": "{external_user_id}", // any stable ID for this user in your system
        "x-pd-app-slug": "google_drive",
      },
    },
  },
)

const mcp = new Client({ name: "my-agent", version: "1.0.0" })
await mcp.connect(transport)

const { tools } = await mcp.listTools()

// listTools() hands your model this tool's input schema, so it can
// fill the arguments itself:
const result = await mcp.callTool({
  name: "google_drive-search-files",
  arguments: {
    query: "Query",
    driveId: "Drive ID",
  },
})
```

**TypeScript**

```ts
import { PipedreamClient } from "@pipedream/sdk"

const pd = new PipedreamClient({
  projectId: process.env.PIPEDREAM_PROJECT_ID!,
  clientId: process.env.PIPEDREAM_CLIENT_ID!,
  clientSecret: process.env.PIPEDREAM_CLIENT_SECRET!,
  projectEnvironment: "production",
})

const result = await pd.actions.run({
  id: "google_drive-search-files",
  externalUserId: "{external_user_id}", // any stable ID for this user in your system
  configuredProps: {
    google_drive: { authProvisionId: "apn_xxxxxxx" },
    query: "Query",
    driveId: "Drive ID",
  },
})

console.log(result)
```

**cURL**

```bash
curl -X POST https://api.pipedream.com/v1/connect/{project_id}/actions/run \
  -H "Content-Type: application/json" \
  -H "X-PD-Environment: production" \
  -H "Authorization: Bearer {access_token}" \
  -d '{
    "external_user_id": "{external_user_id}",
    "id": "google_drive-search-files",
    "configured_props": {
      "google_drive": { "authProvisionId": "apn_xxxxxxx" },
      "query": "Query",
      "driveId": "Drive ID"
    }
  }'
```

---

- App: https://pipedream.com/apps/google-drive.md · All apps: https://pipedream.com/apps
