返回市场
谷歌文档MCP服务器

谷歌文档MCP服务器

作者:highlight-ing2 星标更新:2025-04-05

项目介绍

Google Docs MCP 服务器

这是一个用于 Google Docs API 的模型上下文协议(MCP)服务器,允许语言模型创建、搜索、追加内容以及更新 Google 文档。

功能

  • 搜索文档:使用自定义查询在 Drive 中搜索 Google 文档
  • 创建文档:创建新的 Google 文档,并可选地添加初始内容
  • 追加到文档:在现有 Google 文档的末尾追加内容
  • 更新文档:用新内容替换现有 Google 文档中的内容

安装

先决条件

  • Node.js(v14 或更高版本)
  • npm
  • 启用了 Google Drive 和 Google Docs API 的 Google Cloud Platform 账户

安装步骤

  1. 克隆此仓库:

    git clone <repository-url>
    cd google-docs-mcp-server
    
  2. 安装依赖项:

    npm install
    
  3. 设置 Google API 凭据:

    • 访问 Google Cloud 控制台
    • 创建一个新项目(或选择一个现有项目)
    • 启用 Google Drive API 和 Google Docs API
    • 创建 OAuth 2.0 凭据(桌面应用)
    • 下载凭据 JSON 文件并将其保存为项目根目录下的 credentials.json
  4. 获取认证令牌:

    node get-refresh-token.js
    

    按照浏览器提示授权应用程序。这将创建一个 token.json 文件。

  5. 构建服务器:

    npm run build
    

构建 Extism 插件

服务器使用 Extism WebAssembly 插件与 Google Docs API 进行交互。要构建插件:

cd extism-plugin
npm install
npm run build

这将在 dist 目录中创建 plugin.wasm 文件。

使用方法

运行服务器

启动 MCP 服务器:

npm start

或者使用显式的 node 命令:

node build/index.js

直接测试插件

您可以使用 Extism CLI 直接测试 Extism 插件:

cd extism-plugin
extism call --wasi --allow-host www.googleapis.com --allow-host docs.googleapis.com --config GOOGLE_ACCESS_TOKEN=<your-access-token> dist/plugin.wasm describe

搜索文档:

extism call --wasi --allow-host www.googleapis.com --allow-host docs.googleapis.com --config GOOGLE_ACCESS_TOKEN=<your-access-token> dist/plugin.wasm call --input '{"toolId": "search_docs", "arguments": {"query": "name contains \"report\""}}'

创建新文档:

extism call --wasi --allow-host www.googleapis.com --allow-host docs.googleapis.com --config GOOGLE_ACCESS_TOKEN=<your-access-token> dist/plugin.wasm call --input '{"toolId": "create_doc", "arguments": {"title": "我的新文档", "content": "初始内容"}}'

许可证

MIT