MCPプロトコル完全ガイド:2026年AIエージェント開発の標準仕様

技术架构

なぜMCPが2026年最重要技術なのか

2024年11月、Anthropicが発表したMCP(Model Context Protocol)は、2025年末にLinux FoundationのAgentic AI Foundationへ移管され、2026年6月現在、AIエージェント開発の事実上の標準となっています。

MCPはAIアプリケーションと外部世界をつなぐ「USB-Cインターフェース」です。

「バベルの塔」問題

MCP以前は、各AIアプリケーションが独自のツール呼び出しシステムを実装する必要がありました:

┌──────────────────────────────────────────┐
│              AIアプリケーション層           │
│  ChatGPTプラグイン │ Claudeツール │ 自作   │
├──────────────────────────────────────────┤
│     独自プロトコル(互換性なし)            │
├──────────────────────────────────────────┤
│  DB │ API │ ファイル │ 検索 │ ...         │
└──────────────────────────────────────────┘

MCPはこの状況を一変させました:

┌──────────────────────────────────────────┐
│   MCP対応AI(Claude/Cursor/自作)          │
├──────────────────────────────────────────┤
│          ★ MCPプロトコル(統一)★          │
├──────────────────────────────────────────┤
│  Server A │ Server B │ Server C │ ...    │
└──────────────────────────────────────────┘
指標 データ
GitHub MCPリポジトリ 10,000+
公式MCPサーバー数 3,000+(2026年5月)
npm SDK 週間DL数 500万+
対応AIツール Claude Desktop, Cursor, Continue...

コアアーキテクチャ

三層構造

┌──────────────────────────────────────┐
│          Host(ホストアプリ)           │
│  Claude Desktop / Cursor / VS Code   │
├──────────────────────────────────────┤
│       MCP Client(クライアント層)      │
│  接続管理、ハンドシェイク、能力ネゴシエーション │
├──────────────────────────────────────┤
│       MCP Server(サーバー層)          │
│  Tools、Resources、Prompts の3原語     │
└──────────────────────────────────────┘

3つの基本プリミティブ

① Tools — AIが呼び出せる関数(POST的な操作)
② Resources — AIが読み取れるコンテキストデータ(GET的な操作)
③ Prompts — 定義済みの対話テンプレート

通信プロトコル

JSON-RPC 2.0ベース、2つのトランスポート方式:

方式 ユースケース 特徴
stdio ローカルプロセス 低レイテンシ
HTTP + SSE リモートサービス クラウド向け

MCPの価値:Before/After

Before MCP

// ❌ 各ツールごとに独自の解析ロジックが必要
class AICodeAssistant {
  async handleUserRequest(prompt: string) {
    if (prompt.includes("ファイル読み込み")) {
      const path = extractFilePath(prompt); // 脆い文字列解析
      const content = await fs.readFile(path);
      return this.llm.generate(`内容:${content}\n質問:${prompt}`);
    }
    // ツールが増えるほどif-elseも増加...
  }
}

After MCP

// ✅ プラグアンドプレイ:どんなツールも1行で統合
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";

const client = new Client({ name: "my-agent", version: "1.0.0" });
await client.connect(new StdioClientTransport({
  command: "npx",
  args: ["-y", "@modelcontextprotocol/server-filesystem", "/workspace"],
}));

const { tools } = await client.listTools();
await llm.generate(prompt, { tools });

MCPサーバー構築:実践コード

import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

const server = new McpServer({
  name: "weather-service",
  version: "1.0.0",
});

server.tool(
  "get_current_weather",
  "指定都市の現在の天気を取得",
  {
    city: z.string().describe("都市名"),
    units: z.enum(["metric", "imperial"]).default("metric"),
  },
  async ({ city, units }) => {
    const data = await fetchWeatherData(city, units);
    return { content: [{ type: "text", text: formatReport(data) }] };
  }
);

server.resource(
  "supported_cities",
  "weather://cities",
  { mimeType: "application/json" },
  async () => ({
    contents: [{
      uri: "weather://cities",
      mimeType: "application/json",
      text: JSON.stringify([
        { name: "東京", code: "tokyo" },
        { name: "大阪", code: "osaka" },
      ], null, 2),
    }],
  })
);

// サーバー起動
const transport = new StdioServerTransport();
await server.connect(transport);

Claude Desktop設定

{
  "mcpServers": {
    "weather": {
      "command": "node",
      "args": ["/path/to/dist/index.js"]
    }
  }
}

LLM統合:AIエージェントの作成

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import OpenAI from "openai";

async function createAgent(userQuery: string) {
  const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
  const mcpClient = new Client({ name: "agent", version: "1.0.0" });
  await mcpClient.connect(new StdioClientTransport({
    command: "node", args: ["./dist/index.js"],
  }));

  const { tools } = await mcpClient.listTools();
  const openaiTools = tools.map(t => ({
    type: "function" as const,
    function: { name: t.name, description: t.description, parameters: t.inputSchema },
  }));

  // エージェントループ:LLM判断 → ツール実行 → 結果反映 → 継続
  const messages: any[] = [
    { role: "system", content: "あなたは天気アシスタントです。" },
    { role: "user", content: userQuery },
  ];

  for (let i = 0; i < 5; i++) {
    const response = await openai.chat.completions.create({
      model: "gpt-4o", messages, tools: openaiTools, tool_choice: "auto",
    });

    if (!response.choices[0].message.tool_calls?.length) {
      return response.choices[0].message.content;
    }

    messages.push(response.choices[0].message);
    for (const tc of response.choices[0].message.tool_calls) {
      const result = await mcpClient.callTool({
        name: tc.function.name,
        arguments: JSON.parse(tc.function.arguments),
      });
      messages.push({
        role: "tool", tool_call_id: tc.id, content: result.content[0].text,
      });
    }
  }
  
  await mcpClient.close();
}

マルチエージェント + MCP:最先端アーキテクチャ

┌──────────────────────────────────────────────┐
│            Orchestrator(編成器)               │
│     タスク分解 │ スケジューリング │ 集約          │
├────────┬────────┬────────┬───────────────────┤
│Research │ Coder  │ Tester │     Reviewer      │
│ Agent  │ Agent  │ Agent  │      Agent         │
├────────┴────────┴────────┴───────────────────┤
│             ★ MCPプロトコル ★                  │
│  File Server │ Git Server │ DB │ APIs         │
└──────────────────────────────────────────────┘
次元 単一Agent MCP + Multi-Agent
ツール拡張 Agentコード修正必要 プラグアンドプレイ
並列実行 非対応 分析の並列化
コード再利用 Agent毎に実装 MCP Server共有
保守性 モノリシック 疎結合

本番環境ベストプラクティス

接続プール

class MCPConnectionPool {
  private pool = new Map<string, Client[]>();
  
  async acquire(name: string): Promise<Client> {
    const available = this.pool.get(name) || [];
    return available.pop() ?? this.createConnection(name);
  }

  release(name: string, client: Client) {
    (this.pool.get(name) || []).push(client);
  }
}

セキュリティチェックリスト

項目 優先度
認証(API Key / OAuth) 🔴 必須
レート制限 🔴 必須
入力バリデーション(Zod) 🔴 必須
タイムアウト制御 🟡 推奨
パスホワイトリスト 🟡 推奨

MCPエコシステム

サーバー 用途
@modelcontextprotocol/server-filesystem 安全なファイルI/O
@anthropic/mcp-server-postgres PostgreSQL
@anthropic/mcp-server-git Git操作
@anthropic/mcp-server-github GitHub API
@anthropic/mcp-server-brave-search Web検索

まとめ

  1. MCPはAIエージェントのインフラ — HTTPがWebにとってそうであるように
  2. 3つのプリミティブ — Tools(実行)、Resources(読取)、Prompts(テンプレート)
  3. プラグアンドプレイ — 1つのサーバーで全MCPクライアント対応
  4. MCP + Multi-Agent — 2026年最強のAIアーキテクチャ

2026年後半のトレンド

  • MCP 2.0 — 双方向ストリーミング、強化されたセキュリティ
  • エンタープライズMCPゲートウェイ — 統一認証・課金・監視
  • MCPマーケットプレイス — App Store的なサーバーエコシステム
  • エッジMCP — CDNエッジノードでの実行

ブラウザローカルツールを無料で試す →

#MCP#AI Agent#Model Context Protocol#大模型#工具调用#多智能体