Tool: search_files
Call this tool to search for Drive files given a structured query.
The query field requires the use of query search operators.
A query string contains the following three parts: query_term operator values where:
query_termis the query term or field to search upon.operatorspecifies the condition for the query term.valuesare the specific values to use to filter your search results.
Query Terms
The following table lists valid query terms with their descriptions:
| Query Term | Valid operators | Usage |
|---|---|---|
title |
contains, =, != |
Title of the file. Surround with single quotes ('). Escape single quotes in queries with \', such as 'Valentine\'s Day'. |
fullText |
contains |
Whether the title or text in the file's content matches. Surround with single quotes ('). Escape single quotes in queries with \', such as 'Valentine\'s Day'. |
mimeType |
contains, =, != |
MIME type of the file. Surround with single quotes ('). Escape single quotes in queries with \', such as 'Valentine\'s Day'. |
modifiedTime |
<=, <, =, !=, >, >= |
Date of the last file modification. RFC 3339 format, default time zone is UTC, such as 2012-06-04T12:00:00-08:00. Fields of type date are not comparable. |
viewedByMeTime |
<=, <, =, !=, >, >= |
Date that the user last viewed a file. RFC 3339 format, default time zone is UTC, such as 2012-06-04T12:00:00-08:00. Fields of type date are not comparable. |
parentId |
=, != |
Whether the parent equals the specified ID. root can be used to specify the user's "My Drive" that functions as their primary hierarchy. |
owner |
=, != |
User who owns the file. me can be used to specify the user that is making the request. |
sharedWithMe |
=, != |
Files that are in the user's "Shared with me" collection. All file users are in the file's Access Control List (ACL). Can be either true or false. |
createdTime |
<=, <, =, !=, >, >= |
Date when the file was created. Use RFC 3339 format, default time zone is UTC, such as 2012-06-04T12:00:00-08:00. |
Query Operators
The following table lists valid query operators:
| Operator | Usage |
|---|---|
contains |
The content of one string is present in the other. |
= |
The content of a string or boolean is equal to the other. |
!= |
The content of a string or boolean is not equal to the other. |
< |
A value is less than another. |
<= |
A value is less than or equal to another. |
> |
A value is greater than another. |
>= |
A value is greater than or equal to another. |
in |
An element is contained within a collection. |
and |
Return items that match both queries. |
or |
Return items that match either query. |
not |
Negates a search query. |
has |
A collection contains an element matching the parameters. |
Some examples of queries include:
title contains 'hello' and title contains 'goodbye'modifiedTime > '2024-01-01T00:00:00Z' and (mimeType contains 'image/' or mimeType contains 'video/')parentId = '1234567'fullText contains 'hello'owner = 'test@example.org'sharedWithMe = trueowner = 'me'(for files owned by the user)
Utilize next_page_token to paginate through the results. An empty response indicates that there are either no results or no more results to return.
The following sample demonstrate how to use curl to invoke the search_files MCP tool.
| Curl Request |
|---|
curl --location 'https://drivemcp.googleapis.com/mcp' \ --header 'content-type: application/json' \ --header 'accept: application/json, text/event-stream' \ --data '{ "method": "tools/call", "params": { "name": "search_files", "arguments": { // provide these details according to the tool MCP specification } }, "jsonrpc": "2.0", "id": 1 }' |
Input Schema
Request to search files.
SearchFilesRequest
| JSON representation |
|---|
{ "query": string, "pageToken": string "pageSize": integer "excludeContentSnippets": boolean } |
| Fields | |
|---|---|
query |
The search query. |
Union field
|
|
pageToken |
The page token to use for pagination. |
Union field
|
|
pageSize |
The maximum number of files to return in each page. |
Union field
|
|
excludeContentSnippets |
If true, the content snippet will be excluded from the response. |
Output Schema
Response to search files.
SearchFilesResponse
| JSON representation |
|---|
{
"files": [
{
object ( |
| Fields | |
|---|---|
files[] |
Output only. The list of files. |
Union field
|
|
nextPageToken |
The next page token. |
File
| JSON representation |
|---|
{ "id": string, "title": string, "parentId": string, "mimeType": string "fileSize": string "description": string "fileExtension": string "contentSnippet": string "viewUrl": string "sharedWithMeTime": string "createdTime": string "modifiedTime": string "viewedByMeTime": string "owner": string } |
| Fields | |
|---|---|
id |
The id of the file that was fetched. |
title |
The title of the file. |
parentId |
The (optional) id of the parent of the file. |
Union field
|
|
mimeType |
The mime type of the file. |
Union field
|
|
fileSize |
The size in bytes of the file. |
Union field
|
|
description |
The description of the file. |
Union field
|
|
fileExtension |
The original file extension of the file, this is only populated for files with content stored in Drive. |
Union field
|
|
contentSnippet |
Generated snippet about the content of the file. |
Union field
|
|
viewUrl |
The URL to view the file. |
Union field
|
|
sharedWithMeTime |
The time that the file was shared with the requester. Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: |
Union field
|
|
createdTime |
The time that the file was created. Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: |
Union field
|
|
modifiedTime |
The most recent time at which the file was modified. Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: |
Union field
|
|
viewedByMeTime |
The most recent time at which the file was viewed by requester. Uses RFC 3339, where generated output will always be Z-normalized and use 0, 3, 6 or 9 fractional digits. Offsets other than "Z" are also accepted. Examples: |
Union field
|
|
owner |
The email address of the owner of the file. |
Timestamp
| JSON representation |
|---|
{ "seconds": string, "nanos": integer } |
| Fields | |
|---|---|
seconds |
Represents seconds of UTC time since Unix epoch 1970-01-01T00:00:00Z. Must be between -62135596800 and 253402300799 inclusive (which corresponds to 0001-01-01T00:00:00Z to 9999-12-31T23:59:59Z). |
nanos |
Non-negative fractions of a second at nanosecond resolution. This field is the nanosecond portion of the duration, not an alternative to seconds. Negative second values with fractions must still have non-negative nanos values that count forward in time. Must be between 0 and 999,999,999 inclusive. |
Tool Annotations
Destructive Hint: ❌ | Idempotent Hint: ✅ | Read Only Hint: ✅ | Open World Hint: ❌