Google Docs MCP Server

Integrations

  • Enables reading, creating, updating, and searching Google Docs documents through the Google Docs API, allowing AI agents to manipulate document content programmatically.

  • Facilitates interaction with Google Drive for document management, including search functionality and authorization for accessing Google Docs content.

Google Docs MCP Server

This project provides an MCP (Model Context Protocol) server that works with the Google Docs API. It implements an interface for manipulating Google Docs using generative AI.

function

This MCP server provides the following features:

  • Read Google Docs documents
  • Create a new Google Docs document
  • Updating an existing Google Docs document
  • Searching Google Docs documents

Technology stack

Prerequisites

  • Node.js (v14 or higher recommended)
  • npm or yarn
  • Google Cloud Platform project and access credentials

set up

1. Clone or download the project

git clone [リポジトリURL] cd docs-mcp

2. Install dependencies

npm install

3. Google Cloud Platform Settings

  1. Create a project in the Google Cloud Console (or choose an existing project)
  2. Enable Google Drive API and Google Docs API
  3. Create an OAuth 2.0 client ID and download credentials
  4. Place the downloaded credentials file as credentials.json in the project root.

4. Preferences

  1. Create a .env file in your project root and set your environment variables there:
# アプリケーション環境 NODE_ENV=development # ログ設定 # ログレベル: ERROR, WARN, INFO, DEBUG, TRACE LOG_LEVEL=INFO # 標準エラー出力にログを出力するかどうか(MCPの仕様に準拠) LOG_USE_STDERR=true # サーバー設定 SERVER_NAME=google-docs-mcp-server SERVER_VERSION=1.0.0 # Google API認証情報 # 認証情報ファイルのパス(デフォルトは./credentials.json) CREDENTIALS_PATH=./credentials.json # トークンファイルのパス(デフォルトは./token.json) TOKEN_PATH=./token.json

Explanation of environment variables:

  • NODE_ENV : The application's execution environment (development, production, test)
  • LOG_LEVEL : Log detail level (ERROR, WARN, INFO, DEBUG, TRACE)
  • LOG_USE_STDERR : Whether to output logs to standard error output (MCP specification uses standard error output)
  • SERVER_NAME : MCP server name
  • SERVER_VERSION : MCP server version
  • CREDENTIALS_PATH : Path to the Google API credentials file
  • TOKEN_PATH : Path to store authentication token
  1. Start the development server and get a token:
    npm run dev
    After execution, an authorization URL will be displayed in the terminal. Access that URL in your browser and log in with your Google account to perform authorization. Copy the authorization code that is displayed after authorization is complete, paste it into the terminal, and press Enter. This operation will generate a token.json file, and authentication will be performed automatically from then on.

Build and run

Build

npm run build

execution

Run as a regular server:

npm start

Running in development mode:

npm run dev

Use as an MCP server

This project is a server that complies with the Model Context Protocol (MCP) specification. You can connect to it directly from MCP clients (Cursor, Claude.ai, etc.).

Settings on the MCP client

Setting with Cursor

To use it with Cursor, add the following setting to .cursor/mcp.json file:

{ "mcpServers": { "google-docs": { "command": "node", "args": ["/{プロジェクトへの絶対パス}/docs-mcp/dist/index.js"] } } }
Other MCP clients

Other MCP clients communicate using standard input/output (stdio), so specify the appropriate command depending on your client's configuration.

MCP Tools Provided

read_google_document

Read the contents of a Google Docs document.

Parameters :

  • documentId (string): The ID of the Google Docs document to read.

Example usage :

// MCPクライアントでの使用例 const response = await client.callTool({ name: "read_google_document", arguments: { documentId: "your-document-id" } });
create_google_document

Create a new Google Docs document.

Parameters :

  • title (string): The title of the new document.
  • content (string, optional): The initial content of the document.

Example usage :

const response = await client.callTool({ name: "create_google_document", arguments: { title: "ドキュメントタイトル", content: "初期コンテンツ" } });
update_google_document

Update an existing Google Docs document.

Parameters :

  • documentId (string): The ID of the Google Docs document to update.
  • content (string): The content to add or update.
  • startPosition (number, optional): The position to start updating.
  • endPosition (number, optional): The position to end the update at.

Example usage :

const response = await client.callTool({ name: "update_google_document", arguments: { documentId: "your-document-id", content: "追加または更新するコンテンツ", startPosition: 1, endPosition: 10 } });
search_google_documents

Search for the Google Docs document.

Parameters :

  • query (string): The search query.
  • maxResults (number, optional): The maximum number of results to retrieve (default: 10).

Example usage :

const response = await client.callTool({ name: "search_google_documents", arguments: { query: "検索キーワード", maxResults: 5 } });

Example of use from a program

Example of using MCP client from TypeScript or JavaScript program:

import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"; async function main() { // MCPクライアントの作成 const client = new Client({ name: "google-docs-client", version: "1.0.0" }); // Google Docs MCPサーバーへの接続 const transport = new StdioClientTransport({ command: "npm", args: ["run", "mcp"] }); await client.connect(transport); // サーバー情報の取得 const info = await client.getServerInfo(); console.log("利用可能なツール:", info.tools); // ドキュメントの検索 const searchResult = await client.callTool({ name: "search_google_documents", arguments: { query: "会議資料", maxResults: 5 } }); console.log("検索結果:", searchResult); // 接続を閉じる await client.disconnect(); } main().catch(console.error);

troubleshooting

If a connection error occurs with Cursor

  1. Do a full restart of Cursor.
  2. Please make sure .cursor/mcp.json settings are correct.
  3. Manually start the MCP server and check that it works:
    npm run dev
    Verify that when you run this command, you see the message "Google Docs MCP Server started" and that the process continues to run without exiting.
  4. Check the "MCP Server" section in Cursor's settings and make sure the "google-docs" server is listed.

If you get a Google authentication error

  1. Make sure the credentials.json file is correctly placed in the project root.
  2. If token.json file exists, delete it and try authenticating again.
  3. Verify that the Google Drive API and Google Docs API are enabled for your project in the Google Cloud Console.

Extend and Configure

This MCP server is designed with extensibility in mind, allowing you to add new features such as:

  1. src/googleDocsService.ts - Add new methods to the GoogleDocsService class.
  2. src/index.ts - defines new tools and registers them on the server

Notes

  • On first run, you will be prompted for authorization to authenticate with Google. After authorization, a token will be saved to a file and used automatically on subsequent runs.
  • Google Cloud Platform charges may apply depending on your usage of the API.

license

MIT License

-
security - not tested
F
license - not found
-
quality - not tested

local-only server

The server can only run on the client's local machine because it depends on local resources.

A Model Context Protocol server that provides an interface for AI models to interact with Google Docs, enabling reading, creating, updating, and searching Google Documents.

  1. 機能
    1. 技術スタック
      1. 前提条件
        1. セットアップ
          1. 1. プロジェクトをクローンまたはダウンロード
          2. 2. 依存関係のインストール
          3. 3. Google Cloud Platformの設定
          4. 4. 環境設定
        2. ビルドと実行
          1. ビルド
          2. 実行
        3. MCPサーバーとしての利用
          1. MCPクライアントでの設定
          2. 提供されるMCPツール
        4. プログラムからの利用例
          1. トラブルシューティング
            1. Cursorで接続エラーが発生する場合
            2. Google認証エラーが発生する場合
          2. 拡張と構成
            1. 注意事項
              1. ライセンス

                Related MCP Servers

                • A
                  security
                  A
                  license
                  A
                  quality
                  A Model Context Protocol server that enables AI assistants like Claude to interact with Outline document services, supporting document searching, reading, creation, editing, and comment management.
                  Last updated -
                  25
                  1
                  Python
                  MIT License
                • A
                  security
                  A
                  license
                  A
                  quality
                  A Model Context Protocol server that enables AI assistants to interact with Confluence content, supporting operations like retrieving, searching, creating, and updating pages and spaces.
                  Last updated -
                  9
                  3
                  TypeScript
                  MIT License
                • A
                  security
                  A
                  license
                  A
                  quality
                  A Model Context Protocol server implementation that enables AI assistants like Claude to perform Google searches and retrieve web data directly through natural language requests.
                  Last updated -
                  1
                  75
                  3
                  TypeScript
                  MIT License
                • -
                  security
                  A
                  license
                  -
                  quality
                  A Model Context Protocol server that enables AI assistants like Claude to read from, append to, and format text in Google Documents programmatically.
                  Last updated -
                  5
                  TypeScript
                  MIT License
                  • Linux
                  • Apple

                View all related MCP servers

                ID: 6dscfwd7ts