Skip to main content
Glama

Google Docs MCP Server

by penysho

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

Related MCP Servers

  • -
    security
    -
    license
    -
    quality
    A Model Context Protocol server that enables AI assistants to interact with Gmail services, supporting email operations, draft management, and calendar functionality through Google API integration.
    Last updated -
    356
    1
  • A
    security
    -
    license
    A
    quality
    A Model Context Protocol server that provides seamless integration with Google Workspace, allowing operations with Google Drive, Docs, and Sheets through secure OAuth2 authentication.
    Last updated -
    8
    3
    MIT License
    • Linux
    • Apple
  • A
    security
    -
    license
    A
    quality
    A Model Context Protocol server that provides web search capabilities using Google Custom Search API and webpage content extraction functionality.
    Last updated -
    2
    4
    1
    • Apple
  • A
    security
    -
    license
    A
    quality
    A Model Context Protocol server that enables AI agents to interact with Google Workspace services including Drive, Docs, and Sheets through natural language commands.
    Last updated -
    8
    MIT License
    • Linux
    • Apple

View all related MCP servers

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/penysho/docs-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server