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 サーバー

このプロジェクトは、Google Docs APIと連携するMCP(Model Context Protocol)サーバーを提供します。生成AIを使ってGoogle Docsを操作するためのインターフェースを実装しています。

機能

このMCPサーバーは以下の機能を提供します:

  • Google Docsドキュメントの読み取り
  • 新しいGoogle Docsドキュメントの作成
  • 既存のGoogle Docsドキュメントの更新
  • Google Docsドキュメントの検索

技術スタック

前提条件

  • Node.js (v14以上推奨)
  • npm または yarn
  • Google Cloud Platformのプロジェクトとアクセス認証情報

セットアップ

1. プロジェクトをクローンまたはダウンロード

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

2. 依存関係のインストール

npm install

3. Google Cloud Platformの設定

  1. Google Cloud Consoleでプロジェクトを作成(または既存のプロジェクトを選択)
  2. Google Drive APIとGoogle Docs APIを有効化
  3. OAuth 2.0クライアントIDを作成し、認証情報をダウンロード
  4. ダウンロードした認証情報ファイルをcredentials.jsonとしてプロジェクトルートに配置

4. 環境設定

  1. .envファイルをプロジェクトルートに作成し、環境変数を設定します:
# アプリケーション環境 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

環境変数の説明:

  • NODE_ENV: アプリケーションの実行環境(development, production, test)
  • LOG_LEVEL: ログの詳細レベル(ERROR, WARN, INFO, DEBUG, TRACE)
  • LOG_USE_STDERR: ログを標準エラー出力に出力するかどうか(MCP仕様では標準エラー出力を使用)
  • SERVER_NAME: MCPサーバー名
  • SERVER_VERSION: MCPサーバーのバージョン
  • CREDENTIALS_PATH: Google APIの認証情報ファイルのパス
  • TOKEN_PATH: 認証トークン保存先のパス
  1. 開発サーバーを起動し、トークンを取得します:
    npm run dev
    実行後、ターミナルに認可用URLが表示されます。そのURLにブラウザでアクセスし、Googleアカウントでログインして認可を行ってください。 認可完了後に表示される認可コードをコピーし、ターミナルに貼り付けてEnterキーを押してください。 この操作によりtoken.jsonファイルが生成され、以降は自動的に認証されます。

ビルドと実行

ビルド

npm run build

実行

通常のサーバーとして実行:

npm start

開発モードでの実行:

npm run dev

MCPサーバーとしての利用

このプロジェクトはModel Context Protocol(MCP)の仕様に準拠したサーバーです。MCPクライアント(Cursor、Claude.aiなど)から直接接続して利用できます。

MCPクライアントでの設定

Cursorでの設定

Cursorで使用するには、.cursor/mcp.jsonファイルに以下の設定を追加します:

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

その他のMCPクライアントでは、標準入出力(stdio)を使用して通信します。クライアントの設定に応じて適切なコマンドを指定してください。

提供されるMCPツール

read_google_document

Google Docsドキュメントの内容を読み取ります。

パラメータ:

  • documentId (string): 読み取るGoogle DocsドキュメントのID

使用例:

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

新しいGoogle Docsドキュメントを作成します。

パラメータ:

  • title (string): 新しいドキュメントのタイトル
  • content (string, オプション): ドキュメントの初期内容

使用例:

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

既存のGoogle Docsドキュメントを更新します。

パラメータ:

  • documentId (string): 更新するGoogle DocsドキュメントのID
  • content (string): 追加または更新するコンテンツ
  • startPosition (number, オプション): 更新を開始する位置
  • endPosition (number, オプション): 更新を終了する位置

使用例:

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

Google Docsドキュメントを検索します。

パラメータ:

  • query (string): 検索クエリ
  • maxResults (number, オプション): 取得する最大結果数(デフォルト: 10)

使用例:

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

プログラムからの利用例

TypeScriptやJavaScriptプログラムからMCPクライアントを通じて利用する例:

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);

トラブルシューティング

Cursorで接続エラーが発生する場合

  1. Cursorを完全に再起動してください。
  2. .cursor/mcp.jsonの設定が正しいことを確認してください。
  3. 手動でMCPサーバーを起動して動作確認:
    npm run dev
    このコマンドを実行したときに「Google Docs MCPサーバーが起動しました」というメッセージが表示され、プロセスが終了せずに動作し続けることを確認します。
  4. Cursorの設定から「MCPサーバー」セクションを確認し、「google-docs」サーバーが表示されていることを確認します。

Google認証エラーが発生する場合

  1. credentials.jsonファイルが正しくプロジェクトルートに配置されていることを確認します。
  2. token.jsonファイルが存在する場合は削除し、再認証を試みてください。
  3. Google Cloud Consoleで該当のプロジェクトに対してGoogle Drive APIとGoogle Docs APIが有効になっていることを確認します。

拡張と構成

このMCPサーバーは拡張性を考慮して設計されており、以下のように新しい機能を追加できます:

  1. src/googleDocsService.ts - GoogleDocsServiceクラスに新しいメソッドを追加
  2. src/index.ts - 新しいツールを定義し、サーバーに登録

注意事項

  • 初回実行時に、Google認証のための承認画面が表示されます。認証後、トークンがファイルに保存され、以降の実行では自動的に使用されます。
  • APIの使用量に応じて、Google Cloud Platformの料金が発生する場合があります。

ライセンス

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