Skip to content

AI Agent 協定(MCP & A2A)

核心問題

AI Agent 如何與外部世界「對話」? 就像網際網路需要 HTTP 協定,AI Agent 也需要標準化的通訊協定。本章介紹兩個最主流的 Agent 協定:MCP 和 A2A,它們分別解決了 AI 與工具、Agent 與 Agent 之間的通訊問題。


0. 什麼是協定?

在電腦領域,協定(Protocol) 是一套標準化的規則和約定,讓不同的系統、程式能夠相互「理解」和「通訊」。

0.1 為什麼需要協定?

想像一個情境:你給朋友寄快遞,需要填寫地址。如果每個人寫的地址格式都不一樣,快遞員就沒法投遞。協定就是規定了「地址怎麼寫」的標準——省、市、區、街道、門牌號,按這個格式寫,誰都能看懂。

電腦也是一樣。兩個程式要通訊,必須約定好:

  • 資料格式是什麼?(JSON?二進位?)
  • 怎麼建立連線?(握手流程)
  • 出錯了怎麼辦?(錯誤處理)

0.2 電腦中常見的協定

協定作用你每天都在用
HTTP網頁傳輸協定瀏覽器開啟網頁
HTTPS加密的 HTTP網路銀行、支付頁面
TCP/IP網際網路基礎協定所有網路通訊
DNS域名解析協定google.com 變成 IP 位址
SMTP郵件傳送協定傳送郵件
WebSocket雙向即時通訊聊天軟體、線上遊戲
SSH安全遠端登入連線伺服器
FTP檔案傳輸協定上傳/下載檔案

這些協定構成了網際網路的基石。沒有它們,你無法瀏覽網頁、傳送郵件、觀看影片。

0.3 協定的價值

協定的核心價值是標準化互通性

  • 標準化:大家都按同一套規則辦事,減少溝通成本
  • 互通性:不同廠商、不同技術堆疊的系統可以無縫對接

比如 HTTP 協定,讓 Chrome 瀏覽器可以存取 Nginx 伺服器,讓 Python 爬蟲可以擷取 Java 網站的資料。不需要 Chrome 和 Nginx 互相「認識」,只要都遵守 HTTP 協定就行。

0.4 AI Agent 也需要協定

AI Agent 要真正「幹活」,需要:

  • 呼叫外部工具(查天氣、發郵件、操作資料庫)
  • 與其他 Agent 協作(分工合作完成複雜任務)

這就需要標準化的協定來規定「AI 怎麼呼叫工具」、「Agent 之間怎麼對話」。這就是 MCPA2A 的由來。


1. Agent 協定的層次

在深入瞭解具體協定之前,讓我們先看看 Agent 生態中的通訊層次:

層級協定解決的問題類比
1Function CallAI 如何呼叫本地函式大腦發出指令
2MCPAI 如何連線外部工具和資料來源USB-C 介面
3A2AAgent 之間如何協作通訊企業微信

逐行解讀這張表

第1層(Function Call):這是大型語言模型最基礎的能力——透過輸出結構化資料(JSON)來觸發函式執行。它是「協定」的基礎,但本身更像是一種能力而非標準協定。

第2層(MCP):Model Context Protocol,由 Anthropic 於 2024 年 11 月發布。它標準化了 AI 與外部工具、資料來源的連線方式,就像 USB-C 統一了各種裝置的充電介面。

第3層(A2A):Agent-to-Agent Protocol,由 Google 於 2025 年 4 月發布。它讓不同的 Agent 能夠相互發現、通訊和協作,就像企業微信讓同事之間可以發任務、聊天。

本章重點介紹第 2、3 層的兩個正式協定:MCP 和 A2A。


2. MCP (Model Context Protocol)

2.1 協定基本資訊

項目內容
全稱Model Context Protocol
發起方Anthropic
發布時間2024 年 11 月 25 日
官方文件modelcontextprotocol.io
開源協定MIT License
GitHubgithub.com/modelcontextprotocol

為什麼叫「Context Protocol」?

Context(上下文) 是大型語言模型理解任務的關鍵。MCP 的核心思想是:讓 AI 能夠動態取得所需的上下文資訊,而不是把所有資訊都塞進 Prompt。

比如,AI 需要讀取一個檔案時,不需要你把檔案內容複製貼上給它,而是透過 MCP 直接存取檔案系統。

2.2 發布的背景

2024 年,隨著 Claude 3.5 Sonnet 的發布,Anthropic 發現一個問題:每個工具都要單獨整合

想像一下:

  • 你想讓 AI 讀取 GitHub 儲存庫 → 要寫 GitHub 整合程式碼
  • 你想讓 AI 查詢資料庫 → 要寫資料庫整合程式碼
  • 你想讓 AI 操作檔案系統 → 要寫檔案系統整合程式碼

每個整合都要重複寫類似的程式碼:認證、錯誤處理、資料轉換……

Anthropic 在官方部落格中寫道:

"We're introducing the Model Context Protocol (MCP), an open protocol that standardizes how applications provide context to LLMs."

核心目標:讓工具開發者寫一次程式碼,所有支援 MCP 的 AI 應用都能使用。

2.3 MCP 是什麼?

What is MCP?
MCP (Model Context Protocol) is a unified standard introduced by Anthropic in November 2024 for connecting AI with external tools. It lets AI applications call tools, read resources, and use predefined prompts, giving AI practical "hands" and "eyes".
Three Core Capabilities
Capability
English
Role
Example
Tools
Tools
Functions AI can call
Check weather, send email, call APIs
Resources
Resources
Data AI can read
File content, database records, configuration
Prompts
Prompts
Predefined prompt templates
Code review templates, writing templates
When should you use MCP?
When AI needs to perform real actions
AI should not only answer questions, but also send emails, operate files, and call third-party APIs.
When AI needs access to private data
Read local files, query databases, or access internal business systems.
When tool integration should be standardized
Build once and reuse across AI applications such as Claude, Cursor, and Windsurf.
How do you use MCP?
1
Develop an MCP Server
Implement a server that provides tools, resources, and prompts according to the MCP spec.
2
Configure the AI app connection
Add the MCP Server configuration to your AI app, either local or remote.
3
Let AI call it automatically
AI discovers and calls suitable tools or reads resources based on the task.

三大核心能力

能力英文作用範例
工具ToolsAI 可以呼叫的功能查詢天氣、傳送郵件
資源ResourcesAI 可以讀取的資料檔案內容、資料庫記錄
提示Prompts預定義的提示範本程式碼審查範本、寫作範本

2.4 MCP 的內部實作

MCP InternalsCommunication details of the client-server architecture
Why is MCP so popular?

Before MCP, AI could only read and respond. With MCP, AI can finally take action by operating programs and helping with real work.

How do you use MCP?

Using MCP is simple: configure an mcp.json file, then your IDE can use MCP tools.

1
Find an MCP Server
Find the MCP Server you need from an MCP directory or GitHub.
2
Configure mcp.json
Find the MCP config location in your AI editor, such as Cursor or Claude Desktop, and add the server configuration.
{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-filesystem",
        "/home/user/projects"
      ]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "your-token-here"
      }
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "DATABASE_URL": "postgresql://user:pass@localhost/db"
      }
    }
  }
}
3
Restart the IDE
After restart, AI discovers and loads MCP tools automatically, so you can ask it to use them.
Are Skills replacing MCP?
As Skills become more common, many scenarios are starting to use Skills instead of the MCP protocol. Skills are lighter and easier to write for common tasks. MCP remains better for complex tool integrations and reuse across multiple clients. For simple operations, consider Skills first.
Common mcp.json locations
Cursor~/.cursor/mcp.json
Claude Desktop~/Library/Application Support/Claude/claude_desktop_config.json (macOS)
Windsurf~/.windsurf/mcp.json
How do you implement an MCP Server?

Suppose you have a weather API and want to wrap it as an MCP Server that AI can call. This Node.js example shows the shape:

weather-mcp-server.js
import { Server } from '@modelcontextprotocol/sdk/server/index.js'
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'

// 1. Create MCP Server
const server = new Server({
  name: 'weather-server',
  version: '1.0.0'
}, {
  capabilities: { tools: {} }
})

// 2. Define tool list
server.setRequestHandler('tools/list', async () => ({
  tools: [{
    name: 'get_weather',
    description: 'Get weather for a city',
    inputSchema: {
      type: 'object',
      properties: {
        city: { type: 'string', description: 'City name' }
      },
      required: ['city']
    }
  }]
}))

// 3. Implement tool call logic
server.setRequestHandler('tools/call', async (request) => {
  const { name, arguments: args } = request.params

  if (name === 'get_weather') {
    // Call your weather API
    const response = await fetch(
      `https://api.weather.com/v1/current?city=${args.city}`
    )
    const data = await response.json()

    return {
      content: [{
        type: 'text',
        text: JSON.stringify(data)
      }]
    }
  }
})

// 4. Start service through stdio
const transport = new StdioServerTransport()
await server.connect(transport)
stdio vs HTTP+SSE transport
stdio (local process)

The MCP Server runs as a child process and communicates through standard input and output.

Pros: simple, secure, and suitable for local tools.

Cons: local only; no remote access.

HTTP + SSE (remote service)

The MCP Server runs as an HTTP service and supports SSE pushes.

Pros: remote access and sharing across multiple clients.

Cons: requires server deployment and authentication.

Communication Flow (4 Steps)
1Handshake (initialize)
When the MCP Server starts, it sends an initialize request to the client and declares protocol version and capabilities.
Server → Client
// Server sends an initialize request
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "protocolVersion": "2024-11-05",
    "capabilities": {
      "tools": {},
      "resources": {},
      "prompts": {}
    },
    "serverInfo": {
      "name": "filesystem",
      "version": "1.0.0"
    }
  }
}
2List tools (tools/list)
3Call tool (tools/call)
4Return result
Deep Dive: JSON-RPC 2.0 Message Format
Request Message Structure
{
  "jsonrpc": "2.0",           // protocol version
  "id": 1,                     // request ID used to match response
  "method": "tools/call",      // method name
  "params": { ... }            // parameter object
}
Response Message Structure
// Successful response
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": { ... }
}

// Error response
{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32600,
    "message": "Invalid Request"
  }
}
JSON-RPC 2.0 is stateless. Every request includes an id so the client can match the response.
Deep Dive: Two Transport Modes
stdio (local process)
Used for local tools through standard input and output.
// Start MCP Server as a child process
npx @modelcontextprotocol/server-filesystem ./project

// Communicate through stdio
// stdin: receive requests
// stdout: send responses
HTTP + SSE (remote)
Used for remote services with long-lived push connections.
// HTTP transport with Server-Sent Events
POST /mcp HTTP/1.1
Content-Type: application/json

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": { ... }
}

// SSE long connection for push updates
GET /mcp/sse HTTP/1.1
// Continuously receive server updates
Deep Dive: MCP Core APIs
initializeInitialize
Server declares protocol version and capabilities to the client.
tools/listTool list
Get all available tools provided by the server.
tools/callCall tool
Call a specific tool and receive the result.
resources/listResource list
Get accessible resources such as files and databases.
resources/readRead resource
Read content from a specific resource.
prompts/listPrompt templates
Get predefined prompt templates.

2.5 類比理解:USB-C 介面

MCP 就像 USB-C 介面

  • 以前:每個裝置都有自己的充電口(圓口、扁口、磁吸……)
  • 現在:USB-C 統一了所有裝置的充電和資料傳輸
  • MCP:統一了 AI 與所有工具的連線方式

工具開發者只需要實作一次 MCP Server,所有支援 MCP 的 AI 應用(Claude、Cursor、Windsurf 等)都能直接使用。

2.6 MCP 的典型應用情境

情境說明範例
本地檔案操作讓 AI 讀取/修改本地檔案讀取程式碼庫、分析日誌檔案
資料庫查詢讓 AI 直接查詢資料庫SQL 查詢、資料分析
API 呼叫讓 AI 呼叫第三方服務GitHub API、Slack、郵件
開發工具整合讓 AI 使用開發工具Git 操作、終端機指令

實際案例

  • Cursor/Windsurf:透過 MCP 連線檔案系統、Git、終端機
  • Claude Desktop:透過 MCP 連線筆記軟體、郵件客戶端
  • 自動化腳本:讓 AI 執行自動化任務(備份、部署、資料同步)

3. A2A (Agent-to-Agent Protocol)

3.1 協定基本資訊

項目內容
全稱Agent-to-Agent Protocol
發起方Google
發布時間2025 年 4 月 9 日
官方文件google.github.io/A2A
開源協定Apache 2.0
GitHubgithub.com/google/A2A

為什麼是 Google 發起?

Google 在 Cloud Next 2025 大會上發布 A2A,與其企業級 AI 戰略密切相關。

Google 認為:未來的企業 AI 不是單個超級 Agent,而是多個專業 Agent 協作——有的負責資料分析,有的負責程式碼生成,有的負責文件處理。

這些 Agent 需要一種標準化的方式相互通訊,A2A 應運而生。

3.2 發布的背景

MCP 解決了「AI 如何連線工具」的問題,但還有一個問題:多個 Agent 如何協作?

想像一個情境:

  • Agent A 是「需求分析專家」
  • Agent B 是「程式碼生成專家」
  • Agent C 是「測試專家」

使用者說:「幫我開發一個登入功能」

Agent A 分析需求後,需要把任務分配給 Agent B;Agent B 寫完程式碼後,需要讓 Agent C 測試。它們之間如何通訊?

Google 在官方部落格中寫道:

"A2A is an open protocol that enables AI agents to communicate with each other, facilitating collaboration across different frameworks and vendors."

核心目標:讓不同廠商、不同框架開發的 Agent 能夠無縫協作。

3.3 A2A 是什麼?

What is A2A?
A2A (Agent-to-Agent Protocol) is a communication standard introduced by Google in April 2025 for collaboration between agents. It lets agents from different vendors and frameworks discover each other, assign tasks, and exchange information, like an intercom for the AI world.
Core Concepts
Agent Card
Public metadata for each agent, including capability descriptions, version, and endpoint.
Task
A work unit passed between agents. It can include multi-turn dialogue and file attachments.
Message
Communication content between agents, supporting text, files, audio, and other modalities.
SSE (Server-Sent Events)
A server push mechanism used for real-time task progress updates.
When should you use A2A?
When multiple agents need to complete a complex task
One agent analyzes requirements, another writes code, and another tests the result.
When integrating agents from different vendors
Agents from Google, Anthropic, OpenAI, and others need to collaborate.
When task delegation and progress tracking are needed
A main agent assigns work to expert agents and receives live progress updates.
How do you use A2A?
1
Publish an Agent Card
Expose the agent capability description at /.well-known/agent.json.
2
Discover agents
Use the agents/get API to fetch another agent card and inspect capabilities.
3
Send a task
Use the tasks/send API to send work, optionally receiving progress through SSE.
4
Fetch the result
After completion, use the tasks/get API to retrieve the final result.

三大核心概念

概念英文作用類比
Agent CardAgent 名片描述 Agent 的能力員工工牌
Task任務要執行的工作單元工單
Message訊息Agent 之間的通訊內容聊天記錄

3.4 A2A 的內部實作

A2A InternalsCommunication details of the peer-to-peer architecture
What can A2A do?

A2A lets multiple AI agents collaborate instead of working alone. A complex task can be assigned to specialized agents, each doing what it is best at.

How do you use A2A?

A2A is still early and mainly driven by Google. To try it, you need to develop an agent service that supports the A2A protocol.

1
Implement the Agent Card endpoint
Expose /.well-known/agent.json in your agent service and declare capabilities and version.
2
Implement A2A APIs
Implement core APIs such as agents/get, tasks/send, and tasks/get.
3
Deploy and register the agent
Deploy the agent to a server and register it so other agents can discover it.
Current Status
A2A was released in April 2025 and is still evolving quickly. Google provides reference implementations, while the ecosystem is still being built. Follow the official docs for current progress.
Communication Flow (5 Steps)
1Discovery (agents/get)
Agents fetch each other Agent Cards over HTTP to understand capabilities and versions.
HTTP request
// Agent A fetches Agent B's Agent Card
GET /.well-known/agent.json HTTP/1.1
Host: agent-b.company.com

// Response
{
  "name": "Code Agent",
  "description": "Professional code generation agent",
  "url": "https://agent-b.company.com",
  "version": "1.0.0",
  "capabilities": {
    "streaming": true,
    "pushNotifications": true
  },
  "skills": [
    {"id": "code-gen", "name": "Code generation"},
    {"id": "code-review", "name": "Code review"}
  ]
}
2Send task (tasks/send)
3Process task
4Push updates (SSE)
5Return result (tasks/get)
Deep Dive: Agent Card Format
An Agent Card is a JSON file, usually hosted at /.well-known/agent.json.
Agent Card Example
{
  "name": "Code Generation Agent",
  "description": "Professional frontend and backend code generation agent",
  "url": "https://code-agent.company.com",
  "version": "1.0.0",
  "capabilities": {
    "streaming": true,
    "pushNotifications": true
  },
  "skills": [
    {
      "id": "frontend",
      "name": "Frontend development",
      "description": "React/Vue/Angular"
    },
    {
      "id": "backend",
      "name": "Backend development",
      "description": "Node/Python/Go"
    }
  ],
  "authentication": {
    "schemes": ["Bearer", "OAuth2"]
  }
}
With Agent Cards, agents can discover each other, understand capabilities and versions, and interoperate.
Deep Dive: HTTP + SSE Communication
Task Send (HTTP POST)
POST /tasks/send HTTP/1.1
Host: agent-b.company.com
Content-Type: application/json
Authorization: Bearer {token}

{
  "id": "task-001",
  "message": {
    "role": "user",
    "parts": [{ "type": "text", "text": "Write a login endpoint" }]
  }
}
Real-time Push (SSE)
GET /tasks/task-001/sse HTTP/1.1
Authorization: Bearer {token}

event: progress
data: {"status": "processing", "progress": 50}

event: completed
data: {"status": "completed", "result": {...}}
SSE (Server-Sent Events) lets the server push messages, which works well for long-running task status updates.
Deep Dive: A2A Core APIs
GETagents/get
Fetch the target agent Agent Card and inspect capabilities.
POSTtasks/send
Send a task to the target agent and wait synchronously for the result.
POSTtasks/sendSubscribe
Send a task and subscribe to SSE progress updates.
GETtasks/get
Fetch task status and result by task ID.
GETtasks/cancel
Cancel a running task.
Deep Dive: Authentication
API Key
Simple authentication for internal agent communication.
Authorization: Bearer sk-xxxxx
# or
Authorization: ApiKey sk-xxxxx
OAuth 2.0
Enterprise authentication with token refresh and permission control.
Authorization: Bearer {access_token}
# refresh token supported
POST /oauth/token
{
  "grant_type": "refresh_token",
  "refresh_token": "xxx"
}

3.5 類比理解:企業微信

A2A 就像 企業微信

  • Agent Card:每個人的名片,顯示姓名、部門、職責
  • 發任務:@某人,分配一個任務
  • 聊天溝通:任務執行過程中可以隨時溝通
  • 任務追蹤:能看到任務的進度和狀態

不同的 Agent 就像不同的同事,A2A 讓它們能夠協作完成複雜專案。

3.6 A2A 的典型應用情境

情境說明範例
軟體開發多 Agent 協作完成開發任務需求分析→程式碼→測試→部署
企業工作流程不同部門 Agent 協作處理業務HR Agent + 財務 Agent + 法務 Agent
智慧客服多個專業 Agent 分工處理接待→解答→轉接→記錄
資料分析多個 Agent 協作分析資料收集→清洗→分析→視覺化→報告

實際案例

  • Google Agent Space:企業內部多個 Agent 協作處理文件、郵件、日程
  • 軟體開發團隊:需求 Agent → 程式碼 Agent → 測試 Agent → 部署 Agent
  • 智慧客服系統:接待 Agent → 專業解答 Agent → 人工轉接 Agent

4. MCP vs A2A:對比與關係

4.1 核心差異

維度MCPA2A
發起方Anthropic (2024.11)Google (2025.04)
定位AI 與工具的連線Agent 與 Agent 的協作
通訊範圍Client-ServerPeer-to-Peer
資料格式JSON-RPC 2.0HTTP + JSON
類比USB-C 介面企業微信

4.2 兩者的關係

MCP 和 A2A 不是競爭關係,而是互補關係

MCP vs A2APositioning differences between two major AI Agent protocols
Imagine a large shopping mall: MCP is like a unified outlet standard, so every tool can plug in; A2A is like an internal intercom system, so different agents can coordinate with each other.
MCPTool connection
Model Context Protocol
A protocol that connects AI applications with external tools and data sources, so tool builders can write once and support many AI apps.
InitiatorAnthropic
Released2024.11
ArchitectureClient-Server
Data formatJSON-RPC 2.0
AnalogyUSB-C: one interface for many devices
A2AAgent collaboration
Agent-to-Agent Protocol
A communication protocol that lets agents from different vendors and frameworks collaborate smoothly.
InitiatorGoogle
Released2025.04
ArchitecturePeer-to-Peer
Data formatHTTP + JSON
AnalogyWork chat: coworkers can assign tasks and talk
Core idea:MCP and A2A are complementary, not competing. MCP answers "how can AI access external capabilities"; A2A answers "how can multiple AI agents collaborate".

4.3 如何選擇?

情境選擇
讓 AI 呼叫本地函式或工具Function Call
使用第三方工具(資料庫、API、檔案系統)MCP
建構多 Agent 協作系統A2A
同時需要工具整合和多 Agent 協作MCP + A2A

5. 協定的未來趨勢

5.1 生態發展

MCP 生態(截至 2025 年初):

  • 官方提供的 Server:檔案系統、SQLite、Git、PostgreSQL 等
  • 社群貢獻的 Server:Slack、Notion、Figma、Stripe 等
  • 支援 MCP 的應用:Claude Desktop、Cursor、Windsurf、Zed 等

A2A 生態(剛發布):

  • Google 自家的 Agent 產品率先支援
  • 開源社群正在開發各種語言的 SDK
  • 企業級應用正在探索中

5.2 標準化程序

目前 Agent 協定還處於「戰國時代」:

  • MCP 和 A2A 是最主流的兩個
  • 還有其他新興協定如 ANP、AGP 等
  • 未來可能會融合或統一

類比網際網路的發展:

  • 早期:各種區域網路協定並存
  • 後來:TCP/IP 成為標準
  • 現在:Agent 協定可能也會走向統一

6. 小結

核心要點

協定一句話理解發布時間發起方適用情境
MCPAI 連線工具的「USB-C」2024.11Anthropic工具整合、資料來源連線
A2AAgent 協作的「企業微信」2025.04Google多 Agent 協作、任務委託

關鍵洞察

  1. MCP 解決「AI 如何取得外部能力」的問題
  2. A2A 解決「多個 AI 如何協作」的問題
  3. 兩者互補,未來可能會融合使用
  4. 選擇協定要根據具體情境,沒有銀彈

參考資料

  1. MCP 官方文件: modelcontextprotocol.io
  2. MCP GitHub: github.com/modelcontextprotocol
  3. Anthropic 發布部落格: "Introducing the Model Context Protocol" (2024-11-25)
  4. A2A 官方文件: google.github.io/A2A
  5. A2A GitHub: github.com/google/A2A
  6. Google Cloud Blog: "Announcing the Agent-to-Agent Protocol" (2025-04-09)