The Google Docs MCP Server enables AI systems to interact with Google Docs through a Model Context Protocol (MCP) interface, providing four core capabilities:
Read documents: Retrieve content from specific Google Docs using their document ID
Create documents: Generate new Google Docs with a specified title and optional initial content
Update documents: Modify existing documents by ID, adding or replacing content with optional positioning control
Search documents: Find Google Docs using search queries with customizable result limits
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
Google Docs APIと連携するMCP(Model Context Protocol)サーバーです。AI システムがGoogle Docsを直接操作できるインターフェースを提供します。
機能
このMCPサーバーが提供するツール:
read_google_document - Google Docsドキュメントの読み取り
create_google_document - 新しいGoogle Docsドキュメントの作成
update_google_document - 既存のGoogle Docsドキュメントの更新
search_google_documents - Google Docsドキュメントの検索
Related MCP server: MCP Google Suite
アーキテクチャの特徴
依存性注入コンテナ - ServiceContainerによるサービス管理
階層化エラーハンドリング - 統一されたエラー処理システム
自動ツール登録 - 設定ベースのツール管理
完全なTypeScript - 型安全性と開発効率の向上
技術スタック
Runtime: Node.js (v14以上)
Language: TypeScript (ES2020/ESM)
MCP SDK: @modelcontextprotocol/sdk v1.10.2
Google APIs: googleapis v148.0.0
セットアップ
1. プロジェクトの準備
2. Google Cloud Platform の設定
Google Cloud Console でプロジェクトを作成
以下のAPIを有効化:
Google Docs API
Google Drive API
OAuth 2.0 クライアントIDを作成し、認証情報をダウンロード
credentials.jsonとしてプロジェクトルートに配置
3. 環境設定(オプション)
.env ファイルで設定をカスタマイズできます:
4. 初回認証
ターミナルに表示される認証URLにアクセスし、Googleアカウントで認証してください。認証後に取得したコードをターミナルに入力すると token.json が生成されます。
開発コマンド
ビルドプロセス: TypeScript コンパイル → 実行権限設定 → 認証ファイル複製
MCP クライアント設定
Cursor での設定
.cursor/mcp.json に追加:
Claude Desktop での設定
claude_desktop_config.json に追加:
注意: ビルド後の dist/index.js を指定してください。
提供ツール
read_google_document
Google Docs ドキュメントの内容を読み取ります。
パラメータ:
documentId(string): 読み取るドキュメントのID
create_google_document
新しい Google Docs ドキュメントを作成します。
パラメータ:
title(string): ドキュメントタイトルcontent(string, オプション): 初期内容
update_google_document
既存の Google Docs ドキュメントを更新します。
パラメータ:
documentId(string): 更新するドキュメントのIDcontent(string): 追加または更新するコンテンツstartPosition(number, オプション): 更新開始位置endPosition(number, オプション): 更新終了位置
search_google_documents
Google Docs ドキュメントを検索します。
パラメータ:
query(string): 検索クエリmaxResults(number, オプション): 最大結果数(デフォルト: 10)
プログラムでの利用例
MCP SDK を使用した TypeScript/JavaScript での利用:
アーキテクチャ詳細
コアコンポーネント
ServiceContainer (
src/core/container.ts) - 依存性注入とサービスライフサイクル管理GoogleDocsMcpServer (
src/mcp/server.ts) - MCP サーバーの管理と初期化ToolRegistry (
src/mcp/registry.ts) - ツールの自動登録システムBaseMcpTool (
src/mcp/tools/base.ts) - 全ツールの共通基底クラス
サービス層
AuthService (
src/services/authService.ts) - Google OAuth2 認証管理GoogleDocsService (
src/services/googleDocsService.ts) - Google Docs/Drive API操作
設定システム
統一設定管理 (
src/config/index.ts) - 環境変数とデフォルト値の統合型安全な設定 - Zod による設定値の検証
階層化ログシステム (
src/utils/logger.ts) - モジュール別ログ出力
トラブルシューティング
MCP クライアント接続エラー
ビルドの確認:
npm run buildが成功しているかパス設定: 設定ファイルで
dist/index.jsへの絶対パスを指定権限設定:
chmod 755 dist/index.jsで実行権限を確認手動テスト:
npm run mcpでサーバーが起動するか確認
Google 認証エラー
認証ファイル:
credentials.jsonがプロジェクトルートに存在するかAPI有効化: Google Cloud Console で必要なAPIが有効か
トークン再作成:
token.jsonを削除して再認証スコープ確認: Docs API と Drive API の権限が設定されているか
開発時のデバッグ
拡張ガイド
新しいツールの追加
src/mcp/tools/に新しいツールクラスを作成BaseMcpToolを継承して実装ToolRegistry.registerDefaultTools()に追加
サービスの拡張
src/core/interfaces.tsでインターフェースを定義src/services/に実装クラスを作成ServiceContainerに追加
注意事項
初回実行時の Google 認証が必要
Google Cloud Platform の API 使用料金が発生する可能性
MCP クライアントでは絶対パスでの指定が必要
ライセンス
MIT License