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以上推奨)
- TypeScript
- @modelcontextprotocol/sdk - MCP SDKの公式実装
- Google APIs Node.js Client - Google APIへのアクセス
前提条件
- Node.js (v14以上推奨)
- npm または yarn
- Google Cloud Platformのプロジェクトとアクセス認証情報
セットアップ
1. プロジェクトをクローンまたはダウンロード
2. 依存関係のインストール
3. Google Cloud Platformの設定
- Google Cloud Consoleでプロジェクトを作成(または既存のプロジェクトを選択)
- Google Drive APIとGoogle Docs APIを有効化
- OAuth 2.0クライアントIDを作成し、認証情報をダウンロード
- ダウンロードした認証情報ファイルを
credentials.json
としてプロジェクトルートに配置
4. 環境設定
.env
ファイルをプロジェクトルートに作成し、環境変数を設定します:
環境変数の説明:
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
: 認証トークン保存先のパス
- 開発サーバーを起動し、トークンを取得します:実行後、ターミナルに認可用URLが表示されます。そのURLにブラウザでアクセスし、Googleアカウントでログインして認可を行ってください。 認可完了後に表示される認可コードをコピーし、ターミナルに貼り付けてEnterキーを押してください。 この操作により
token.json
ファイルが生成され、以降は自動的に認証されます。
ビルドと実行
ビルド
実行
通常のサーバーとして実行:
開発モードでの実行:
MCPサーバーとしての利用
このプロジェクトはModel Context Protocol(MCP)の仕様に準拠したサーバーです。MCPクライアント(Cursor、Claude.aiなど)から直接接続して利用できます。
MCPクライアントでの設定
Cursorでの設定
Cursorで使用するには、.cursor/mcp.json
ファイルに以下の設定を追加します:
その他のMCPクライアント
その他のMCPクライアントでは、標準入出力(stdio)を使用して通信します。クライアントの設定に応じて適切なコマンドを指定してください。
提供されるMCPツール
read_google_document
Google Docsドキュメントの内容を読み取ります。
パラメータ:
documentId
(string): 読み取るGoogle DocsドキュメントのID
使用例:
create_google_document
新しいGoogle Docsドキュメントを作成します。
パラメータ:
title
(string): 新しいドキュメントのタイトルcontent
(string, オプション): ドキュメントの初期内容
使用例:
update_google_document
既存のGoogle Docsドキュメントを更新します。
パラメータ:
documentId
(string): 更新するGoogle DocsドキュメントのIDcontent
(string): 追加または更新するコンテンツstartPosition
(number, オプション): 更新を開始する位置endPosition
(number, オプション): 更新を終了する位置
使用例:
search_google_documents
Google Docsドキュメントを検索します。
パラメータ:
query
(string): 検索クエリmaxResults
(number, オプション): 取得する最大結果数(デフォルト: 10)
使用例:
プログラムからの利用例
TypeScriptやJavaScriptプログラムからMCPクライアントを通じて利用する例:
トラブルシューティング
Cursorで接続エラーが発生する場合
- Cursorを完全に再起動してください。
.cursor/mcp.json
の設定が正しいことを確認してください。- 手動でMCPサーバーを起動して動作確認:このコマンドを実行したときに「Google Docs MCPサーバーが起動しました」というメッセージが表示され、プロセスが終了せずに動作し続けることを確認します。
- Cursorの設定から「MCPサーバー」セクションを確認し、「google-docs」サーバーが表示されていることを確認します。
Google認証エラーが発生する場合
credentials.json
ファイルが正しくプロジェクトルートに配置されていることを確認します。token.json
ファイルが存在する場合は削除し、再認証を試みてください。- Google Cloud Consoleで該当のプロジェクトに対してGoogle Drive APIとGoogle Docs APIが有効になっていることを確認します。
拡張と構成
このMCPサーバーは拡張性を考慮して設計されており、以下のように新しい機能を追加できます:
src/googleDocsService.ts
- GoogleDocsServiceクラスに新しいメソッドを追加src/index.ts
- 新しいツールを定義し、サーバーに登録
注意事項
- 初回実行時に、Google認証のための承認画面が表示されます。認証後、トークンがファイルに保存され、以降の実行では自動的に使用されます。
- APIの使用量に応じて、Google Cloud Platformの料金が発生する場合があります。
ライセンス
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
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.
Related MCP Servers
- AsecurityAlicenseAqualityA 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 -2519PythonMIT License
- AsecurityAlicenseAqualityA 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 -93TypeScriptMIT License
- AsecurityAlicenseAqualityA 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 -1753TypeScriptMIT License
- -securityAlicense-qualityA Model Context Protocol server that enables AI assistants like Claude to read from, append to, and format text in Google Documents programmatically.Last updated -24TypeScriptMIT License