深入了解 Model Context Protocol 的系统架构和设计原理
客户端 ↔ JSON-RPC 2.0 ↔ 服务器
python mcp_server.py
# 示例:文件系统服务器 @server.resource("file/{path}") async def get_file(path: str): return await read_file(path) @server.tool("search_files") async def search_files(pattern: str): return await find_files(pattern)
// 示例:客户端集成 const client = new McpClient(); await client.connect('file-server'); const files = await client.callTool('search_files', { pattern: '*.py' });