
docs mcp
提供基于 Google Docs API 的 Model Context Protocol (MCP) 服务器,用于通过生成式 AI 操作 Google Docs。
Repository Info
About This Server
提供基于 Google Docs API 的 Model Context Protocol (MCP) 服务器,用于通过生成式 AI 操作 Google Docs。
Model Context Protocol (MCP) - This server can be integrated with AI applications to provide additional context and capabilities, enabling enhanced AI interactions and functionality.
Documentation
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. プロジェクトをクローンまたはダウンロード
git clone [リポジトリURL]
cd docs-mcp
2. 依存関係のインストール
npm install
3. Google Cloud Platformの設定
- Google Cloud Consoleでプロジェクトを作成(または既存のプロジェクトを選択)
- Google Drive APIとGoogle Docs APIを有効化
- OAuth 2.0クライアントIDを作成し、認証情報をダウンロード
- ダウンロードした認証情報ファイルを
credentials.jsonとしてプロジェクトルートに配置
4. 環境設定
.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: 認証トークン保存先のパス
- 開発サーバーを起動し、トークンを取得します:
実行後、ターミナルに認可用URLが表示されます。そのURLにブラウザでアクセスし、Googleアカウントでログインして認可を行ってください。 認可完了後に表示される認可コードをコピーし、ターミナルに貼り付けてEnterキーを押してください。 この操作によりnpm run devtoken.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ドキュメントのIDcontent(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で接続エラーが発生する場合
- Cursorを完全に再起動してください。
.cursor/mcp.jsonの設定が正しいことを確認してください。- 手動でMCPサーバーを起動して動作確認:
このコマンドを実行したときに「Google Docs MCPサーバーが起動しました」というメッセージが表示され、プロセスが終了せずに動作し続けることを確認します。npm run dev - 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の料金が発生する場合があります。
ライセンス
MIT License
Quick Start
Clone the repository
git clone https://github.com/penysho/docs-mcpInstall dependencies
cd docs-mcp
npm installFollow the documentation
Check the repository's README.md file for specific installation and usage instructions.
Repository Details
Recommended MCP Servers
Discord MCP
Enable AI assistants to seamlessly interact with Discord servers, channels, and messages.
Knit MCP
Connect AI agents to 200+ SaaS applications and automate workflows.
Apify MCP Server
Deploy and interact with Apify actors for web scraping and data extraction.
BrowserStack MCP
BrowserStack MCP Server for automated testing across multiple browsers.
Zapier MCP
A Zapier server that provides automation capabilities for various apps.