工具:read_file_content
调用此工具可获取 Drive 文件的自然语言表示形式,并可选择获取其评论。
对于非常大的文件,文件内容可能不完整。文本表示形式会随时间变化,因此请勿对该工具返回的文本的特定格式做出假设。如果支持,评论标记将包含在内容中。
支持的 MIME 类型:
application/vnd.google-apps.documentapplication/vnd.google-apps.presentationapplication/vnd.google-apps.spreadsheetapplication/pdfapplication/mswordapplication/vnd.openxmlformats-officedocument.wordprocessingml.documentapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetapplication/vnd.openxmlformats-officedocument.presentationml.presentationapplication/vnd.oasis.opendocument.spreadsheetapplication/vnd.oasis.opendocument.presentationapplication/x-vnd.oasis.opendocument.textimage/pngimage/jpegimage/jpg
如果找不到文件,请尝试使用其他工具(例如 search_files)通过关键字查找用户请求的文件。
以下示例演示了如何使用 curl 调用 read_file_content MCP 工具。
| Curl 请求 |
|---|
curl --location 'https://drivemcp.googleapis.com/mcp/v1' \ --header 'Authorization: Bearer YOUR_ACCESS_TOKEN' \ --header 'content-type: application/json' \ --header 'accept: application/json, text/event-stream' \ --data '{ "method": "tools/call", "params": { "name": "read_file_content", "arguments": { // provide these details according to the tool's MCP specification } }, "jsonrpc": "2.0", "id": 1 }' |
输入架构
请求读取文件内容,并支持获取评论。
ReadFileContentRequest
| JSON 表示法 |
|---|
{ "fileId": string, "includeComments": boolean } |
| 字段 | |
|---|---|
fileId |
必需。要检索的文件的 ID。 |
includeComments |
是否在响应中包含评论。评论将以内嵌方式显示在文件的文本内容中,并映射到评论串。 |
输出架构
读取文件内容的响应。
ReadFileContentResponse
| JSON 表示法 |
|---|
{ "contentAnchoredComments": [ { object ( |
| 字段 | |
|---|---|
contentAnchoredComments[] |
返回的 file_content 中引用的评论串。 |
unanchoredComments[] |
无法锚定到返回的文件中的特定内容的评论串。 |
联合字段
|
|
fileContent |
以文本格式返回的 Drive 文件内容。如果文件不支持文本格式,则可能为空。如果请求中的 include_comments 为 true,则可以包含评论引用。 |
联合字段
|
|
textFormattingNotSupported |
此文件是否支持文本格式。如果为 true,则 file_content 将为空。 |
联合字段
|
|
commentsNotSupported |
此文件是否支持返回评论。仅当请求中的 include_comments 为 true 且不支持评论时,此字段才会显示。 |
CommentThread
| JSON 表示法 |
|---|
{ "replies": [ { object ( |
| 字段 | |
|---|---|
replies[] |
对评论串中第一条帖子的回复。 |
联合字段
|
|
commentId |
评论串的 ID。此 ID 与初始评论的 ID 相同。 |
联合字段
|
|
status |
评论串的状态。 |
联合字段
|
|
headPost |
评论串中的第一条帖子。 |
Post
| JSON 表示法 |
|---|
{ "postId": string "content": string "authorName": string "modifiedTime": string } |
| 字段 | |
|---|---|
联合字段
|
|
postId |
帖子的 ID。 |
联合字段
|
|
content |
帖子的内容。 |
联合字段
|
|
authorName |
帖子作者的姓名。 |
联合字段
|
|
modifiedTime |
上次修改帖子的时间。 采用 RFC 3339 标准,生成的输出将始终进行 Z 规范化(即转换为 UTC 零时区格式并在末尾附加 Z),并使用 0、3、6 或 9 个小数位。不进行“Z”归一化处理的偏差时间也是可以接受的。示例: |
时间戳
| JSON 表示法 |
|---|
{ "seconds": string, "nanos": integer } |
| 字段 | |
|---|---|
seconds |
表示世界协调时间 (UTC) 的秒数(从 Unix 纪元 1970-01-01T00:00:00Z 开始算起)。必须介于 -62135596800 和 253402300799 之间(含边界值),对应于 0001-01-01T00:00:00Z 到 9999-12-31T23:59:59Z。 |
nanos |
秒数的非负小数部分(以纳秒为单位)。此字段是时长的纳秒部分,而不是秒的替代值。对于含小数部分的负秒数,仍必须包含按时间递升的非负纳秒值。必须在 0 到 999,999,999 之间(含边界值)。 |
状态
定义评论串的状态。
| 枚举 | |
|---|---|
STATUS_UNSPECIFIED |
|
OPEN |
|
RESOLVED |
|
工具注释
破坏性提示:❌ | 等幂性提示:✅ | 只读提示:✅ | 开放世界提示:❌
授权范围
需要以下 OAuth 范围之一:
https://www.googleapis.com/auth/drivehttps://www.googleapis.com/auth/drive.appdatahttps://www.googleapis.com/auth/drive.filehttps://www.googleapis.com/auth/drive.meet.readonlyhttps://www.googleapis.com/auth/drive.metadatahttps://www.googleapis.com/auth/drive.metadata.readonlyhttps://www.googleapis.com/auth/drive.photos.readonlyhttps://www.googleapis.com/auth/drive.readonly