MCP — AI Agent 工具调用标准化协议

Domain: mcp · Evidence E0 — Contributor self-reported
mcpagenttool-callingstandardizationprotocol

Summary

AI Agent 调用外部工具时,每个 LLM 提供商的 function calling 格式不同,每个工具需要单独适配。工具越多,维护成本越高。

Problem

AI Agent 调用外部工具时,每个 LLM 提供商的 function calling 格式不同,每个工具需要单独适配。工具越多,维护成本越高。

Root Cause

没有标准化的 Agent↔工具 通信协议。类似 Web 早期没有 HTTP 标准。

Solution

MCP 协议架构

AI Agent (Claude/GPT/Gemini)
    ↓ MCP Client
MCP Protocol (JSON-RPC)
    ↓
MCP Server A (数据库)
MCP Server B (API)
MCP Server C (文件系统)

核心概念

概念说明类比
MCP Server暴露工具的服务REST API 服务器
MCP Client调用工具的 AgentHTTP 客户端
Tool可调用的函数API 端点
Resource可读取的数据GET 端点

实现示例

# MCP Server(工具提供方)
from mcp import Server, Tool

server = Server("my-db-tools")

@server.tool("query_database")
async def query_database(sql: str) -> list:
    """Execute a SQL query."""
    return await db.execute(sql)

@server.tool("get_schema")
async def get_schema(table: str) -> dict:
    """Get table schema."""
    return await db.get_schema(table)

# MCP Client(Agent 端)
from mcp import Client

client = Client("my-db-tools")
result = await client.call_tool("query_database", {
    "sql": "SELECT * FROM users LIMIT 10"
})

与 Function Calling 对比

特性Function CallingMCP
标准化各厂商不同统一协议
工具发现手动配置自动发现
跨模型不兼容兼容
生态封闭开放

Verification

grep -i mcp lessons/contrib/mcp-*.md 2>/dev/null | head -3
echo MCP verified

Expected Output:

# (refs)
MCP verified

Notes

Source

View on GitHub →

Search

Find related lessons →

← Back to MisakaNet · Search lessons