Model Context Protocol(MCP) は、Anthropic が作成したオープンスタンダードで、AI モデルが外部ツール、データソース、サービスとどのように通信するかを定義します。これを「AI の USB-C」と考えてください - 標準化されたインターフェースを通じて、任意の AI エージェントが任意のツールと通信できるユニバーサルコネクタです。
ローンチ以来、MCP は 月間9,700万回以上の SDK ダウンロード を達成し、すべての主要 AI プロバイダーに採用されています:Anthropic、OpenAI、Google、Microsoft、Amazon。このガイドでは、MCP を使って構築するために知っておくべきすべてを探ります。
MCP が存在する理由
MCP 以前は、すべての AI アプリケーションが使用したい各ツールに対してカスタム統合を構築する必要がありました。AI にファイルを読ませたい?カスタムコードを書く。データベースをクエリする?さらにカスタムコード。Slack に投稿する?また別の統合。
これにより N×M 問題 が発生しました:N 個の AI アプリケーションがそれぞれ M 個のカスタム統合を必要とし、作業の重複と断片化したエコシステムにつながりました。
MCP はこれを、任意の AI クライアントが任意の MCP サーバーと通信するために使用できる単一のプロトコルで解決します:
基本概念
MCP には3つの基本的なプリミティブがあります:
1. ツール(Tools)
ツールは AI が呼び出せる関数です。「ファイルを作成する」「データベースをクエリする」「メッセージを送信する」などのアクションを表します。各ツールには名前、説明、パラメータの JSON Schema があります。
{ name: "create_issue", description: "Create a new GitHub issue", inputSchema: { type: "object", properties: { title: { type: "string", description: "Issue title" }, body: { type: "string", description: "Issue body" }, repo: { type: "string", description: "Repository name" } }, required: ["title", "repo"] } }
2. リソース(Resources)
リソースは AI が読み取れるデータです。ファイル、データベースレコード、API レスポンス、その他のデータソースを表します。リソースは URI で識別されます。
{ uri: "file:///Users/dev/project/README.md", name: "Project README", mimeType: "text/markdown" }
3. プロンプト(Prompts)
プロンプトはインタラクションの構造化を助ける再利用可能なテンプレートです。動的パラメータを含めることができ、一般的なワークフローの標準化に役立ちます。
{ name: "code_review", description: "Review code changes for quality and security", arguments: [ { name: "diff", description: "The code diff to review", required: true } ] }
アーキテクチャ
MCP はクライアント-サーバーアーキテクチャに従います:
- ホスト:AI アプリケーション(Claude Desktop、Cursor、カスタムアプリ)
- クライアント:MCP サーバーとの 1:1 接続を維持
- サーバー:ツール、リソース、プロンプトをクライアントに公開
- トランスポート:stdio(ローカル)または Server-Sent Events(リモート)上の JSON-RPC 2.0 で通信
MCP サーバーの構築
JSON ファイルに保存されたタスクリストとやり取りする実用的な MCP サーバーを構築しましょう。
セットアップ
mkdir mcp-todo-server && cd mcp-todo-server npm init -y npm install @modelcontextprotocol/sdk zod
サーバーの実装
// src/index.ts import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { z } from "zod"; import fs from "fs"; const TODO_FILE = "./todos.json"; function readTodos(): { id: number; text: string; done: boolean }[] { if (!fs.existsSync(TODO_FILE)) return []; return JSON.parse(fs.readFileSync(TODO_FILE, "utf-8")); } function writeTodos(todos: { id: number; text: string; done: boolean }[]) { fs.writeFileSync(TODO_FILE, JSON.stringify(todos, null, 2)); } const server = new McpServer({ name: "todo-server", version: "1.0.0", }); // Tool: Add a todo server.tool( "add_todo", "Add a new todo item", { text: z.string().describe("The todo text") }, async ({ text }) => { const todos = readTodos(); const newTodo = { id: Date.now(), text, done: false }; todos.push(newTodo); writeTodos(todos); return { content: [{ type: "text", text: `Added: "${text}"` }] }; } ); // Tool: List todos server.tool( "list_todos", "List all todo items", {}, async () => { const todos = readTodos(); const list = todos .map((t) => `${t.done ? "✅" : "⬜"} [${t.id}] ${t.text}`) .join("\n"); return { content: [{ type: "text", text: list || "No todos yet." }] }; } ); // Tool: Complete a todo server.tool( "complete_todo", "Mark a todo as completed", { id: z.number().describe("The todo ID to complete") }, async ({ id }) => { const todos = readTodos(); const todo = todos.find((t) => t.id === id); if (!todo) return { content: [{ type: "text", text: "Todo not found." }] }; todo.done = true; writeTodos(todos); return { content: [{ type: "text", text: `Completed: "${todo.text}"` }] }; } ); // Resource: Current todos as a readable resource server.resource( "todos://list", "Current todo list", async () => ({ contents: [{ uri: "todos://list", mimeType: "application/json", text: JSON.stringify(readTodos(), null, 2), }], }) ); // Start the server const transport = new StdioServerTransport(); await server.connect(transport);
設定
このサーバーを Claude Desktop で使用するには、設定に追加してください:
{ "mcpServers": { "todo": { "command": "npx", "args": ["tsx", "/path/to/mcp-todo-server/src/index.ts"] } } }
MCP クライアントの構築
任意の MCP サーバーに接続するカスタムクライアントも構築できます:
import { Client } from "@modelcontextprotocol/sdk/client/index.js"; import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"; const transport = new StdioClientTransport({ command: "npx", args: ["tsx", "./src/index.ts"], }); const client = new Client({ name: "my-client", version: "1.0.0" }); await client.connect(transport); // List available tools const { tools } = await client.listTools(); console.log("Available tools:", tools.map((t) => t.name)); // Call a tool const result = await client.callTool({ name: "add_todo", arguments: { text: "Write MCP blog post" }, }); console.log(result);
人気の MCP サーバー
MCP エコシステムは急速に成長しています。最も人気のあるサーバーの一部を紹介します:
| サーバー | 説明 | ユースケース |
|---|---|---|
| GitHub | Issue、PR の作成、リポジトリの管理 | 開発ワークフロー |
| Slack | メッセージの送信、チャンネルの管理 | チームコミュニケーション |
| PostgreSQL | データベースのクエリと管理 | データアクセス |
| Filesystem | ファイルの読み取り、書き込み、検索 | ローカル開発 |
| Puppeteer | ブラウザの自動化とスクレイピング | Web テスト |
| Sentry | エラー監視とデバッグ | 本番サポート |
| Supabase | データベース、認証、ストレージ | バックエンド操作 |
MCP vs A2A(Agent-to-Agent)
MCP がエージェント-ツール間の通信を処理するのに対し、Google の A2A(Agent-to-Agent) プロトコルはエージェント-エージェント間の通信を処理します。これらは相補的です:
- MCP:AI エージェントがツールを使用する方法(垂直統合)
- A2A:AI エージェント同士が協力する方法(水平統合)
ベストプラクティス
- サーバーを焦点を絞る:ドメインごとに1つのサーバー(GitHub サーバー、Slack サーバーなど)。モノリシックなサーバーを構築しないでください。
- Zod で入力を検証する:常に適切なスキーマでツールの入力を検証してください。
- エラーを適切に処理する:スタックトレースではなく、意味のあるエラーメッセージを返してください。
- 読み取り専用データにはリソースを使用する:AI がデータの読み取りのみが必要な場合は、ツールではなくリソースとして公開してください。
- 適切な説明を追加する:ツールとパラメータの良い説明は、AI が各ツールをいつ、どのように使用するかを理解するのに役立ちます。
- MCP Inspector でテストする:
npx @modelcontextprotocol/inspectorを使用してサーバーを対話的にテストしてください。
はじめに
# Create a new MCP server from template npx @modelcontextprotocol/create-server my-server # Test with the MCP Inspector npx @modelcontextprotocol/inspector npx tsx ./src/index.ts
まとめ
MCP は 2026 年に AI ツール利用のデファクトスタンダードとなりました。カスタム AI エージェントの構築、Claude Code の拡張、既存プラットフォームへの統合の作成のいずれであっても、MCP を理解することは不可欠です。このプロトコルは午後の数時間で学べるほどシンプルですが、本番レベルの AI ワークフローを構築するのに十分な強力さを持っています。
次のステップ:
- MCP 仕様を探索する
- 既存の MCP サーバーをブラウズしてインスピレーションを得る
- TypeScript または Python SDK で最初のサーバーを構築する
- Claude Desktop または MCP Inspector でテストする