{"id":97028,"date":"2026-08-28T22:16:31","date_gmt":"2026-08-28T14:16:31","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/97028.html"},"modified":"2026-08-28T22:16:31","modified_gmt":"2026-08-28T14:16:31","slug":"mcp%e5%8d%8f%e8%ae%ae%e4%bb%8e%e9%9b%b6%e5%ae%9e%e7%8e%b0%ef%bc%9a%e6%89%8b%e5%86%99%e4%b8%80%e4%b8%aa%e5%ae%8c%e6%95%b4%e7%9a%84-model-context-protocol-%e6%9c%8d%e5%8a%a1%e5%99%a8%e4%b8%8e%e5%ae%a2","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/97028.html","title":{"rendered":"MCP\u534f\u8bae\u4ece\u96f6\u5b9e\u73b0\uff1a\u624b\u5199\u4e00\u4e2a\u5b8c\u6574\u7684 Model Context Protocol \u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef"},"content":{"rendered":"<h3>\u5f15\u8a00<\/h3>\n<p>2025-2026\u5e74\u662fAI Agent\u4ece\u6982\u5ff5\u8d70\u5411\u843d\u5730\u7684\u7206\u53d1\u671f\u3002\u4eceClaude Code\u3001Cursor\u5230Visual Studio Code Copilot&#xff0c;\u51e0\u4e4e\u4e3b\u6d41AI\u5e94\u7528\u90fd\u5728\u5411&#034;\u667a\u80fd\u4f53&#034;\u5f62\u6001\u6f14\u8fdb\u2014\u2014\u5b83\u4eec\u4e0d\u518d\u53ea\u662f\u95ee\u7b54\u673a\u5668\u4eba&#xff0c;\u800c\u662f\u80fd\u591f\u81ea\u4e3b\u8c03\u7528\u5de5\u5177\u3001\u8bfb\u53d6\u6587\u4ef6\u3001\u64cd\u4f5c\u6570\u636e\u5e93\u7684\u771f\u5b9e\u751f\u4ea7\u529b\u5de5\u5177\u3002<\/p>\n<p>\u7136\u800c&#xff0c;\u8fd9\u4e9b\u80fd\u529b\u80cc\u540e\u6709\u4e00\u4e2a\u5173\u952e\u7684\u6807\u51c6\u5316\u534f\u8bae\u6b63\u5728\u6084\u7136\u98a0\u8986\u6574\u4e2a\u751f\u6001&#xff1a;MCP&#xff08;Model Context Protocol&#xff0c;\u6a21\u578b\u4e0a\u4e0b\u6587\u534f\u8bae&#xff09;\u3002<\/p>\n<p>\u7531Anthropic\u63a8\u51fa\u7684MCP&#xff0c;\u88ab\u4e1a\u754c\u79f0\u4e3a&#034;AI\u754c\u7684USB-C\u63a5\u53e3&#034;\u3002\u5b83\u7edf\u4e00\u4e86AI\u5e94\u7528\u4e0e\u5916\u90e8\u6570\u636e\u6e90\u3001\u5de5\u5177\u4e4b\u95f4\u7684\u901a\u4fe1\u6807\u51c6&#xff0c;\u8ba9\u4e00\u6b21\u5f00\u53d1\u3001\u5230\u5904\u8fd0\u884c\u6210\u4e3a\u53ef\u80fd\u3002\u622a\u81f32026\u5e74\u4e2d&#xff0c;MCP\u751f\u6001\u5df2\u8986\u76d6Claude\u3001ChatGPT\u3001VS Code\u3001Cursor\u7b49\u4e3b\u6d41\u5e73\u53f0&#xff0c;\u6ce8\u518cMCP\u670d\u52a1\u5668\u6570\u91cf\u7a81\u7834\u6570\u5343\u4e2a\u3002<\/p>\n<p>\u672c\u6587\u5c06\u4ece\u96f6\u5f00\u59cb\u624b\u5199\u4e00\u4e2a\u5b8c\u6574\u7684MCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u3002\u6211\u4eec\u4e0d\u4f9d\u8d56\u4efb\u4f55MCP SDK&#xff0c;\u76f4\u63a5\u57fa\u4e8eJSON-RPC\u534f\u8bae\u6784\u5efa&#xff0c;\u8ba9\u4f60\u4ece\u5e95\u5c42\u5f7b\u5e95\u7406\u89e3MCP\u7684\u5de5\u4f5c\u673a\u5236\u3002<\/p>\n<p>\u5b9e\u6218\u6307\u5357&#xff1a;\u672c\u6587\u63d0\u4f9b\u5b8c\u6574\u53ef\u8fd0\u884c\u7684\u4ee3\u7801\u793a\u4f8b&#xff0c;\u5efa\u8bae\u8fb9\u770b\u8fb9\u5b9e\u8df5\u3002\u66f4\u591aAI Agent\u5b9e\u6218\u6559\u7a0b\u53c2\u89c1&#xff1a;DeepSeek \u5b9e\u6218\u6307\u5357\u7cfb\u5217<\/p>\n<hr \/>\n<h3>\u4e00\u3001MCP \u6838\u5fc3\u67b6\u6784\u89e3\u6790<\/h3>\n<h4>1.1 \u4ec0\u4e48\u662fMCP&#xff1f;<\/h4>\n<p>MCP&#xff08;Model Context Protocol&#xff09;\u662f\u4e00\u4e2a\u5f00\u653e\u7684\u3001\u6807\u51c6\u5316\u7684\u534f\u8bae&#xff0c;\u7528\u4e8e\u5728AI\u5e94\u7528&#xff08;\u5982Claude\u3001VS Code\u7b49&#xff09;\u548c\u5916\u90e8\u6570\u636e\u6e90\/\u5de5\u5177\u4e4b\u95f4\u5efa\u7acb\u5b89\u5168\u7684\u901a\u4fe1\u901a\u9053\u3002<\/p>\n<p>\u7c7b\u6bd4\u7406\u89e3&#xff1a; &#8211; HTTP \u8ba9\u6d4f\u89c8\u5668\u4e0eWeb\u670d\u52a1\u5668\u901a\u4fe1 \u2192 \u4e92\u8054\u7f51\u65f6\u4ee3\u7684\u57fa\u7840\u8bbe\u65bd &#8211; MCP \u8ba9AI\u5e94\u7528\u4e0e\u5916\u90e8\u5de5\u5177\u901a\u4fe1 \u2192 AI Agent\u65f6\u4ee3\u7684\u57fa\u7840\u8bbe\u65bd<\/p>\n<p>MCP\u534f\u8bae\u7684\u6838\u5fc3\u4f7f\u547d\u662f\u56de\u7b54\u4e09\u4e2a\u95ee\u9898&#xff1a; 1. AI\u5982\u4f55\u53d1\u73b0\u53ef\u7528\u5de5\u5177&#xff1f; \u2192 \u901a\u8fc7 tools\/list \u65b9\u6cd5 2. AI\u5982\u4f55\u8c03\u7528\u5de5\u5177&#xff1f; \u2192 \u901a\u8fc7 tools\/call \u65b9\u6cd5 3. AI\u5982\u4f55\u83b7\u53d6\u4e0a\u4e0b\u6587\u6570\u636e&#xff1f; \u2192 \u901a\u8fc7 resources\/read \u65b9\u6cd5<\/p>\n<h4>1.2 \u4e09\u8981\u7d20\u89d2\u8272<\/h4>\n<p>MCP\u67b6\u6784\u7531\u4e09\u4e2a\u5c42\u6b21\u6784\u6210&#xff1a;<\/p>\n<p>MCP\u4e3b\u673a&#xff08;Host&#xff09;&#xff1a;\u8fd0\u884cAI\u5927\u6a21\u578b\u7684\u5e94\u7528&#xff0c;\u4f8b\u5982Claude Desktop\u3001VS Code\u3001Cursor\u7b49\u3002\u4e3b\u673a\u8d1f\u8d23\u534f\u8c03\u591a\u4e2aMCP\u5ba2\u6237\u7aef\u3002<\/p>\n<p>MCP\u5ba2\u6237\u7aef&#xff08;Client&#xff09;&#xff1a;\u4e0e\u5177\u4f53MCP\u670d\u52a1\u5668\u5efa\u7acb\u4e00\u5bf9\u4e00\u8fde\u63a5\u7684\u4fe1\u9053\u7ec4\u4ef6\u3002\u6bcf\u4e2aMCP\u5ba2\u6237\u7aef\u7ef4\u62a4\u4e0e\u4e00\u4e2aMCP\u670d\u52a1\u5668\u7684\u4e13\u7528\u8fde\u63a5\u3002<\/p>\n<p>MCP\u670d\u52a1\u5668&#xff08;Server&#xff09;&#xff1a;\u63d0\u4f9b\u5de5\u5177\u3001\u8d44\u6e90\u6216\u63d0\u793a\u6a21\u677f\u7684\u5916\u90e8\u7a0b\u5e8f\u3002\u53ef\u4ee5\u672c\u5730\u8fd0\u884c&#xff08;\u5982\u6587\u4ef6\u7cfb\u7edf\u670d\u52a1\u5668&#xff09;&#xff0c;\u4e5f\u53ef\u4ee5\u8fdc\u7a0b\u90e8\u7f72&#xff08;\u5982Sentry MCP\u670d\u52a1\u5668&#xff09;\u3002<\/p>\n<p> \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502          MCP \u4e3b\u673a (VS Code)         \u2502<br \/>\n\u2502  \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510  \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510        \u2502<br \/>\n\u2502  \u2502 Client 1 \u2502  \u2502 Client 2 \u2502        \u2502<br \/>\n\u2502  \u2514\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2518  \u2514\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2518        \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<br \/>\n        \u2502              \u2502<br \/>\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u25bc\u2500\u2500\u2500\u2500\u2500\u2500\u2510 \u250c\u2500\u2500\u2500\u2500\u2500\u25bc\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502 Server A     \u2502 \u2502 Server B     \u2502<br \/>\n\u2502 (Filesystem) \u2502 \u2502 (Database)   \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518 \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/p>\n<h4>1.3 \u4e24\u5c42\u534f\u8bae\u6808<\/h4>\n<p>MCP\u534f\u8bae\u5206\u4e3a\u4e24\u4e2a\u6838\u5fc3\u5c42\u6b21&#xff1a;<\/p>\n<p>\u6570\u636e\u5c42&#xff08;Data Layer&#xff09;&#xff1a;\u57fa\u4e8eJSON-RPC 2.0\u534f\u8bae&#xff0c;\u5b9a\u4e49\u4e86\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u6d88\u606f\u683c\u5f0f\u3001\u751f\u547d\u5468\u671f\u7ba1\u7406\u548c\u6838\u5fc3\u539f\u8bed&#xff08;\u5de5\u5177\u3001\u8d44\u6e90\u3001\u63d0\u793a\u6a21\u677f&#xff09;\u3002\u6570\u636e\u5c42\u662fMCP\u534f\u8bae\u6700\u6838\u5fc3\u7684\u90e8\u5206&#xff0c;\u4e5f\u662f\u5f00\u53d1\u8005\u6700\u5e38\u76f4\u63a5\u63a5\u89e6\u7684\u5c42\u6b21\u3002\u5b83\u5b9a\u4e49\u4e86\u4e09\u79cd\u670d\u52a1\u5668\u7aef\u539f\u8bed\u548c\u4e09\u79cd\u5ba2\u6237\u7aef\u539f\u8bed&#xff0c;\u5206\u522b\u5bf9\u5e94AI\u5e94\u7528\u4e0e\u5916\u90e8\u4e16\u754c\u7684\u8f93\u5165\u8f93\u51fa\u4ea4\u4e92\u3002<\/p>\n<p>\u4f20\u8f93\u5c42&#xff08;Transport Layer&#xff09;&#xff1a;\u5b9a\u4e49\u4e86\u901a\u4fe1\u673a\u5236\u548c\u4fe1\u9053\u3002\u4f20\u8f93\u5c42\u8d1f\u8d23\u5efa\u7acb\u8fde\u63a5\u3001\u6d88\u606f\u5c01\u5e27\u3001\u5b89\u5168\u901a\u4fe1\u7b49\u5e95\u5c42\u5de5\u4f5c\u3002MCP\u652f\u6301\u4e24\u79cd\u4f20\u8f93\u65b9\u5f0f&#xff1a;<\/p>\n<ul>\n<li>\n<p>Stdio\u4f20\u8f93&#xff1a;\u901a\u8fc7\u6807\u51c6\u8f93\u5165\/\u8f93\u51fa\u6d41\u8fdb\u884c\u672c\u5730\u8fdb\u7a0b\u95f4\u901a\u4fe1\u3002\u8fd9\u662f\u6700\u5e38\u7528\u7684\u5f00\u53d1\u8c03\u8bd5\u65b9\u5f0f&#xff0c;\u6027\u80fd\u6700\u4f18&#xff0c;\u56e0\u4e3a\u4e0d\u9700\u8981\u7f51\u7edc\u5f00\u9500\u3002\u670d\u52a1\u5668\u8fdb\u7a0b\u7531\u5ba2\u6237\u7aef\u76f4\u63a5\u542f\u52a8&#xff0c;\u53cc\u65b9\u901a\u8fc7stdin\/stdout\u4ea4\u6362JSON-RPC\u6d88\u606f\u3002\u6ce8\u610fStdio\u6a21\u5f0f\u4e0b\u65e5\u5fd7\u5fc5\u987b\u8f93\u51fa\u5230stderr&#xff0c;\u5426\u5219\u4f1a\u7834\u574f\u534f\u8bae\u6d88\u606f\u7684\u5b8c\u6574\u6027\u3002<\/p>\n<\/li>\n<li>\n<p>Streamable HTTP\u4f20\u8f93&#xff1a;\u57fa\u4e8eHTTP POST\u8bf7\u6c42\u53d1\u9001\u5ba2\u6237\u7aef\u5230\u670d\u52a1\u5668\u7684\u6d88\u606f&#xff0c;\u914d\u5408Server-Sent Events&#xff08;SSE&#xff09;\u5b9e\u73b0\u670d\u52a1\u7aef\u63a8\u9001\u80fd\u529b\u3002\u8fd9\u79cd\u4f20\u8f93\u65b9\u5f0f\u652f\u6301\u8fdc\u7a0b\u670d\u52a1\u5668\u901a\u4fe1&#xff0c;\u53ef\u4ee5\u4f7f\u7528Bearer Token\u3001API Key\u7b49\u6807\u51c6HTTP\u8ba4\u8bc1\u65b9\u5f0f\u3002Anthropic\u63a8\u8350\u4f7f\u7528OAuth 2.0\u83b7\u53d6\u8ba4\u8bc1\u4ee4\u724c&#xff0c;\u786e\u4fdd\u8fdc\u7a0b\u8c03\u7528\u7684\u5b89\u5168\u6027\u3002<\/p>\n<\/li>\n<\/ul>\n<p>\u534f\u8bae\u7248\u672c\u4e0e\u517c\u5bb9\u6027&#xff1a;MCP\u5f53\u524d\u4f7f\u7528\u7684\u534f\u8bae\u7248\u672c\u6807\u8bc6\u4e3a 2024-11-05&#xff08;\u4ee5\u65e5\u671f\u547d\u540d&#xff09;\u3002\u5728\u521d\u59cb\u5316\u9636\u6bb5&#xff0c;\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u5668\u4f1a\u534f\u5546\u534f\u8bae\u7248\u672c&#xff0c;\u786e\u4fdd\u53cc\u65b9\u4f7f\u7528\u517c\u5bb9\u7684\u534f\u8bae\u80fd\u529b\u3002\u5982\u679c\u670d\u52a1\u5668\u4e0d\u652f\u6301\u5ba2\u6237\u7aef\u8bf7\u6c42\u7684\u7248\u672c&#xff0c;\u53ef\u4ee5\u5728\u521d\u59cb\u5316\u54cd\u5e94\u4e2d\u58f0\u660e\u81ea\u5df1\u652f\u6301\u7684\u7248\u672c&#xff0c;\u7531\u5ba2\u6237\u7aef\u51b3\u5b9a\u662f\u5426\u7ee7\u7eed\u8fde\u63a5\u3002<\/p>\n<hr \/>\n<h3>\u4e8c\u3001\u534f\u8bae\u5e95\u5c42&#xff1a;JSON-RPC 2.0 \u7cbe\u8981<\/h3>\n<p>\u5728\u52a8\u624b\u5199MCP\u4e4b\u524d&#xff0c;\u6211\u4eec\u5fc5\u987b\u5148\u7406\u89e3\u5176\u5e95\u5c42\u7684RPC\u534f\u8bae\u3002MCP\u5b8c\u5168\u57fa\u4e8eJSON-RPC 2.0\u89c4\u8303&#xff0c;\u6bcf\u4e2a\u6d88\u606f\u90fd\u662f\u4e00\u4e2aJSON\u5bf9\u8c61\u3002<\/p>\n<h4>2.1 \u8bf7\u6c42\u683c\u5f0f<\/h4>\n<p> {<br \/>\n  &#034;jsonrpc&#034;: &#034;2.0&#034;,<br \/>\n  &#034;id&#034;: 1,<br \/>\n  &#034;method&#034;: &#034;tools\/list&#034;,<br \/>\n  &#034;params&#034;: {}<br \/>\n}<\/p>\n<p>\u5173\u952e\u5b57\u6bb5&#xff1a; &#8211; jsonrpc&#xff1a;\u56fa\u5b9a\u4e3a &#034;2.0&#034; &#8211; id&#xff1a;\u8bf7\u6c42\u552f\u4e00\u6807\u8bc6&#xff0c;\u54cd\u5e94\u4f1a\u643a\u5e26\u76f8\u540c\u7684id &#8211; method&#xff1a;\u8981\u8c03\u7528\u7684\u65b9\u6cd5\u540d &#8211; params&#xff1a;\u65b9\u6cd5\u53c2\u6570&#xff08;\u53ef\u9009&#xff09;<\/p>\n<h4>2.2 \u54cd\u5e94\u683c\u5f0f<\/h4>\n<p> {<br \/>\n  &#034;jsonrpc&#034;: &#034;2.0&#034;,<br \/>\n  &#034;id&#034;: 1,<br \/>\n  &#034;result&#034;: {<br \/>\n    &#034;tools&#034;: [<br \/>\n      {<br \/>\n        &#034;name&#034;: &#034;calculator&#034;,<br \/>\n        &#034;description&#034;: &#034;\u6267\u884c\u6570\u5b66\u8ba1\u7b97&#034;,<br \/>\n        &#034;inputSchema&#034;: {<br \/>\n          &#034;type&#034;: &#034;object&#034;,<br \/>\n          &#034;properties&#034;: {<br \/>\n            &#034;expression&#034;: {&#034;type&#034;: &#034;string&#034;}<br \/>\n          },<br \/>\n          &#034;required&#034;: [&#034;expression&#034;]<br \/>\n        }<br \/>\n      }<br \/>\n    ]<br \/>\n  }<br \/>\n}<\/p>\n<h4>2.3 \u901a\u77e5\u683c\u5f0f<\/h4>\n<p>\u901a\u77e5\u662f\u65e0\u9700\u54cd\u5e94\u7684\u8bf7\u6c42&#xff0c;id\u5b57\u6bb5\u88ab\u7701\u7565&#xff1a;<\/p>\n<p> {<br \/>\n  &#034;jsonrpc&#034;: &#034;2.0&#034;,<br \/>\n  &#034;method&#034;: &#034;notifications\/tools\/list_changed&#034;,<br \/>\n  &#034;params&#034;: {}<br \/>\n}<\/p>\n<h4>2.4 \u9519\u8bef\u54cd\u5e94<\/h4>\n<p>\u5f53\u8bf7\u6c42\u5904\u7406\u5931\u8d25\u65f6&#xff0c;\u670d\u52a1\u5668\u8fd4\u56de\u9519\u8bef\u54cd\u5e94&#xff1a;<\/p>\n<p> {<br \/>\n  &#034;jsonrpc&#034;: &#034;2.0&#034;,<br \/>\n  &#034;id&#034;: 1,<br \/>\n  &#034;error&#034;: {<br \/>\n    &#034;code&#034;: -32601,<br \/>\n    &#034;message&#034;: &#034;Method not found&#034;<br \/>\n  }<br \/>\n}<\/p>\n<p>\u9519\u8bef\u54cd\u5e94\u4e0e\u6210\u529f\u54cd\u5e94\u7684\u533a\u522b\u5728\u4e8e\u5305\u542berror\u5b57\u6bb5\u800c\u975eresult\u5b57\u6bb5\u3002\u9519\u8bef\u5bf9\u8c61\u5305\u542b\u4e09\u4e2a\u5c5e\u6027&#xff1a;code&#xff08;\u6574\u6570\u9519\u8bef\u7801&#xff09;\u3001message&#xff08;\u9519\u8bef\u63cf\u8ff0\u5b57\u7b26\u4e32&#xff09;\u548c\u53ef\u9009\u7684data&#xff08;\u9644\u52a0\u9519\u8bef\u4fe1\u606f&#xff09;\u3002<\/p>\n<p>\u6807\u51c6JSON-RPC\u9519\u8bef\u7801&#xff1a;<\/p>\n<table>\n<tr>\u9519\u8bef\u7801\u542b\u4e49\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>-32700<\/td>\n<td>\u89e3\u6790\u9519\u8bef<\/td>\n<td>\u670d\u52a1\u7aef\u6536\u5230\u65e0\u6548\u7684JSON&#xff0c;\u5e94\u68c0\u67e5\u6d88\u606f\u683c\u5f0f<\/td>\n<\/tr>\n<tr>\n<td>-32600<\/td>\n<td>\u65e0\u6548\u8bf7\u6c42<\/td>\n<td>\u53d1\u9001\u7684JSON\u4e0d\u662f\u4e00\u4e2a\u5408\u6cd5\u7684\u8bf7\u6c42\u5bf9\u8c61<\/td>\n<\/tr>\n<tr>\n<td>-32601<\/td>\n<td>\u65b9\u6cd5\u672a\u627e\u5230<\/td>\n<td>\u670d\u52a1\u7aef\u4e0d\u5b58\u5728\u8bf7\u6c42\u7684\u65b9\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>-32602<\/td>\n<td>\u65e0\u6548\u53c2\u6570<\/td>\n<td>\u65b9\u6cd5\u53c2\u6570\u7c7b\u578b\u6216\u6570\u91cf\u4e0d\u5408\u6cd5<\/td>\n<\/tr>\n<tr>\n<td>-32603<\/td>\n<td>\u5185\u90e8\u9519\u8bef<\/td>\n<td>\u670d\u52a1\u7aef\u6267\u884c\u65b9\u6cd5\u65f6\u53d1\u751f\u8fd0\u884c\u65f6\u9519\u8bef<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u9664\u4e86\u6807\u51c6JSON-RPC\u9519\u8bef\u7801&#xff0c;MCP\u534f\u8bae\u8fd8\u5b9a\u4e49\u4e86\u4e00\u4e9b\u6269\u5c55\u9519\u8bef\u7801\u7528\u4e8e\u7279\u5b9a\u573a\u666f\u3002\u7406\u89e3\u8fd9\u4e9b\u9519\u8bef\u7801\u5bf9\u4e8e\u8c03\u8bd5MCP\u5e94\u7528\u7a0b\u5e8f\u81f3\u5173\u91cd\u8981\u2014\u2014\u5927\u90e8\u5206\u8fde\u63a5\u95ee\u9898\u90fd\u53ef\u4ee5\u901a\u8fc7\u67e5\u770b\u9519\u8bef\u7801\u6765\u5feb\u901f\u5b9a\u4f4d\u3002<\/p>\n<h4>2.5 \u6d88\u606f\u4ea4\u4e92\u5b9e\u4f8b<\/h4>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5b8c\u6574\u7684MCP\u6d88\u606f\u4ea4\u4e92\u5e8f\u5217&#xff0c;\u5c55\u793a\u4ece\u521d\u59cb\u5316\u5230\u5de5\u5177\u8c03\u7528\u7684\u5168\u8fc7\u7a0b&#xff1a;<\/p>\n<p>\u7b2c1\u6b65&#xff1a;\u5ba2\u6237\u7aef\u53d1\u9001\u521d\u59cb\u5316\u8bf7\u6c42<\/p>\n<p> &#8211;&gt; {&#034;jsonrpc&#034;:&#034;2.0&#034;,&#034;id&#034;:1,&#034;method&#034;:&#034;initialize&#034;,&#034;params&#034;:{&#034;protocolVersion&#034;:&#034;2024-11-05&#034;,&#034;capabilities&#034;:{},&#034;clientInfo&#034;:{&#034;name&#034;:&#034;my-mcp-client&#034;,&#034;version&#034;:&#034;1.0.0&#034;}}}<\/p>\n<p>&lt;&#8211; {&#034;jsonrpc&#034;:&#034;2.0&#034;,&#034;id&#034;:1,&#034;result&#034;:{&#034;protocolVersion&#034;:&#034;2024-11-05&#034;,&#034;capabilities&#034;:{&#034;tools&#034;:{},&#034;resources&#034;:{}},&#034;serverInfo&#034;:{&#034;name&#034;:&#034;my-mcp-server&#034;,&#034;version&#034;:&#034;1.0.0&#034;}}}<\/p>\n<p>\u7b2c2\u6b65&#xff1a;\u5ba2\u6237\u7aef\u53d1\u9001\u521d\u59cb\u5316\u5b8c\u6210\u901a\u77e5&#xff08;\u65e0\u9700\u54cd\u5e94&#xff09;<\/p>\n<p> &#8211;&gt; {&#034;jsonrpc&#034;:&#034;2.0&#034;,&#034;method&#034;:&#034;notifications\/initialized&#034;}<\/p>\n<p>\u7b2c3\u6b65&#xff1a;\u5ba2\u6237\u7aef\u5217\u51fa\u53ef\u7528\u5de5\u5177<\/p>\n<p> &#8211;&gt; {&#034;jsonrpc&#034;:&#034;2.0&#034;,&#034;id&#034;:2,&#034;method&#034;:&#034;tools\/list&#034;}<\/p>\n<p>&lt;&#8211; {&#034;jsonrpc&#034;:&#034;2.0&#034;,&#034;id&#034;:2,&#034;result&#034;:{&#034;tools&#034;:[{&#034;name&#034;:&#034;calculator&#034;,&#034;description&#034;:&#034;\u6267\u884c\u6570\u5b66\u8ba1\u7b97&#034;,&#034;inputSchema&#034;:{&#034;type&#034;:&#034;object&#034;,&#034;properties&#034;:{&#034;expression&#034;:{&#034;type&#034;:&#034;string&#034;}},&#034;required&#034;:[&#034;expression&#034;]}}]}}<\/p>\n<p>\u7b2c4\u6b65&#xff1a;\u5ba2\u6237\u7aef\u8c03\u7528\u5de5\u5177<\/p>\n<p> &#8211;&gt; {&#034;jsonrpc&#034;:&#034;2.0&#034;,&#034;id&#034;:3,&#034;method&#034;:&#034;tools\/call&#034;,&#034;params&#034;:{&#034;name&#034;:&#034;calculator&#034;,&#034;arguments&#034;:{&#034;expression&#034;:&#034;2&#043;2&#034;}}}<\/p>\n<p>&lt;&#8211; {&#034;jsonrpc&#034;:&#034;2.0&#034;,&#034;id&#034;:3,&#034;result&#034;:{&#034;content&#034;:[{&#034;type&#034;:&#034;text&#034;,&#034;text&#034;:&#034;\u8ba1\u7b97\u7ed3\u679c: 4&#034;}]}}<\/p>\n<p>\u7406\u89e3\u8fd9\u4e09\u4e2a\u5b57\u6bb5&#xff08;jsonrpc\u7248\u672c\u6807\u8bc6\u3001id\u8bf7\u6c42\u6807\u8bc6\u3001method\u65b9\u6cd5\u540d&#xff09;\u7684\u4ea4\u4e92\u6a21\u5f0f&#xff0c;\u5c31\u638c\u63e1\u4e86MCP\u534f\u8bae80%\u7684\u6d88\u606f\u4ea4\u4e92\u903b\u8f91\u3002<\/p>\n<hr \/>\n<h3>\u4e09\u3001\u4ece\u96f6\u6784\u5efaMCP\u670d\u52a1\u5668&#xff08;\u7eafPython&#xff0c;\u65e0SDK&#xff09;<\/h3>\n<p>\u672c\u8282\u6211\u4eec\u5c06\u5b8c\u5168\u4e0d\u4f9d\u8d56\u4efb\u4f55MCP SDK&#xff0c;\u53ea\u7528Python\u6807\u51c6\u5e93\u4ece\u5e95\u5c42\u5b9e\u73b0\u4e00\u4e2a\u5b8c\u6574\u7684MCP\u670d\u52a1\u5668\u3002\u8fd9\u80fd\u8ba9\u4f60\u771f\u6b63\u7406\u89e3MCP\u534f\u8bae\u7684\u672c\u8d28\u3002<\/p>\n<h4>3.1 \u57fa\u7840\u67b6\u6784\u8bbe\u8ba1<\/h4>\n<p>\u6211\u4eec\u7684MCP\u670d\u52a1\u5668\u9700\u8981\u5904\u7406\u4ee5\u4e0b\u6838\u5fc3\u65b9\u6cd5&#xff1a;<\/p>\n<table>\n<tr>\u65b9\u6cd5\u8bf4\u660e<\/tr>\n<tbody>\n<tr>\n<td>initialize<\/td>\n<td>\u521d\u59cb\u5316\u8fde\u63a5&#xff0c;\u534f\u5546\u80fd\u529b<\/td>\n<\/tr>\n<tr>\n<td>tools\/list<\/td>\n<td>\u5217\u51fa\u6240\u6709\u53ef\u7528\u5de5\u5177<\/td>\n<\/tr>\n<tr>\n<td>tools\/call<\/td>\n<td>\u8c03\u7528\u6307\u5b9a\u5de5\u5177<\/td>\n<\/tr>\n<tr>\n<td>resources\/list<\/td>\n<td>\u5217\u51fa\u53ef\u7528\u8d44\u6e90<\/td>\n<\/tr>\n<tr>\n<td>resources\/read<\/td>\n<td>\u8bfb\u53d6\u6307\u5b9a\u8d44\u6e90<\/td>\n<\/tr>\n<tr>\n<td>notifications\/initialized<\/td>\n<td>\u5ba2\u6237\u7aef\u521d\u59cb\u5316\u5b8c\u6210\u901a\u77e5<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4>3.2 \u5b9e\u73b0JSON-RPC\u6d88\u606f\u5904\u7406\u5668<\/h4>\n<p> import json<br \/>\nimport sys<br \/>\nimport logging<br \/>\nfrom typing import Any, Callable<\/p>\n<p>logging.basicConfig(level&#061;logging.INFO, stream&#061;sys.stderr)<\/p>\n<p>class JSONRPCMessage:<br \/>\n    &#034;&#034;&#034;JSON-RPC 2.0 \u6d88\u606f\u5c01\u88c5&#034;&#034;&#034;<\/p>\n<p>    &#064;staticmethod<br \/>\n    def create_request(id: int, method: str, params: dict &#061; None) -&gt; str:<br \/>\n        msg &#061; {<br \/>\n            &#034;jsonrpc&#034;: &#034;2.0&#034;,<br \/>\n            &#034;id&#034;: id,<br \/>\n            &#034;method&#034;: method<br \/>\n        }<br \/>\n        if params is not None:<br \/>\n            msg[&#034;params&#034;] &#061; params<br \/>\n        return json.dumps(msg)<\/p>\n<p>    &#064;staticmethod<br \/>\n    def create_response(id: int, result: Any) -&gt; str:<br \/>\n        return json.dumps({<br \/>\n            &#034;jsonrpc&#034;: &#034;2.0&#034;,<br \/>\n            &#034;id&#034;: id,<br \/>\n            &#034;result&#034;: result<br \/>\n        })<\/p>\n<p>    &#064;staticmethod<br \/>\n    def create_error(id: int, code: int, message: str, data: Any &#061; None) -&gt; str:<br \/>\n        error &#061; {&#034;code&#034;: code, &#034;message&#034;: message}<br \/>\n        if data is not None:<br \/>\n            error[&#034;data&#034;] &#061; data<br \/>\n        return json.dumps({<br \/>\n            &#034;jsonrpc&#034;: &#034;2.0&#034;,<br \/>\n            &#034;id&#034;: id,<br \/>\n            &#034;error&#034;: error<br \/>\n        })<\/p>\n<p>    &#064;staticmethod<br \/>\n    def create_notification(method: str, params: dict &#061; None) -&gt; str:<br \/>\n        msg &#061; {<br \/>\n            &#034;jsonrpc&#034;: &#034;2.0&#034;,<br \/>\n            &#034;method&#034;: method<br \/>\n        }<br \/>\n        if params is not None:<br \/>\n            msg[&#034;params&#034;] &#061; params<br \/>\n        return json.dumps(msg)<\/p>\n<h4>3.3 \u5b9e\u73b0MCP\u670d\u52a1\u5668\u6838\u5fc3<\/h4>\n<p> class MCPServer:<br \/>\n    &#034;&#034;&#034;\u4ece\u96f6\u5b9e\u73b0\u7684MCP\u670d\u52a1\u5668&#034;&#034;&#034;<\/p>\n<p>    def __init__(self, server_name: str &#061; &#034;my-mcp-server&#034;, version: str &#061; &#034;1.0.0&#034;):<br \/>\n        self.server_name &#061; server_name<br \/>\n        self.version &#061; version<br \/>\n        self.tools: dict[str, dict] &#061; {}<br \/>\n        self.tool_handlers: dict[str, Callable] &#061; {}<br \/>\n        self.resources: dict[str, dict] &#061; {}<br \/>\n        self.request_id &#061; 0<\/p>\n<p>    def register_tool(self, name: str, description: str,<br \/>\n                      input_schema: dict, handler: Callable):<br \/>\n        &#034;&#034;&#034;\u6ce8\u518c\u4e00\u4e2aMCP\u5de5\u5177&#034;&#034;&#034;<br \/>\n        self.tools[name] &#061; {<br \/>\n            &#034;name&#034;: name,<br \/>\n            &#034;description&#034;: description,<br \/>\n            &#034;inputSchema&#034;: input_schema<br \/>\n        }<br \/>\n        self.tool_handlers[name] &#061; handler<\/p>\n<p>    def register_resource(self, uri: str, name: str,<br \/>\n                          description: str, mime_type: str &#061; &#034;text\/plain&#034;):<br \/>\n        &#034;&#034;&#034;\u6ce8\u518c\u4e00\u4e2aMCP\u8d44\u6e90&#034;&#034;&#034;<br \/>\n        self.resources[uri] &#061; {<br \/>\n            &#034;uri&#034;: uri,<br \/>\n            &#034;name&#034;: name,<br \/>\n            &#034;description&#034;: description,<br \/>\n            &#034;mimeType&#034;: mime_type<br \/>\n        }<\/p>\n<p>    async def handle_message(self, raw_message: str) -&gt; str | None:<br \/>\n        &#034;&#034;&#034;\u5904\u7406\u4e00\u6761JSON-RPC\u6d88\u606f&#034;&#034;&#034;<br \/>\n        try:<br \/>\n            message &#061; json.loads(raw_message)<br \/>\n        except json.JSONDecodeError:<br \/>\n            return JSONRPCMessage.create_error(0, -32700, &#034;Parse error&#034;)<\/p>\n<p>        method &#061; message.get(&#034;method&#034;, &#034;&#034;)<br \/>\n        msg_id &#061; message.get(&#034;id&#034;)<br \/>\n        params &#061; message.get(&#034;params&#034;, {})<\/p>\n<p>        # \u521d\u59cb\u5316\u9636\u6bb5<br \/>\n        if method &#061;&#061; &#034;initialize&#034;:<br \/>\n            return self._handle_initialize(msg_id, params)<\/p>\n<p>        # \u521d\u59cb\u5316\u5b8c\u6210\u901a\u77e5&#xff08;\u65e0\u54cd\u5e94&#xff09;<br \/>\n        if method &#061;&#061; &#034;notifications\/initialized&#034;:<br \/>\n            logging.info(&#034;Client initialized&#034;)<br \/>\n            return None<\/p>\n<p>        # \u5de5\u5177\u5217\u51fa<br \/>\n        if method &#061;&#061; &#034;tools\/list&#034;:<br \/>\n            return JSONRPCMessage.create_response(<br \/>\n                msg_id, {&#034;tools&#034;: list(self.tools.values())}<br \/>\n            )<\/p>\n<p>        # \u5de5\u5177\u8c03\u7528<br \/>\n        if method &#061;&#061; &#034;tools\/call&#034;:<br \/>\n            return await self._handle_tool_call(msg_id, params)<\/p>\n<p>        # \u8d44\u6e90\u5217\u51fa<br \/>\n        if method &#061;&#061; &#034;resources\/list&#034;:<br \/>\n            return JSONRPCMessage.create_response(<br \/>\n                msg_id, {&#034;resources&#034;: list(self.resources.values())}<br \/>\n            )<\/p>\n<p>        # \u8d44\u6e90\u8bfb\u53d6<br \/>\n        if method &#061;&#061; &#034;resources\/read&#034;:<br \/>\n            return await self._handle_resource_read(msg_id, params)<\/p>\n<p>        # \u672a\u77e5\u65b9\u6cd5<br \/>\n        return JSONRPCMessage.create_error(<br \/>\n            msg_id, -32601, f&#034;Method not found: {method}&#034;<br \/>\n        )<\/p>\n<p>    def _handle_initialize(self, msg_id: int, params: dict) -&gt; str:<br \/>\n        &#034;&#034;&#034;\u5904\u7406\u521d\u59cb\u5316\u8bf7\u6c42&#034;&#034;&#034;<br \/>\n        protocol_version &#061; params.get(&#034;protocolVersion&#034;, &#034;2024-11-05&#034;)<br \/>\n        client_name &#061; params.get(&#034;clientInfo&#034;, {}).get(&#034;name&#034;, &#034;unknown&#034;)<br \/>\n        logging.info(f&#034;Client connecting: {client_name} (v{protocol_version})&#034;)<\/p>\n<p>        # \u8fd4\u56de\u670d\u52a1\u5668\u80fd\u529b\u58f0\u660e<br \/>\n        return JSONRPCMessage.create_response(msg_id, {<br \/>\n            &#034;protocolVersion&#034;: protocol_version,<br \/>\n            &#034;capabilities&#034;: {<br \/>\n                &#034;tools&#034;: {},<br \/>\n                &#034;resources&#034;: {}<br \/>\n            },<br \/>\n            &#034;serverInfo&#034;: {<br \/>\n                &#034;name&#034;: self.server_name,<br \/>\n                &#034;version&#034;: self.version<br \/>\n            }<br \/>\n        })<\/p>\n<p>    async def _handle_tool_call(self, msg_id: int, params: dict) -&gt; str:<br \/>\n        &#034;&#034;&#034;\u5904\u7406\u5de5\u5177\u8c03\u7528\u8bf7\u6c42&#034;&#034;&#034;<br \/>\n        tool_name &#061; params.get(&#034;name&#034;, &#034;&#034;)<br \/>\n        arguments &#061; params.get(&#034;arguments&#034;, {})<\/p>\n<p>        if tool_name not in self.tool_handlers:<br \/>\n            return JSONRPCMessage.create_error(<br \/>\n                msg_id, -32602, f&#034;Unknown tool: {tool_name}&#034;<br \/>\n            )<\/p>\n<p>        try:<br \/>\n            handler &#061; self.tool_handlers[tool_name]<br \/>\n            result &#061; await handler(**arguments)<br \/>\n            return JSONRPCMessage.create_response(msg_id, {<br \/>\n                &#034;content&#034;: [{&#034;type&#034;: &#034;text&#034;, &#034;text&#034;: str(result)}]<br \/>\n            })<br \/>\n        except Exception as e:<br \/>\n            logging.error(f&#034;Tool execution error: {e}&#034;)<br \/>\n            return JSONRPCMessage.create_error(<br \/>\n                msg_id, -32603, f&#034;Internal error: {str(e)}&#034;<br \/>\n            )<\/p>\n<p>    async def _handle_resource_read(self, msg_id: int, params: dict) -&gt; str:<br \/>\n        &#034;&#034;&#034;\u5904\u7406\u8d44\u6e90\u8bfb\u53d6\u8bf7\u6c42&#034;&#034;&#034;<br \/>\n        uri &#061; params.get(&#034;uri&#034;, &#034;&#034;)<br \/>\n        if uri not in self.resources:<br \/>\n            return JSONRPCMessage.create_error(<br \/>\n                msg_id, -32602, f&#034;Resource not found: {uri}&#034;<br \/>\n            )<br \/>\n        # \u8fd4\u56de\u8d44\u6e90\u5185\u5bb9&#xff08;\u7b80\u5316\u5b9e\u73b0&#xff09;<br \/>\n        return JSONRPCMessage.create_response(msg_id, {<br \/>\n            &#034;contents&#034;: [{<br \/>\n                &#034;uri&#034;: uri,<br \/>\n                &#034;mimeType&#034;: self.resources[uri][&#034;mimeType&#034;],<br \/>\n                &#034;text&#034;: f&#034;\u5185\u5bb9\u6765\u81ea\u8d44\u6e90: {uri}&#034;<br \/>\n            }]<br \/>\n        })<\/p>\n<h4>3.4 Stdio\u4f20\u8f93\u5c42\u5b9e\u73b0<\/h4>\n<p>MCP\u901a\u8fc7Stdio\u4f20\u8f93\u5c42\u5b9e\u73b0\u8fdb\u7a0b\u95f4\u901a\u4fe1\u3002\u670d\u52a1\u5668\u4ecestdin\u8bfb\u53d6JSON-RPC\u6d88\u606f&#xff0c;\u5c06\u54cd\u5e94\u5199\u5165stdout\u3002<\/p>\n<p> import asyncio<\/p>\n<p>class StdioTransport:<br \/>\n    &#034;&#034;&#034;Stdio\u4f20\u8f93\u5c42&#034;&#034;&#034;<\/p>\n<p>    def __init__(self, server: MCPServer):<br \/>\n        self.server &#061; server<\/p>\n<p>    async def read_line(self) -&gt; str | None:<br \/>\n        &#034;&#034;&#034;\u4ecestdin\u8bfb\u53d6\u4e00\u884c&#034;&#034;&#034;<br \/>\n        loop &#061; asyncio.get_event_loop()<br \/>\n        line &#061; await loop.run_in_executor(None, sys.stdin.readline)<br \/>\n        return line.strip() if line else None<\/p>\n<p>    def write_message(self, message: str):<br \/>\n        &#034;&#034;&#034;\u5c06\u6d88\u606f\u5199\u5165stdout&#034;&#034;&#034;<br \/>\n        sys.stdout.write(message &#043; &#034;\\\\n&#034;)<br \/>\n        sys.stdout.flush()<\/p>\n<p>    async def run(self):<br \/>\n        &#034;&#034;&#034;\u8fd0\u884c\u4e8b\u4ef6\u5faa\u73af&#034;&#034;&#034;<br \/>\n        while True:<br \/>\n            line &#061; await self.read_line()<br \/>\n            if not line:<br \/>\n                break<\/p>\n<p>            response &#061; await self.server.handle_message(line)<br \/>\n            if response:<br \/>\n                self.write_message(response)<\/p>\n<h4>3.5 \u6ce8\u518c\u5177\u4f53\u5de5\u5177<\/h4>\n<p>\u73b0\u5728&#xff0c;\u8ba9\u6211\u4eec\u4e3a\u670d\u52a1\u5668\u6ce8\u518c\u51e0\u4e2a\u5b9e\u7528\u7684\u5de5\u5177&#xff1a;<\/p>\n<p> import subprocess<br \/>\nimport os<br \/>\nfrom datetime import datetime<\/p>\n<p>async def calculator(expression: str) -&gt; str:<br \/>\n    &#034;&#034;&#034;\u6267\u884c\u6570\u5b66\u8ba1\u7b97&#034;&#034;&#034;<br \/>\n    try:<br \/>\n        # \u6ce8\u610f: \u751f\u4ea7\u73af\u5883\u5e94\u4f7f\u7528\u66f4\u5b89\u5168\u7684\u65b9\u5f0f<br \/>\n        result &#061; eval(expression)<br \/>\n        return f&#034;\u8ba1\u7b97\u7ed3\u679c: {result}&#034;<br \/>\n    except Exception as e:<br \/>\n        return f&#034;\u8ba1\u7b97\u9519\u8bef: {str(e)}&#034;<\/p>\n<p>async def get_current_time(timezone: str &#061; &#034;Asia\/Shanghai&#034;) -&gt; str:<br \/>\n    &#034;&#034;&#034;\u83b7\u53d6\u5f53\u524d\u65f6\u95f4&#034;&#034;&#034;<br \/>\n    now &#061; datetime.now()<br \/>\n    return f&#034;\u5f53\u524d\u65f6\u95f4: {now.strftime(&#039;%Y-%m-%d %H:%M:%S&#039;)} (\u65f6\u533a: {timezone})&#034;<\/p>\n<p>async def list_directory(path: str &#061; &#034;.&#034;) -&gt; str:<br \/>\n    &#034;&#034;&#034;\u5217\u51fa\u76ee\u5f55\u5185\u5bb9&#034;&#034;&#034;<br \/>\n    try:<br \/>\n        files &#061; os.listdir(path)<br \/>\n        return &#034;\\\\n&#034;.join(files) if files else &#034;(\u7a7a\u76ee\u5f55)&#034;<br \/>\n    except Exception as e:<br \/>\n        return f&#034;\u8bfb\u53d6\u76ee\u5f55\u5931\u8d25: {str(e)}&#034;<\/p>\n<p># \u6784\u5efa\u5b8c\u6574\u7684\u670d\u52a1\u5668<br \/>\ndef create_demo_server() -&gt; MCPServer:<br \/>\n    server &#061; MCPServer(&#034;demo-mcp-server&#034;, &#034;1.0.0&#034;)<\/p>\n<p>    server.register_tool(<br \/>\n        name&#061;&#034;calculator&#034;,<br \/>\n        description&#061;&#034;\u6267\u884c\u6570\u5b66\u8ba1\u7b97&#xff0c;\u652f\u6301\u56db\u5219\u8fd0\u7b97\u548c\u51fd\u6570&#034;,<br \/>\n        input_schema&#061;{<br \/>\n            &#034;type&#034;: &#034;object&#034;,<br \/>\n            &#034;properties&#034;: {<br \/>\n                &#034;expression&#034;: {<br \/>\n                    &#034;type&#034;: &#034;string&#034;,<br \/>\n                    &#034;description&#034;: &#034;\u6570\u5b66\u8868\u8fbe\u5f0f&#xff0c;\u5982 &#039;2 &#043; 2&#039; \u6216 &#039;sin(pi\/2)&#039;&#034;<br \/>\n                }<br \/>\n            },<br \/>\n            &#034;required&#034;: [&#034;expression&#034;]<br \/>\n        },<br \/>\n        handler&#061;calculator<br \/>\n    )<\/p>\n<p>    server.register_tool(<br \/>\n        name&#061;&#034;get_current_time&#034;,<br \/>\n        description&#061;&#034;\u83b7\u53d6\u6307\u5b9a\u65f6\u533a\u7684\u5f53\u524d\u65f6\u95f4&#034;,<br \/>\n        input_schema&#061;{<br \/>\n            &#034;type&#034;: &#034;object&#034;,<br \/>\n            &#034;properties&#034;: {<br \/>\n                &#034;timezone&#034;: {<br \/>\n                    &#034;type&#034;: &#034;string&#034;,<br \/>\n                    &#034;description&#034;: &#034;\u65f6\u533a\u540d\u79f0&#xff0c;\u5982 &#039;Asia\/Shanghai&#039;&#034;,<br \/>\n                    &#034;default&#034;: &#034;Asia\/Shanghai&#034;<br \/>\n                }<br \/>\n            }<br \/>\n        },<br \/>\n        handler&#061;get_current_time<br \/>\n    )<\/p>\n<p>    server.register_tool(<br \/>\n        name&#061;&#034;list_directory&#034;,<br \/>\n        description&#061;&#034;\u5217\u51fa\u6307\u5b9a\u76ee\u5f55\u7684\u6587\u4ef6\u548c\u6587\u4ef6\u5939&#034;,<br \/>\n        input_schema&#061;{<br \/>\n            &#034;type&#034;: &#034;object&#034;,<br \/>\n            &#034;properties&#034;: {<br \/>\n                &#034;path&#034;: {<br \/>\n                    &#034;type&#034;: &#034;string&#034;,<br \/>\n                    &#034;description&#034;: &#034;\u76ee\u5f55\u8def\u5f84&#034;,<br \/>\n                    &#034;default&#034;: &#034;.&#034;<br \/>\n                }<br \/>\n            }<br \/>\n        },<br \/>\n        handler&#061;list_directory<br \/>\n    )<\/p>\n<p>    # \u6ce8\u518c\u8d44\u6e90<br \/>\n    server.register_resource(<br \/>\n        uri&#061;&#034;server:\/\/info&#034;,<br \/>\n        name&#061;&#034;\u670d\u52a1\u5668\u4fe1\u606f&#034;,<br \/>\n        description&#061;&#034;MCP\u670d\u52a1\u5668\u7684\u57fa\u672c\u4fe1\u606f&#034;<br \/>\n    )<\/p>\n<p>    return server<\/p>\n<h4>3.6 \u542f\u52a8\u5165\u53e3<\/h4>\n<p> async def main():<br \/>\n    server &#061; create_demo_server()<br \/>\n    transport &#061; StdioTransport(server)<br \/>\n    logging.info(f&#034;Starting MCP server: {server.server_name} v{server.version}&#034;)<br \/>\n    await transport.run()<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    asyncio.run(main())<\/p>\n<hr \/>\n<h3>\u56db\u3001\u4ece\u96f6\u6784\u5efaMCP\u5ba2\u6237\u7aef<\/h3>\n<p>\u6709\u4e86\u670d\u52a1\u5668&#xff0c;\u6211\u4eec\u8fd8\u9700\u8981\u4e00\u4e2a\u5ba2\u6237\u7aef\u6765\u8fde\u63a5\u548c\u4ea4\u4e92\u3002\u540c\u6837&#xff0c;\u6211\u4eec\u4e0d\u4f9d\u8d56\u4efb\u4f55SDK\u3002<\/p>\n<p> import json<br \/>\nimport asyncio<br \/>\nimport subprocess<br \/>\nfrom typing import Any<\/p>\n<p>class MCPClient:<br \/>\n    &#034;&#034;&#034;\u4ece\u96f6\u5b9e\u73b0\u7684MCP\u5ba2\u6237\u7aef&#034;&#034;&#034;<\/p>\n<p>    def __init__(self):<br \/>\n        self.process: subprocess.Popen | None &#061; None<br \/>\n        self.request_id &#061; 0<br \/>\n        self.pending_requests: dict[int, asyncio.Future] &#061; {}<\/p>\n<p>    async def connect_stdio(self, command: str, *args: str):<br \/>\n        &#034;&#034;&#034;\u901a\u8fc7Stdio\u8fde\u63a5\u5230MCP\u670d\u52a1\u5668&#034;&#034;&#034;<br \/>\n        self.process &#061; await asyncio.create_subprocess_exec(<br \/>\n            command, *args,<br \/>\n            stdin&#061;asyncio.subprocess.PIPE,<br \/>\n            stdout&#061;asyncio.subprocess.PIPE,<br \/>\n            stderr&#061;asyncio.subprocess.PIPE<br \/>\n        )<\/p>\n<p>        # \u542f\u52a8\u6d88\u606f\u8bfb\u53d6\u5faa\u73af<br \/>\n        asyncio.create_task(self._read_loop())<\/p>\n<p>    async def _read_loop(self):<br \/>\n        &#034;&#034;&#034;\u6301\u7eed\u8bfb\u53d6\u670d\u52a1\u5668\u54cd\u5e94&#034;&#034;&#034;<br \/>\n        while self.process and self.process.stdout:<br \/>\n            line &#061; await self.process.stdout.readline()<br \/>\n            if not line:<br \/>\n                break<br \/>\n            try:<br \/>\n                response &#061; json.loads(line.decode().strip())<br \/>\n                msg_id &#061; response.get(&#034;id&#034;)<br \/>\n                if msg_id in self.pending_requests:<br \/>\n                    future &#061; self.pending_requests.pop(msg_id)<br \/>\n                    future.set_result(response)<br \/>\n            except json.JSONDecodeError:<br \/>\n                continue<\/p>\n<p>    async def send_request(self, method: str, params: dict &#061; None) -&gt; dict:<br \/>\n        &#034;&#034;&#034;\u53d1\u9001JSON-RPC\u8bf7\u6c42\u5e76\u7b49\u5f85\u54cd\u5e94&#034;&#034;&#034;<br \/>\n        self.request_id &#043;&#061; 1<br \/>\n        request_id &#061; self.request_id<\/p>\n<p>        message &#061; {<br \/>\n            &#034;jsonrpc&#034;: &#034;2.0&#034;,<br \/>\n            &#034;id&#034;: request_id,<br \/>\n            &#034;method&#034;: method<br \/>\n        }<br \/>\n        if params is not None:<br \/>\n            message[&#034;params&#034;] &#061; params<\/p>\n<p>        future &#061; asyncio.get_event_loop().create_future()<br \/>\n        self.pending_requests[request_id] &#061; future<\/p>\n<p>        # \u53d1\u9001\u6d88\u606f<br \/>\n        self.process.stdin.write((json.dumps(message) &#043; &#034;\\\\n&#034;).encode())<br \/>\n        await self.process.stdin.drain()<\/p>\n<p>        # \u7b49\u5f85\u54cd\u5e94<br \/>\n        response &#061; await future<\/p>\n<p>        if &#034;error&#034; in response:<br \/>\n            error &#061; response[&#034;error&#034;]<br \/>\n            raise Exception(f&#034;MCP error [{error[&#039;code&#039;]}]: {error[&#039;message&#039;]}&#034;)<\/p>\n<p>        return response.get(&#034;result&#034;, {})<\/p>\n<p>    async def initialize(self):<br \/>\n        &#034;&#034;&#034;\u521d\u59cb\u5316MCP\u8fde\u63a5&#034;&#034;&#034;<br \/>\n        result &#061; await self.send_request(&#034;initialize&#034;, {<br \/>\n            &#034;protocolVersion&#034;: &#034;2024-11-05&#034;,<br \/>\n            &#034;capabilities&#034;: {},<br \/>\n            &#034;clientInfo&#034;: {<br \/>\n                &#034;name&#034;: &#034;my-mcp-client&#034;,<br \/>\n                &#034;version&#034;: &#034;1.0.0&#034;<br \/>\n            }<br \/>\n        })<br \/>\n        # \u53d1\u9001\u521d\u59cb\u5316\u5b8c\u6210\u901a\u77e5<br \/>\n        self.process.stdin.write(<br \/>\n            (json.dumps({<br \/>\n                &#034;jsonrpc&#034;: &#034;2.0&#034;,<br \/>\n                &#034;method&#034;: &#034;notifications\/initialized&#034;<br \/>\n            }) &#043; &#034;\\\\n&#034;).encode()<br \/>\n        )<br \/>\n        await self.process.stdin.drain()<br \/>\n        return result<\/p>\n<p>    async def list_tools(self) -&gt; list[dict]:<br \/>\n        &#034;&#034;&#034;\u5217\u51fa\u6240\u6709\u53ef\u7528\u5de5\u5177&#034;&#034;&#034;<br \/>\n        result &#061; await self.send_request(&#034;tools\/list&#034;)<br \/>\n        return result.get(&#034;tools&#034;, [])<\/p>\n<p>    async def call_tool(self, name: str, arguments: dict &#061; None) -&gt; Any:<br \/>\n        &#034;&#034;&#034;\u8c03\u7528\u6307\u5b9a\u5de5\u5177&#034;&#034;&#034;<br \/>\n        params &#061; {&#034;name&#034;: name}<br \/>\n        if arguments:<br \/>\n            params[&#034;arguments&#034;] &#061; arguments<br \/>\n        result &#061; await self.send_request(&#034;tools\/call&#034;, params)<br \/>\n        return result<\/p>\n<p>    async def list_resources(self) -&gt; list[dict]:<br \/>\n        &#034;&#034;&#034;\u5217\u51fa\u6240\u6709\u53ef\u7528\u8d44\u6e90&#034;&#034;&#034;<br \/>\n        result &#061; await self.send_request(&#034;resources\/list&#034;)<br \/>\n        return result.get(&#034;resources&#034;, [])<\/p>\n<p>    async def close(self):<br \/>\n        &#034;&#034;&#034;\u5173\u95ed\u8fde\u63a5&#034;&#034;&#034;<br \/>\n        if self.process:<br \/>\n            self.process.terminate()<br \/>\n            await self.process.wait()<\/p>\n<h4>4.1 \u4f7f\u7528\u5ba2\u6237\u7aef\u4ea4\u4e92<\/h4>\n<p> async def demo_client_interaction():<br \/>\n    &#034;&#034;&#034;\u6f14\u793a\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u7684\u4ea4\u4e92&#034;&#034;&#034;<\/p>\n<p>    # 1. \u8fde\u63a5\u5230\u670d\u52a1\u5668<br \/>\n    client &#061; MCPClient()<br \/>\n    await client.connect_stdio(&#034;python&#034;, &#034;mcp_server.py&#034;)<\/p>\n<p>    # 2. \u521d\u59cb\u5316\u8fde\u63a5<br \/>\n    init_result &#061; await client.initialize()<br \/>\n    print(f&#034;\u5df2\u8fde\u63a5\u670d\u52a1\u5668: {init_result[&#039;serverInfo&#039;][&#039;name&#039;]}&#034;)<br \/>\n    print(f&#034;\u534f\u8bae\u7248\u672c: {init_result[&#039;protocolVersion&#039;]}&#034;)<br \/>\n    print(f&#034;\u80fd\u529b: {list(init_result[&#039;capabilities&#039;].keys())}&#034;)<br \/>\n    print()<\/p>\n<p>    # 3. \u5217\u51fa\u6240\u6709\u5de5\u5177<br \/>\n    tools &#061; await client.list_tools()<br \/>\n    print(f&#034;\u53ef\u7528\u5de5\u5177 ({len(tools)}):&#034;)<br \/>\n    for tool in tools:<br \/>\n        print(f&#034;  &#8211; {tool[&#039;name&#039;]}: {tool[&#039;description&#039;]}&#034;)<br \/>\n    print()<\/p>\n<p>    # 4. \u8c03\u7528\u5de5\u5177<br \/>\n    print(&#034;\u8c03\u7528 calculator \u5de5\u5177: 2 &#043; 3 * 4&#034;)<br \/>\n    result &#061; await client.call_tool(&#034;calculator&#034;, {&#034;expression&#034;: &#034;2 &#043; 3 * 4&#034;})<br \/>\n    print(f&#034;\u7ed3\u679c: {result[&#039;content&#039;][0][&#039;text&#039;]}&#034;)<br \/>\n    print()<\/p>\n<p>    print(&#034;\u8c03\u7528 get_current_time \u5de5\u5177&#034;)<br \/>\n    result &#061; await client.call_tool(&#034;get_current_time&#034;)<br \/>\n    print(f&#034;\u7ed3\u679c: {result[&#039;content&#039;][0][&#039;text&#039;]}&#034;)<br \/>\n    print()<\/p>\n<p>    # 5. \u5217\u51fa\u8d44\u6e90<br \/>\n    resources &#061; await client.list_resources()<br \/>\n    print(f&#034;\u53ef\u7528\u8d44\u6e90 ({len(resources)}):&#034;)<br \/>\n    for res in resources:<br \/>\n        print(f&#034;  &#8211; {res[&#039;name&#039;]} ({res[&#039;uri&#039;]})&#034;)<\/p>\n<p>    # 6. \u5173\u95ed\u8fde\u63a5<br \/>\n    await client.close()<\/p>\n<p># \u8fd0\u884c\u6f14\u793a<br \/>\n# asyncio.run(demo_client_interaction())<\/p>\n<hr \/>\n<h3>\u4e94\u3001\u4f7f\u7528\u5b98\u65b9SDK\u5feb\u901f\u6784\u5efa&#xff08;\u8fdb\u9636&#xff09;<\/h3>\n<p>\u7406\u89e3\u5e95\u5c42\u534f\u8bae\u540e&#xff0c;\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\u6211\u4eec\u901a\u5e38\u4f1a\u4f7f\u7528MCP SDK\u6765\u52a0\u901f\u5f00\u53d1\u3002MCP\u63d0\u4f9b\u4e86Python\u3001TypeScript\u3001Java\u3001Kotlin\u7b49\u591a\u8bed\u8a00SDK\u3002<\/p>\n<h4>5.1 \u5b89\u88c5Python SDK<\/h4>\n<p> pip install &#034;mcp[cli]&#034;<\/p>\n<h4>5.2 \u4f7f\u7528FastMCP\u6784\u5efa\u670d\u52a1\u5668&#xff08;\u7b80\u5316\u7248&#xff09;<\/h4>\n<p>MCP SDK\u4ece1.2.0\u7248\u672c\u5f00\u59cb\u63d0\u4f9b\u4e86 FastMCP \u7c7b&#xff0c;\u4f7f\u7528Python\u7c7b\u578b\u63d0\u793a\u548cdocstring\u81ea\u52a8\u751f\u6210\u5de5\u5177\u5b9a\u4e49&#xff1a;<\/p>\n<p> from mcp.server.fastmcp import FastMCP<br \/>\nimport httpx<br \/>\nimport json<\/p>\n<p># \u521b\u5efaMCP\u670d\u52a1\u5668\u5b9e\u4f8b<br \/>\nmcp &#061; FastMCP(&#034;data-analyzer&#034;)<\/p>\n<p>&#064;mcp.tool()<br \/>\nasync def fetch_json_data(url: str) -&gt; str:<br \/>\n    &#034;&#034;&#034;\u83b7\u53d6JSON\u683c\u5f0f\u7684\u8fdc\u7a0b\u6570\u636e<\/p>\n<p>    Args:<br \/>\n        url: \u6570\u636e\u6e90\u7684URL\u5730\u5740<br \/>\n    &#034;&#034;&#034;<br \/>\n    async with httpx.AsyncClient() as client:<br \/>\n        response &#061; await client.get(url, timeout&#061;30.0)<br \/>\n        response.raise_for_status()<br \/>\n        data &#061; response.json()<br \/>\n        return json.dumps(data, indent&#061;2, ensure_ascii&#061;False)<\/p>\n<p>&#064;mcp.tool()<br \/>\nasync def analyze_text(text: str, operation: str &#061; &#034;word_count&#034;) -&gt; str:<br \/>\n    &#034;&#034;&#034;\u5206\u6790\u6587\u672c\u7684\u57fa\u672c\u7edf\u8ba1\u4fe1\u606f<\/p>\n<p>    Args:<br \/>\n        text: \u5f85\u5206\u6790\u7684\u6587\u672c\u5185\u5bb9<br \/>\n        operation: \u5206\u6790\u64cd\u4f5c: word_count(\u8bcd\u6570), char_count(\u5b57\u7b26\u6570),<br \/>\n                   line_count(\u884c\u6570), all(\u5168\u90e8)<br \/>\n    &#034;&#034;&#034;<br \/>\n    operations &#061; {<br \/>\n        &#034;word_count&#034;: f&#034;\u8bcd\u6570: {len(text.split())}&#034;,<br \/>\n        &#034;char_count&#034;: f&#034;\u5b57\u7b26\u6570: {len(text)}&#034;,<br \/>\n        &#034;line_count&#034;: f&#034;\u884c\u6570: {len(text.splitlines())}&#034;,<br \/>\n        &#034;all&#034;: (<br \/>\n            f&#034;\u8bcd\u6570: {len(text.split())}\\\\n&#034;<br \/>\n            f&#034;\u5b57\u7b26\u6570: {len(text)}\\\\n&#034;<br \/>\n            f&#034;\u884c\u6570: {len(text.splitlines())}&#034;<br \/>\n        )<br \/>\n    }<br \/>\n    return operations.get(operation, f&#034;\u672a\u77e5\u64cd\u4f5c: {operation}&#034;)<\/p>\n<p>&#064;mcp.resource(&#034;config:\/\/app\/settings&#034;)<br \/>\ndef get_settings() -&gt; str:<br \/>\n    &#034;&#034;&#034;\u8fd4\u56de\u4e00\u4e2a\u6a21\u62df\u7684\u5e94\u7528\u914d\u7f6e&#xff08;\u8d44\u6e90\u793a\u4f8b&#xff09;&#034;&#034;&#034;<br \/>\n    return json.dumps({<br \/>\n        &#034;app_name&#034;: &#034;Data Analyzer&#034;,<br \/>\n        &#034;version&#034;: &#034;2.0.0&#034;,<br \/>\n        &#034;max_request_size&#034;: &#034;10MB&#034;,<br \/>\n        &#034;enable_logging&#034;: True<br \/>\n    }, indent&#061;2)<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    # \u4f7f\u7528Stdio\u4f20\u8f93\u8fd0\u884c<br \/>\n    mcp.run(transport&#061;&#034;stdio&#034;)<\/p>\n<p>\u8fd0\u884c\u65b9\u5f0f&#xff1a;<\/p>\n<p> python data_analyzer_server.py<\/p>\n<h4>5.3 \u4f7f\u7528\u5f02\u6b65\u5ba2\u6237\u7aefSDK<\/h4>\n<p> from mcp import ClientSession, StdioServerParameters<br \/>\nfrom mcp.client.stdio import stdio_client<br \/>\nimport asyncio<\/p>\n<p>async def main():<br \/>\n    # \u914d\u7f6e\u670d\u52a1\u5668\u53c2\u6570<br \/>\n    server_params &#061; StdioServerParameters(<br \/>\n        command&#061;&#034;python&#034;,<br \/>\n        args&#061;[&#034;data_analyzer_server.py&#034;]<br \/>\n    )<\/p>\n<p>    async with stdio_client(server_params) as (read, write):<br \/>\n        async with ClientSession(read, write) as session:<br \/>\n            # \u521d\u59cb\u5316<br \/>\n            await session.initialize()<\/p>\n<p>            # \u5217\u51fa\u5de5\u5177<br \/>\n            tools &#061; await session.list_tools()<br \/>\n            print(&#034;\u53ef\u7528\u5de5\u5177:&#034;)<br \/>\n            for tool in tools:<br \/>\n                print(f&#034;  {tool.name}: {tool.description}&#034;)<\/p>\n<p>            # \u8c03\u7528\u5de5\u5177<br \/>\n            result &#061; await session.call_tool(<br \/>\n                &#034;analyze_text&#034;,<br \/>\n                arguments&#061;{<br \/>\n                    &#034;text&#034;: &#034;Hello MCP! This is a test.&#034;,<br \/>\n                    &#034;operation&#034;: &#034;all&#034;<br \/>\n                }<br \/>\n            )<br \/>\n            print(f&#034;\\\\n\u5206\u6790\u7ed3\u679c:\\\\n{result.content[0].text}&#034;)<\/p>\n<p>            # \u8bfb\u53d6\u8d44\u6e90<br \/>\n            resource &#061; await session.read_resource(&#034;config:\/\/app\/settings&#034;)<br \/>\n            print(f&#034;\\\\n\u914d\u7f6e\u4fe1\u606f:\\\\n{resource.contents[0].text}&#034;)<\/p>\n<p>asyncio.run(main())<\/p>\n<hr \/>\n<h3>\u516d\u3001MCP\u4e0eDeepSeek\u7684\u6df1\u5ea6\u7ed3\u5408<\/h3>\n<p>\u5230\u76ee\u524d\u4e3a\u6b62&#xff0c;\u6211\u4eec\u6784\u5efa\u7684MCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u90fd\u662f\u901a\u7528\u7684\u3002\u63a5\u4e0b\u6765&#xff0c;\u8ba9\u6211\u4eec\u770b\u770b\u5982\u4f55\u5c06MCP\u4e0eDeepSeek\u5927\u6a21\u578b\u7ed3\u5408&#xff0c;\u771f\u6b63\u6253\u9020\u4e00\u4e2a\u53ef\u4ee5\u81ea\u4e3b\u8c03\u7528\u5de5\u5177\u7684AI Agent\u3002<\/p>\n<h4>6.1 \u67b6\u6784\u8bbe\u8ba1<\/h4>\n<p>\u5c06DeepSeek\u4e0eMCP\u7ed3\u5408&#xff0c;\u672c\u8d28\u4e0a\u662f\u6784\u5efa\u4e00\u4e2aReAct&#xff08;\u63a8\u7406&#043;\u884c\u52a8&#xff09;\u5faa\u73af\u3002DeepSeek\u5927\u6a21\u578b\u4f5c\u4e3a\u63a8\u7406\u6838\u5fc3&#xff0c;MCP\u4f5c\u4e3a\u884c\u52a8\u63a5\u53e3\u3002<\/p>\n<p> \u7528\u6237\u8f93\u5165 \u2192 DeepSeek\u5927\u6a21\u578b \u2192 MCP\u5ba2\u6237\u7aef \u2192 MCP\u670d\u52a1\u5668 \u2192 \u5916\u90e8\u5de5\u5177<br \/>\n                              \u2191                    \u2193<br \/>\n                          \u2514\u2500\u2500\u2500 \u5de5\u5177\u8c03\u7528\u7ed3\u679c \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/p>\n<p>\u6838\u5fc3\u6d41\u7a0b\u5206\u4e3a\u4e94\u4e2a\u6b65\u9aa4&#xff1a;<\/p>\n<p>\u7b2c\u4e00\u6b65&#xff1a;\u610f\u56fe\u7406\u89e3\u3002DeepSeek\u63a5\u6536\u7528\u6237\u7684\u81ea\u7136\u8bed\u8a00\u8f93\u5165&#xff0c;\u901a\u8fc7\u5176\u5f3a\u5927\u7684\u8bed\u4e49\u7406\u89e3\u80fd\u529b\u89e3\u6790\u51fa\u7528\u6237\u7684\u771f\u5b9e\u610f\u56fe\u3002\u4f8b\u5982\u7528\u6237\u8bf4&#034;\u5e2e\u6211\u770b\u770b\u4eca\u5929\u7684\u4ee3\u7801\u63d0\u4ea4\u8bb0\u5f55&#034;&#xff0c;DeepSeek\u80fd\u7406\u89e3\u8fd9\u9700\u8981\u8c03\u7528Git\u5de5\u5177\u3002<\/p>\n<p>\u7b2c\u4e8c\u6b65&#xff1a;\u5de5\u5177\u9009\u62e9\u3002\u7ed3\u5408MCP\u5ba2\u6237\u7aef\u63d0\u4f9b\u7684\u5de5\u5177\u5217\u8868&#xff08;\u901a\u8fc7tools\/list\u83b7\u53d6&#xff09;&#xff0c;DeepSeek\u5224\u65ad\u5e94\u8be5\u4f7f\u7528\u54ea\u4e2a\u6216\u54ea\u4e9b\u5de5\u5177\u6765\u5b8c\u6210\u4efb\u52a1\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u4e0e\u4eba\u7c7b\u9009\u62e9\u5de5\u5177\u7684\u903b\u8f91\u76f8\u4f3c\u2014\u2014&#034;\u6211\u9700\u8981\u67e5\u770bGit\u8bb0\u5f55&#xff0c;\u6240\u4ee5\u9009\u62e9&#039;git_log&#039;\u5de5\u5177&#034;\u3002<\/p>\n<p>\u7b2c\u4e09\u6b65&#xff1a;\u53c2\u6570\u751f\u6210\u3002DeepSeek\u6839\u636e\u7528\u6237\u9700\u6c42\u751f\u6210\u5de5\u5177\u6240\u9700\u7684\u53c2\u6570\u3002\u4f8b\u5982git_log\u5de5\u5177\u53ef\u80fd\u9700\u8981branch&#xff08;\u5206\u652f\u540d&#xff09;\u3001since&#xff08;\u8d77\u59cb\u65e5\u671f&#xff09;\u7b49\u53c2\u6570\u3002DeepSeek\u7684\u63a8\u7406\u80fd\u529b\u786e\u4fdd\u4e86\u53c2\u6570\u751f\u6210\u7684\u51c6\u786e\u6027\u3002<\/p>\n<p>\u7b2c\u56db\u6b65&#xff1a;\u5de5\u5177\u6267\u884c\u3002DeepSeek\u8f93\u51fa\u7ed3\u6784\u5316\u7684\u51fd\u6570\u8c03\u7528&#xff08;function call&#xff09;&#xff0c;MCP\u5ba2\u6237\u7aef\u5c06\u5176\u8f6c\u6362\u6210JSON-RPC\u6d88\u606f\u53d1\u9001\u7ed9MCP\u670d\u52a1\u5668\u6267\u884c\u3002\u8fd9\u4e00\u6b65\u5b8c\u5168\u662f\u534f\u8bae\u5c42\u9762\u7684\u901a\u4fe1&#xff0c;DeepSeek\u4e0d\u76f4\u63a5\u53c2\u4e0e\u3002<\/p>\n<p>\u7b2c\u4e94\u6b65&#xff1a;\u7ed3\u679c\u7efc\u5408\u3002MCP\u670d\u52a1\u5668\u8fd4\u56de\u5de5\u5177\u6267\u884c\u7ed3\u679c\u540e&#xff0c;DeepSeek\u5c06\u7ed3\u679c\u4e0e\u7528\u6237\u7684\u95ee\u9898\u4e0a\u4e0b\u6587\u7ed3\u5408&#xff0c;\u751f\u6210\u81ea\u7136\u8bed\u8a00\u7684\u56de\u590d\u3002\u4f8b\u5982\u62ff\u5230Git\u63d0\u4ea4\u8bb0\u5f55\u540e&#xff0c;\u5b83\u4f1a\u6574\u7406\u6210\u6613\u8bfb\u7684\u683c\u5f0f&#xff0c;\u751a\u81f3\u5206\u6790\u63d0\u4ea4\u9891\u7387\u548c\u8d21\u732e\u8005\u7edf\u8ba1\u3002<\/p>\n<p>\u5982\u679c\u4e00\u6b21\u5de5\u5177\u8c03\u7528\u4e0d\u591f&#xff0c;\u6574\u4e2a\u5faa\u73af\u4f1a\u91cd\u590d\u8fdb\u884c&#xff0c;\u76f4\u5230\u4efb\u52a1\u5b8c\u6210\u6216\u8fbe\u5230\u9884\u8bbe\u7684\u6700\u5927\u8f6e\u6b21\u3002\u8fd9\u5c31\u662fReAct\u5faa\u73af\u7684\u6838\u5fc3\u601d\u60f3\u2014\u2014\u63a8\u7406\u3001\u884c\u52a8\u3001\u89c2\u5bdf\u3001\u518d\u63a8\u7406\u3002<\/p>\n<h4>6.2 \u96c6\u6210\u4ee3\u7801\u793a\u4f8b<\/h4>\n<p> from openai import OpenAI<br \/>\nimport json<\/p>\n<p># \u914d\u7f6eDeepSeek API&#xff08;\u5047\u8bbe\u4f7f\u7528\u517c\u5bb9OpenAI\u63a5\u53e3\u7684DeepSeek API&#xff09;<br \/>\nclient &#061; OpenAI(<br \/>\n    base_url&#061;&#034;https:\/\/api.deepseek.com\/v1&#034;,<br \/>\n    api_key&#061;&#034;your-deepseek-api-key&#034;<br \/>\n)<\/p>\n<p>class DeepSeekMCPAgent:<br \/>\n    &#034;&#034;&#034;\u96c6\u6210DeepSeek\u4e0eMCP\u7684\u667a\u80fd\u4f53&#034;&#034;&#034;<\/p>\n<p>    def __init__(self, mcp_client: MCPClient, system_prompt: str &#061; None):<br \/>\n        self.mcp_client &#061; mcp_client<br \/>\n        self.system_prompt &#061; system_prompt or (<br \/>\n            &#034;\u4f60\u662f\u4e00\u4e2a\u667a\u80fd\u52a9\u624b&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u5404\u79cd\u5de5\u5177\u6765\u5e2e\u52a9\u7528\u6237\u5b8c\u6210\u4efb\u52a1\u3002&#034;<br \/>\n            &#034;\u5f53\u4f60\u9700\u8981\u8c03\u7528\u5de5\u5177\u65f6&#xff0c;\u8bf7\u4f7f\u7528\u51fd\u6570\u8c03\u7528\u683c\u5f0f\u3002&#034;<br \/>\n        )<br \/>\n        self.tools &#061; []<\/p>\n<p>    async def load_tools(self):<br \/>\n        &#034;&#034;&#034;\u4eceMCP\u670d\u52a1\u5668\u52a0\u8f7d\u5de5\u5177\u5b9a\u4e49&#034;&#034;&#034;<br \/>\n        mcp_tools &#061; await self.mcp_client.list_tools()<br \/>\n        self.tools &#061; [<br \/>\n            {<br \/>\n                &#034;type&#034;: &#034;function&#034;,<br \/>\n                &#034;function&#034;: {<br \/>\n                    &#034;name&#034;: t[&#034;name&#034;],<br \/>\n                    &#034;description&#034;: t[&#034;description&#034;],<br \/>\n                    &#034;parameters&#034;: t[&#034;inputSchema&#034;]<br \/>\n                }<br \/>\n            }<br \/>\n            for t in mcp_tools<br \/>\n        ]<\/p>\n<p>    async def chat(self, user_message: str, max_turns: int &#061; 5) -&gt; str:<br \/>\n        &#034;&#034;&#034;\u591a\u8f6e\u5bf9\u8bdd&#xff0c;\u652f\u6301\u5de5\u5177\u8c03\u7528&#034;&#034;&#034;<br \/>\n        messages &#061; [<br \/>\n            {&#034;role&#034;: &#034;system&#034;, &#034;content&#034;: self.system_prompt},<br \/>\n            {&#034;role&#034;: &#034;user&#034;, &#034;content&#034;: user_message}<br \/>\n        ]<\/p>\n<p>        for turn in range(max_turns):<br \/>\n            # \u8c03\u7528DeepSeek<br \/>\n            response &#061; client.chat.completions.create(<br \/>\n                model&#061;&#034;deepseek-chat&#034;,<br \/>\n                messages&#061;messages,<br \/>\n                tools&#061;self.tools if self.tools else None,<br \/>\n                tool_choice&#061;&#034;auto&#034; if self.tools else None<br \/>\n            )<\/p>\n<p>            msg &#061; response.choices[0].message<\/p>\n<p>            # \u5982\u679c\u6a21\u578b\u51b3\u5b9a\u76f4\u63a5\u56de\u590d&#xff0c;\u8fd4\u56de\u7ed3\u679c<br \/>\n            if not msg.tool_calls:<br \/>\n                return msg.content<\/p>\n<p>            # \u6dfb\u52a0\u6a21\u578b\u54cd\u5e94\u5230\u5bf9\u8bdd<br \/>\n            messages.append(msg)<\/p>\n<p>            # \u5904\u7406\u6bcf\u4e2a\u5de5\u5177\u8c03\u7528<br \/>\n            for tool_call in msg.tool_calls:<br \/>\n                function_name &#061; tool_call.function.name<br \/>\n                function_args &#061; json.loads(tool_call.function.arguments)<\/p>\n<p>                # \u901a\u8fc7MCP\u8c03\u7528\u5de5\u5177<br \/>\n                try:<br \/>\n                    result &#061; await self.mcp_client.call_tool(<br \/>\n                        function_name, function_args<br \/>\n                    )<br \/>\n                    tool_result &#061; result[&#034;content&#034;][0][&#034;text&#034;]<br \/>\n                except Exception as e:<br \/>\n                    tool_result &#061; f&#034;\u5de5\u5177\u8c03\u7528\u5931\u8d25: {str(e)}&#034;<\/p>\n<p>                # \u6dfb\u52a0\u5de5\u5177\u8c03\u7528\u7ed3\u679c\u5230\u5bf9\u8bdd<br \/>\n                messages.append({<br \/>\n                    &#034;role&#034;: &#034;tool&#034;,<br \/>\n                    &#034;tool_call_id&#034;: tool_call.id,<br \/>\n                    &#034;content&#034;: tool_result<br \/>\n                })<\/p>\n<p>        return &#034;\u5df2\u8fbe\u5230\u6700\u5927\u5bf9\u8bdd\u8f6e\u6b21&#034;<\/p>\n<h4>6.3 \u6548\u679c\u6f14\u793a<\/h4>\n<p>\u5f53\u7528\u6237\u95ee&#034;\u5e2e\u6211\u8ba1\u7b97\u4e00\u4e0b\u5f53\u524d\u65f6\u95f4\u52a0\u4e0a8\u5c0f\u65f6\u662f\u4ec0\u4e48\u65f6\u5019&#xff0c;\u7136\u540e\u5217\u51fa\u5f53\u524d\u76ee\u5f55\u6709\u54ea\u4e9b\u6587\u4ef6&#034;\u65f6&#xff0c;DeepSeek\u4f1a&#xff1a;<\/p>\n<li>\u8c03\u7528 get_current_time \u5de5\u5177\u83b7\u53d6\u5f53\u524d\u65f6\u95f4<\/li>\n<li>\u6839\u636e\u65f6\u95f4\u7ed3\u679c\u8ba1\u7b97\u52a08\u5c0f\u65f6<\/li>\n<li>\u8c03\u7528 list_directory \u5de5\u5177\u5217\u51fa\u6587\u4ef6<\/li>\n<li>\u7efc\u5408\u6240\u6709\u7ed3\u679c\u56de\u590d\u7528\u6237<\/li>\n<p>\u8fd9\u79cd\u81ea\u4e3b\u8c03\u7528\u5de5\u5177\u7684\u80fd\u529b&#xff0c;\u6b63\u662fMCP\u8d4b\u4e88AI Agent\u7684\u6838\u5fc3\u4ef7\u503c\u3002<\/p>\n<hr \/>\n<h3>\u4e03\u3001MCP\u7684\u9ad8\u7ea7\u7279\u6027<\/h3>\n<h4>7.1 \u80fd\u529b\u534f\u5546<\/h4>\n<p>MCP\u7684\u521d\u59cb\u5316\u9636\u6bb5\u5305\u542b\u80fd\u529b\u534f\u5546\u3002\u670d\u52a1\u5668\u58f0\u660e\u81ea\u5df1\u652f\u6301\u54ea\u4e9b\u529f\u80fd&#xff08;\u5de5\u5177\u3001\u8d44\u6e90\u3001\u63d0\u793a\u6a21\u677f&#xff09;&#xff0c;\u5ba2\u6237\u7aef\u4e5f\u53ef\u4ee5\u58f0\u660e\u81ea\u5df1\u7684\u652f\u6301&#xff08;\u5982\u91c7\u6837\u80fd\u529b&#xff09;&#xff1a;<\/p>\n<p> # \u5ba2\u6237\u7aef\u58f0\u660e\u652f\u6301\u91c7\u6837<br \/>\nserver_result &#061; await client.send_request(&#034;initialize&#034;, {<br \/>\n    &#034;protocolVersion&#034;: &#034;2024-11-05&#034;,<br \/>\n    &#034;capabilities&#034;: {<br \/>\n        &#034;sampling&#034;: {}  # \u652f\u6301\u91c7\u6837\u8bf7\u6c42<br \/>\n    },<br \/>\n    &#034;clientInfo&#034;: {&#034;name&#034;: &#034;advanced-client&#034;, &#034;version&#034;: &#034;1.0.0&#034;}<br \/>\n})<\/p>\n<h4>7.2 \u5b9e\u65f6\u901a\u77e5<\/h4>\n<p>\u5f53\u5de5\u5177\u6216\u8d44\u6e90\u53d1\u751f\u53d8\u5316\u65f6&#xff0c;\u670d\u52a1\u5668\u53ef\u4ee5\u4e3b\u52a8\u53d1\u9001\u901a\u77e5&#xff1a;<\/p>\n<p> # \u670d\u52a1\u5668\u7aef&#xff1a;\u901a\u77e5\u5de5\u5177\u5217\u8868\u5df2\u53d8\u66f4<br \/>\ntransport.write_message(<br \/>\n    JSONRPCMessage.create_notification(<br \/>\n        &#034;notifications\/tools\/list_changed&#034;<br \/>\n    )<br \/>\n)<\/p>\n<h4>7.3 \u8fdb\u5ea6\u8ffd\u8e2a<\/h4>\n<p>\u5bf9\u4e8e\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u64cd\u4f5c&#xff0c;MCP\u652f\u6301\u8fdb\u5ea6\u8ffd\u8e2a&#xff1a;<\/p>\n<p> {<br \/>\n  &#034;jsonrpc&#034;: &#034;2.0&#034;,<br \/>\n  &#034;method&#034;: &#034;notifications\/progress&#034;,<br \/>\n  &#034;params&#034;: {<br \/>\n    &#034;progressToken&#034;: &#034;token-001&#034;,<br \/>\n    &#034;progress&#034;: 50,<br \/>\n    &#034;total&#034;: 100<br \/>\n  }<br \/>\n}<\/p>\n<h4>7.4 \u4efb\u52a1&#xff08;Experimental&#xff09;<\/h4>\n<p>MCP\u7684\u5b9e\u9a8c\u6027\u529f\u80fd\u2014\u2014\u4efb\u52a1&#xff0c;\u63d0\u4f9b\u6301\u4e45\u5316\u7684\u6267\u884c\u5305\u88c5\u5668&#xff0c;\u652f\u6301\u5f02\u6b65\u7ed3\u679c\u68c0\u7d22\u548c\u72b6\u6001\u8ddf\u8e2a&#xff1a;<\/p>\n<p> {<br \/>\n  &#034;jsonrpc&#034;: &#034;2.0&#034;,<br \/>\n  &#034;method&#034;: &#034;tasks\/schedule&#034;,<br \/>\n  &#034;params&#034;: {<br \/>\n    &#034;name&#034;: &#034;batch-process&#034;,<br \/>\n    &#034;uri&#034;: &#034;tasks:\/\/batch\/process-001&#034;<br \/>\n  }<br \/>\n}<\/p>\n<hr \/>\n<h3>\u516b\u3001\u6700\u4f73\u5b9e\u8df5\u4e0e\u751f\u4ea7\u5316\u5efa\u8bae<\/h3>\n<h4>8.1 \u5b89\u5168\u6027<\/h4>\n<ul>\n<li>Stdio\u670d\u52a1\u5668&#xff1a;\u7edd\u4e0d\u5411stdout\u8f93\u51fa\u65e5\u5fd7&#xff08;\u4f1a\u7834\u574fJSON-RPC\u534f\u8bae&#xff09;&#xff0c;\u59cb\u7ec8\u4f7f\u7528stderr\u6216\u6587\u4ef6\u65e5\u5fd7<\/li>\n<li>HTTP\u670d\u52a1\u5668&#xff1a;\u4f7f\u7528OAuth 2.0\u8fdb\u884c\u8ba4\u8bc1\u6388\u6743<\/li>\n<li>\u8f93\u5165\u9a8c\u8bc1&#xff1a;\u4e25\u683c\u6821\u9a8c\u5de5\u5177\u53c2\u6570&#xff0c;\u907f\u514d\u547d\u4ee4\u6ce8\u5165<\/li>\n<li>\u6700\u5c0f\u6743\u9650&#xff1a;MCP\u670d\u52a1\u5668\u53ea\u5f00\u653e\u5fc5\u8981\u7684\u5de5\u5177\u548c\u8d44\u6e90<\/li>\n<\/ul>\n<h4>8.2 \u65e5\u5fd7\u89c4\u8303<\/h4>\n<p> # \u2705 \u6b63\u786e\u7684\u65e5\u5fd7\u65b9\u5f0f&#xff08;Stdio\u4f20\u8f93&#xff09;<br \/>\nimport sys<br \/>\nimport logging<br \/>\nlogging.basicConfig(level&#061;logging.INFO, stream&#061;sys.stderr)<\/p>\n<p># \u2705 \u6216\u8005\u4f7f\u7528print\u91cd\u5b9a\u5411\u5230stderr<br \/>\nprint(&#034;Server started&#034;, file&#061;sys.stderr)<\/p>\n<p># \u274c \u9519\u8bef\u65b9\u5f0f \u2014\u2014 \u4f1a\u7834\u574f\u534f\u8bae<br \/>\nprint(&#034;Server started&#034;)  # \u8f93\u51fa\u5230stdout<\/p>\n<h4>8.3 \u9519\u8bef\u5904\u7406<\/h4>\n<ul>\n<li>\u59cb\u7ec8\u6355\u83b7\u5de5\u5177\u6267\u884c\u5f02\u5e38\u5e76\u8fd4\u56de\u53cb\u597d\u9519\u8bef\u4fe1\u606f<\/li>\n<li>\u4f7f\u7528\u6807\u51c6JSON-RPC\u9519\u8bef\u7801<\/li>\n<li>\u5b9e\u73b0\u8d85\u65f6\u673a\u5236&#xff0c;\u9632\u6b62\u5de5\u5177\u8c03\u7528\u6302\u8d77<\/li>\n<li>\u5728MCP\u5ba2\u6237\u7aef\u5b9e\u73b0\u91cd\u8bd5\u903b\u8f91&#xff0c;\u5904\u7406\u77ac\u6001\u7f51\u7edc\u6545\u969c<\/li>\n<\/ul>\n<h4>8.4 \u4e0eFunction Calling\u7684\u5bf9\u6bd4<\/h4>\n<p>MCP\u4e0eOpenAI\u63d0\u51fa\u7684Function Calling\u6a21\u5f0f\u65e2\u6709\u76f8\u4f3c\u4e4b\u5904&#xff0c;\u53c8\u6709\u672c\u8d28\u533a\u522b&#xff1a;<\/p>\n<table>\n<tr>\u7ef4\u5ea6MCPFunction Calling<\/tr>\n<tbody>\n<tr>\n<td>\u6807\u51c6\u5316\u7a0b\u5ea6<\/td>\n<td>\u5f00\u653e\u534f\u8bae&#xff0c;\u8de8\u5e73\u53f0<\/td>\n<td>OpenAI\u4e13\u6709\u683c\u5f0f<\/td>\n<\/tr>\n<tr>\n<td>\u5de5\u5177\u53d1\u73b0<\/td>\n<td>tools\/list\u52a8\u6001\u53d1\u73b0<\/td>\n<td>\u9700\u9884\u914d\u7f6e\u5de5\u5177\u5b9a\u4e49<\/td>\n<\/tr>\n<tr>\n<td>\u4f20\u8f93\u5c42<\/td>\n<td>Stdio\/HTTP\u53cc\u6a21\u5f0f<\/td>\n<td>\u4ec5HTTP<\/td>\n<\/tr>\n<tr>\n<td>\u8d44\u6e90\u8bbf\u95ee<\/td>\n<td>\u539f\u751f\u652f\u6301Resources\u539f\u8bed<\/td>\n<td>\u65e0\u6807\u51c6\u8d44\u6e90\u673a\u5236<\/td>\n<\/tr>\n<tr>\n<td>\u751f\u6001\u517c\u5bb9<\/td>\n<td>Claude\u3001ChatGPT\u3001VS Code\u7b49<\/td>\n<td>\u4ec5OpenAI\u517c\u5bb9API<\/td>\n<\/tr>\n<tr>\n<td>\u5b89\u5168\u63a7\u5236<\/td>\n<td>\u5185\u7f6e\u80fd\u529b\u534f\u5546\u3001OAuth<\/td>\n<td>\u4f9d\u8d56\u5e94\u7528\u5c42\u5b9e\u73b0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u7b80\u5355\u6765\u8bf4&#xff0c;Function Calling\u662fOpenAI API\u7684\u4e00\u4e2a\u7279\u6027&#xff0c;\u800cMCP\u662f\u4e00\u4e2a\u72ec\u7acb\u7684\u5f00\u653e\u534f\u8bae\u3002MCP\u7684\u8bbe\u8ba1\u76ee\u6807\u66f4\u5b8f\u5927\u2014\u2014\u5b83\u8981\u6210\u4e3aAI\u5e94\u7528\u8fde\u63a5\u5916\u90e8\u4e16\u754c\u7684\u4e8b\u5b9e\u6807\u51c6\u3002\u4ece\u751f\u6001\u517c\u5bb9\u6027\u6765\u770b&#xff0c;\u652f\u6301MCP\u7684\u5ba2\u6237\u7aef\u8d8a\u6765\u8d8a\u591a&#xff0c;\u800cFunction Calling\u4ecd\u7136\u5c40\u9650\u4e8eOpenAI\u751f\u6001\u3002<\/p>\n<h4>8.5 \u4e0eLangChain\u5de5\u5177\u7684\u5bf9\u6bd4<\/h4>\n<p>LangChain\u662f\u53e6\u4e00\u4e2a\u5e7f\u6cdb\u4f7f\u7528\u7684AI\u5e94\u7528\u6846\u67b6&#xff0c;\u5b83\u4e5f\u63d0\u4f9b\u4e86\u5de5\u5177\u8c03\u7528\u673a\u5236\u3002\u4e0eMCP\u76f8\u6bd4&#xff1a;<\/p>\n<ul>\n<li>LangChain\u7684\u5de5\u5177&#xff1a;\u6846\u67b6\u5185\u5d4c\u7684\u62bd\u8c61&#xff0c;\u9700\u8981\u901a\u8fc7LangChain\u7684\u7ec4\u4ef6\u94fe\u6765\u8c03\u7528&#xff0c;\u8026\u5408\u5ea6\u8f83\u9ad8<\/li>\n<li>MCP\u7684\u5de5\u5177&#xff1a;\u534f\u8bae\u5c42\u7684\u6807\u51c6\u5316\u63a5\u53e3&#xff0c;\u65e0\u5173\u6846\u67b6&#xff0c;\u4efb\u4f55\u652f\u6301MCP\u7684\u5ba2\u6237\u7aef\u90fd\u53ef\u4ee5\u8c03\u7528<\/li>\n<\/ul>\n<p>LangChain\u66f4\u50cf\u662f\u4e00\u4e2a\u5168\u6808\u5f00\u53d1\u6846\u67b6&#xff0c;\u800cMCP\u4e13\u6ce8\u4e8e\u5b9a\u4e49AI\u4e0e\u5de5\u5177\u4e4b\u95f4\u7684\u901a\u4fe1\u534f\u8bae\u3002\u5b9e\u9645\u9879\u76ee\u4e2d&#xff0c;\u4e24\u8005\u4e5f\u53ef\u4ee5\u7ed3\u5408\u4f7f\u7528\u2014\u2014LangChain\u4f5c\u4e3a\u534f\u8c03\u5c42&#xff0c;MCP\u4f5c\u4e3a\u5de5\u5177\u5c42\u7684\u6807\u51c6\u5316\u63a5\u53e3\u3002<\/p>\n<h4>8.6 \u6d4b\u8bd5\u4e0e\u8c03\u8bd5<\/h4>\n<p>MCP\u5b98\u65b9\u63d0\u4f9b\u4e86Inspector\u5de5\u5177\u7528\u4e8e\u8c03\u8bd5MCP\u670d\u52a1\u5668&#xff1a;<\/p>\n<p> # \u4f7f\u7528MCP Inspector\u8c03\u8bd5\u670d\u52a1\u5668<br \/>\nnpx &#064;modelcontextprotocol\/inspector python my_server.py<\/p>\n<p>Inspector\u63d0\u4f9b\u4e86\u4e00\u4e2aWeb\u754c\u9762&#xff0c;\u53ef\u4ee5\u67e5\u770b&#xff1a; &#8211; \u5de5\u5177\u5217\u8868\u548c\u53c2\u6570\u5b9a\u4e49 &#8211; \u53d1\u9001\u6d4b\u8bd5\u5de5\u5177\u8c03\u7528\u8bf7\u6c42 &#8211; \u67e5\u770bJSON-RPC\u6d88\u606f\u65e5\u5fd7 &#8211; \u76d1\u63a7\u670d\u52a1\u5668\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5<\/p>\n<p>\u5bf9\u4e8e\u5f00\u53d1\u8005\u6765\u8bf4&#xff0c;\u8fd9\u662f\u4e00\u4e2a\u975e\u5e38\u5b9e\u7528\u7684\u8c03\u8bd5\u5de5\u5177&#xff0c;\u53ef\u4ee5\u5feb\u901f\u9a8c\u8bc1MCP\u670d\u52a1\u5668\u7684\u884c\u4e3a\u662f\u5426\u7b26\u5408\u9884\u671f\u3002<\/p>\n<h4>8.4 \u90e8\u7f72\u7b56\u7565<\/h4>\n<ul>\n<li>\u672c\u5730MCP\u670d\u52a1\u5668&#xff1a;\u9002\u7528\u4e8e\u6587\u4ef6\u7cfb\u7edf\u3001\u672c\u5730\u6570\u636e\u5e93\u7b49\u654f\u611f\u64cd\u4f5c<\/li>\n<li>\u8fdc\u7a0bMCP\u670d\u52a1\u5668&#xff1a;\u9002\u7528\u4e8e\u4e91API\u3001SaaS\u670d\u52a1\u96c6\u6210<\/li>\n<li>\u5efa\u8bae&#xff1a;\u5bf9\u6bcf\u4e2a\u6570\u636e\u6e90\/\u5de5\u5177\u4f7f\u7528\u72ec\u7acb\u7684MCP\u670d\u52a1\u5668&#xff0c;\u4fbf\u4e8e\u9694\u79bb\u548c\u6269\u5c55<\/li>\n<\/ul>\n<hr \/>\n<h3>\u4e5d\u3001MCP\u751f\u6001\u5168\u666f\u4e0e\u672a\u6765\u5c55\u671b<\/h3>\n<h4>9.1 \u5f53\u524d\u751f\u6001\u683c\u5c40<\/h4>\n<p>\u622a\u81f32026\u5e74\u4e2d&#xff0c;MCP\u751f\u6001\u5df2\u7ecf\u521d\u5177\u89c4\u6a21&#xff1a;<\/p>\n<p>\u4e3b\u6d41AI\u5ba2\u6237\u7aef\u5168\u9762\u652f\u6301&#xff1a; &#8211; Claude Desktop\u4e0eClaude Code&#xff1a;Anthropic\u81ea\u5bb6\u4ea7\u54c1&#xff0c;\u5bf9MCP\u7684\u652f\u6301\u6700\u539f\u751f\u548c\u5b8c\u5584 &#8211; ChatGPT&#xff1a;2025\u5e74\u665a\u4e9b\u65f6\u5019\u5f00\u59cb\u652f\u6301MCP\u534f\u8bae\u8fde\u63a5 &#8211; Visual Studio Code&#xff1a;\u901a\u8fc7\u5185\u7f6e\u7684MCP\u652f\u6301&#xff0c;\u53ef\u4ee5\u8ba9Copilot\u76f4\u63a5\u8c03\u7528\u5916\u90e8\u5de5\u5177 &#8211; Cursor&#xff1a;\u4f5c\u4e3aAI\u539f\u751fIDE&#xff0c;\u5bf9MCP\u6709\u7740\u6df1\u5ea6\u7684\u96c6\u6210 &#8211; JetBrains IDE&#xff1a;2026\u5e74\u521d\u5f00\u59cb\u652f\u6301MCP<\/p>\n<p>\u5b98\u65b9MCP\u670d\u52a1\u5668\u53c2\u8003\u5b9e\u73b0&#xff1a; Anthropic\u5b98\u65b9\u7ef4\u62a4\u4e86\u591a\u4e2a\u53c2\u8003MCP\u670d\u52a1\u5668\u5b9e\u73b0&#xff0c;\u6db5\u76d6\u5e38\u89c1\u573a\u666f&#xff1a; &#8211; server-filesystem&#xff1a;\u5b89\u5168\u7684\u6587\u4ef6\u7cfb\u7edf\u64cd\u4f5c&#xff08;\u8bfb\u3001\u5199\u3001\u904d\u5386&#xff09; &#8211; server-github&#xff1a;GitHub API\u96c6\u6210&#xff08;Issue\u3001PR\u3001\u4ee3\u7801\u641c\u7d22&#xff09; &#8211; server-postgres&#xff1a;PostgreSQL\u6570\u636e\u5e93\u67e5\u8be2 &#8211; server-sqlite&#xff1a;SQLite\u6570\u636e\u5e93\u4ea4\u4e92 &#8211; server-puppeteer&#xff1a;\u6d4f\u89c8\u5668\u81ea\u52a8\u5316 &#8211; server-sentry&#xff1a;\u9519\u8bef\u76d1\u63a7\u548c\u544a\u8b66\u67e5\u8be2 &#8211; server-slack&#xff1a;Slack\u6d88\u606f\u548c\u5de5\u4f5c\u7a7a\u95f4\u7ba1\u7406<\/p>\n<p>\u8fd9\u4e9b\u53c2\u8003\u5b9e\u73b0\u4ee5MIT\u534f\u8bae\u5f00\u6e90&#xff0c;\u662f\u5b66\u4e60MCP\u670d\u52a1\u5668\u5f00\u53d1\u7684\u6700\u4f73\u5b9e\u8df5\u53c2\u8003\u3002<\/p>\n<h4>9.2 \u5178\u578b\u5e94\u7528\u573a\u666f<\/h4>\n<p>\u573a\u666f\u4e00&#xff1a;\u667a\u80fd\u4ee3\u7801\u5ba1\u67e5<\/p>\n<p>\u5c06MCP\u670d\u52a1\u5668\u8fde\u63a5\u5230\u4ee3\u7801\u4ed3\u5e93&#xff08;GitHub\/GitLab&#xff09;&#xff0c;AI\u5c31\u53ef\u4ee5\u76f4\u63a5\u8bfb\u53d6PR\u5dee\u5f02\u3001\u68c0\u67e5\u4ee3\u7801\u89c4\u8303\u3001\u81ea\u52a8\u751f\u6210\u5ba1\u67e5\u610f\u89c1\u3002\u5f00\u53d1\u8005\u53ea\u9700\u8bf4&#034;\u5e2e\u6211\u5ba1\u67e5\u8fd9\u4e2aPR&#034;&#xff0c;AI\u81ea\u52a8\u5b8c\u6210\u5168\u90e8\u5de5\u4f5c\u3002<\/p>\n<p>\u573a\u666f\u4e8c&#xff1a;\u6570\u636e\u5206\u6790\u52a9\u624b<\/p>\n<p>\u8fde\u63a5\u6570\u636e\u5e93MCP\u670d\u52a1\u5668&#xff0c;AI\u53ef\u4ee5\u6267\u884cSQL\u67e5\u8be2\u3001\u751f\u6210\u53ef\u89c6\u5316\u56fe\u8868\u3001\u5206\u6790\u6570\u636e\u8d8b\u52bf\u3002\u4e0d\u518d\u9700\u8981\u624b\u52a8\u7f16\u5199\u590d\u6742\u7684SQL\u8bed\u53e5&#xff0c;\u7528\u81ea\u7136\u8bed\u8a00\u5c31\u80fd\u5b8c\u6210\u6570\u636e\u63a2\u7d22\u3002<\/p>\n<p>\u573a\u666f\u4e09&#xff1a;\u81ea\u52a8\u5316\u8fd0\u7ef4<\/p>\n<p>\u8fde\u63a5\u670d\u52a1\u5668\u76d1\u63a7\u548c\u544a\u8b66MCP\u670d\u52a1\u5668&#xff0c;AI\u53ef\u4ee5\u5b9e\u65f6\u76d1\u542c\u7cfb\u7edf\u72b6\u6001\u3001\u5206\u6790\u65e5\u5fd7\u6587\u4ef6\u3001\u81ea\u52a8\u6267\u884c\u6545\u969c\u6062\u590d\u811a\u672c\u3002\u8fd9\u662f\u4e00\u79cd\u4ece&#034;\u88ab\u52a8\u544a\u8b66&#034;\u5230&#034;\u4e3b\u52a8\u8fd0\u7ef4&#034;\u7684\u8303\u5f0f\u8f6c\u53d8\u3002<\/p>\n<p>\u573a\u666f\u56db&#xff1a;\u4e2a\u4eba\u77e5\u8bc6\u7ba1\u7406<\/p>\n<p>\u8fde\u63a5\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\u548c\u7b14\u8bb0\u5e94\u7528\u7684MCP\u670d\u52a1\u5668&#xff0c;AI\u53ef\u4ee5\u50cf\u4e2a\u4eba\u79d8\u4e66\u4e00\u6837\u7ba1\u7406\u6587\u6863\u3001\u6574\u7406\u7b14\u8bb0\u3001\u68c0\u7d22\u4fe1\u606f\u3002<\/p>\n<h4>9.3 \u672a\u6765\u8d8b\u52bf<\/h4>\n<p>MCP\u7684\u53d1\u5c55\u6b63\u9075\u5faa\u7740\u4e0eHTTP\u3001USB\u7b49\u6807\u51c6\u5316\u534f\u8bae\u76f8\u4f3c\u7684\u8f68\u8ff9&#xff1a;\u4ece\u521d\u671f\u7684\u788e\u7247\u5316\u96c6\u6210&#xff0c;\u8d70\u5411\u7edf\u4e00\u7684\u6807\u51c6\u5316\u534f\u8bae&#xff0c;\u6700\u7ec8\u6210\u4e3aAI Agent\u65f6\u4ee3\u7684\u57fa\u7840\u8bbe\u65bd\u3002<\/p>\n<p>\u51e0\u4e2a\u503c\u5f97\u5173\u6ce8\u7684\u65b9\u5411&#xff1a;<\/p>\n<li>MCP Registry&#xff1a;\u7c7b\u4f3cDocker Hub\u7684MCP\u670d\u52a1\u5668\u6ce8\u518c\u4e2d\u5fc3&#xff0c;\u5f00\u53d1\u8005\u53ef\u4ee5\u53d1\u73b0\u3001\u5b89\u88c5\u548c\u5206\u4eabMCP\u670d\u52a1\u5668<\/li>\n<li>MCP Gateway&#xff1a;\u4f01\u4e1a\u7ea7\u7684MCP\u7f51\u5173&#xff0c;\u7edf\u4e00\u7ba1\u7406\u591a\u4e2aMCP\u670d\u52a1\u5668\u7684\u8bbf\u95ee\u63a7\u5236\u3001\u9650\u6d41\u548c\u76d1\u63a7<\/li>\n<li>\u591a\u6a21\u6001MCP&#xff1a;\u6269\u5c55MCP\u534f\u8bae\u4ee5\u652f\u6301\u56fe\u50cf\u3001\u97f3\u9891\u7b49\u975e\u6587\u672c\u6570\u636e\u7684\u4f20\u8f93<\/li>\n<li>\u6807\u51c6\u5316\u5b89\u5168\u8ba4\u8bc1&#xff1a;OAuth 2.0 &#043; MCP\u7684\u6df1\u5ea6\u96c6\u6210&#xff0c;\u5f62\u6210\u4f01\u4e1a\u7ea7\u5b89\u5168\u6807\u51c6<\/li>\n<h3>\u7ed3\u8bed<\/h3>\n<p>\u672c\u6587\u4ece\u96f6\u5f00\u59cb&#xff0c;\u5b8c\u6574\u5730\u5b9e\u73b0\u4e86\u4e00\u4e2aMCP&#xff08;Model Context Protocol&#xff09;\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u3002\u4eceJSON-RPC\u534f\u8bae\u5e95\u5c42&#xff0c;\u5230Stdio\u4f20\u8f93\u5c42&#xff0c;\u518d\u5230\u5de5\u5177\u6ce8\u518c\u548c\u8c03\u7528&#xff0c;\u6211\u4eec\u6ca1\u6709\u4f9d\u8d56\u4efb\u4f55SDK&#xff0c;\u5b8c\u5168\u7406\u89e3\u4e86MCP\u7684\u6838\u5fc3\u539f\u7406\u3002<\/p>\n<p>\u901a\u8fc7\u672c\u6587&#xff0c;\u4f60\u5e94\u8be5\u638c\u63e1\u4e86&#xff1a;<\/p>\n<li>MCP\u7684\u57fa\u7840\u67b6\u6784 \u2014 \u4e3b\u673a\u3001\u5ba2\u6237\u7aef\u3001\u670d\u52a1\u5668\u4e09\u5c42\u67b6\u6784<\/li>\n<li>JSON-RPC 2.0\u534f\u8bae \u2014 MCP\u7684\u5e95\u5c42\u901a\u4fe1\u534f\u8bae<\/li>\n<li>\u4ece\u96f6\u6784\u5efaMCP\u670d\u52a1\u5668 \u2014 \u7eafPython\u5b9e\u73b0&#xff0c;\u7406\u89e3\u534f\u8bae\u672c\u8d28<\/li>\n<li>\u4ece\u96f6\u6784\u5efaMCP\u5ba2\u6237\u7aef \u2014 \u8fde\u63a5\u3001\u521d\u59cb\u5316\u3001\u5de5\u5177\u8c03\u7528\u5168\u6d41\u7a0b<\/li>\n<li>\u5b98\u65b9SDK\u5feb\u901f\u5f00\u53d1 \u2014 FastMCP\u7684\u7b80\u5316\u7528\u6cd5<\/li>\n<li>\u4e0eDeepSeek\u96c6\u6210 \u2014 \u6253\u9020\u771f\u6b63\u7684AI Agent<\/li>\n<p>MCP\u6b63\u5728\u6210\u4e3aAI Agent\u65f6\u4ee3\u7684\u57fa\u7840\u8bbe\u65bd\u3002\u5c31\u50cfHTTP\u534f\u8bae\u7edf\u4e00\u4e86Web\u901a\u4fe1\u3001USB-C\u7edf\u4e00\u4e86\u8bbe\u5907\u8fde\u63a5\u4e00\u6837&#xff0c;MCP\u6b63\u5728\u7edf\u4e00AI\u5e94\u7528\u4e0e\u5916\u90e8\u4e16\u754c\u7684\u4ea4\u4e92\u6807\u51c6\u3002\u968f\u7740Claude\u3001ChatGPT\u3001VS Code\u7b49\u4e3b\u6d41\u5e73\u53f0\u5168\u9762\u652f\u6301MCP&#xff0c;\u4ee5\u53ca\u793e\u533a\u8d21\u732e\u7684\u6570\u5343\u4e2aMCP\u670d\u52a1\u5668\u751f\u6001\u7684\u6210\u719f&#xff0c;AI\u4ece&#034;\u95ee\u7b54\u5de5\u5177&#034;\u5230&#034;\u6570\u5b57\u52a9\u624b&#034;\u7684\u8fdb\u5316\u6b63\u5728\u52a0\u901f\u3002<\/p>\n<p>\u672a\u6765\u5df2\u6765&#xff0c;\u53ea\u662f\u5206\u5e03\u4e0d\u5747\u3002\u638c\u63e1MCP&#xff0c;\u5c31\u662f\u638c\u63e1AI Agent\u65f6\u4ee3\u7684&#034;\u63a5\u53e3&#034;\u80fd\u529b\u3002<\/p>\n<hr \/>\n<p>\u5b9e\u6218\u6307\u5357&#xff1a;\u672c\u6587\u914d\u5957\u5b8c\u6574\u4ee3\u7801\u793a\u4f8b\u3002\u66f4\u591aDeepSeek\u5927\u6a21\u578b\u4e0eAI Agent\u5b9e\u6218\u6559\u7a0b\u53c2\u89c1&#xff1a;DeepSeek \u5b9e\u6218\u6307\u5357\u7cfb\u5217<\/p>\n<p>\u00a0<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f15\u8a00<br \/>\n2025-2026\u5e74\u662fAI Agent\u4ece\u6982\u5ff5\u8d70\u5411\u843d\u5730\u7684\u7206\u53d1\u671f\u3002\u4eceClaude Code\u3001Cursor\u5230Visual Studio Code Copilot&#xff0c;\u51e0\u4e4e\u4e3b\u6d41AI\u5e94\u7528\u90fd\u5728\u5411\\&#8221;\u667a\u80fd\u4f53\\&#8221;\u5f62\u6001\u6f14\u8fdb\u2014\u2014\u5b83\u4eec\u4e0d\u518d\u53ea\u662f\u95ee\u7b54\u673a\u5668\u4eba&#xff0c;\u800c\u662f\u80fd\u591f\u81ea\u4e3b\u8c03\u7528\u5de5\u5177\u3001\u8bfb\u53d6\u6587\u4ef6\u3001\u64cd\u4f5c\u6570\u636e\u5e93\u7684\u771f\u5b9e\u751f\u4ea7\u529b\u5de5\u5177\u3002<br \/>\n\u7136\u800c&#xff0c;\u8fd9\u4e9b\u80fd\u529b\u80cc\u540e\u6709\u4e00\u4e2a\u5173\u952e\u7684\u6807\u51c6\u5316\u534f\u8bae\u6b63\u5728\u6084\u7136\u98a0\u8986\u6574\u4e2a\u751f\u6001&#xff1a;MCP&#xff08;Model Context Protocol<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[190,1813],"topic":[],"class_list":["post-97028","post","type-post","status-publish","format-standard","hentry","category-server","tag-190","tag-1813"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>MCP\u534f\u8bae\u4ece\u96f6\u5b9e\u73b0\uff1a\u624b\u5199\u4e00\u4e2a\u5b8c\u6574\u7684 Model Context Protocol \u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/97028.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MCP\u534f\u8bae\u4ece\u96f6\u5b9e\u73b0\uff1a\u624b\u5199\u4e00\u4e2a\u5b8c\u6574\u7684 Model Context Protocol \u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u5f15\u8a00 2025-2026\u5e74\u662fAI Agent\u4ece\u6982\u5ff5\u8d70\u5411\u843d\u5730\u7684\u7206\u53d1\u671f\u3002\u4eceClaude Code\u3001Cursor\u5230Visual Studio Code Copilot&#xff0c;\u51e0\u4e4e\u4e3b\u6d41AI\u5e94\u7528\u90fd\u5728\u5411&quot;\u667a\u80fd\u4f53&quot;\u5f62\u6001\u6f14\u8fdb\u2014\u2014\u5b83\u4eec\u4e0d\u518d\u53ea\u662f\u95ee\u7b54\u673a\u5668\u4eba&#xff0c;\u800c\u662f\u80fd\u591f\u81ea\u4e3b\u8c03\u7528\u5de5\u5177\u3001\u8bfb\u53d6\u6587\u4ef6\u3001\u64cd\u4f5c\u6570\u636e\u5e93\u7684\u771f\u5b9e\u751f\u4ea7\u529b\u5de5\u5177\u3002 \u7136\u800c&#xff0c;\u8fd9\u4e9b\u80fd\u529b\u80cc\u540e\u6709\u4e00\u4e2a\u5173\u952e\u7684\u6807\u51c6\u5316\u534f\u8bae\u6b63\u5728\u6084\u7136\u98a0\u8986\u6574\u4e2a\u751f\u6001&#xff1a;MCP&#xff08;Model Context Protocol\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/97028.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-28T14:16:31+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/97028.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/97028.html\",\"name\":\"MCP\u534f\u8bae\u4ece\u96f6\u5b9e\u73b0\uff1a\u624b\u5199\u4e00\u4e2a\u5b8c\u6574\u7684 Model Context Protocol \u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-28T14:16:31+00:00\",\"dateModified\":\"2026-08-28T14:16:31+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/97028.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/97028.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/97028.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"MCP\u534f\u8bae\u4ece\u96f6\u5b9e\u73b0\uff1a\u624b\u5199\u4e00\u4e2a\u5b8c\u6574\u7684 Model Context Protocol \u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MCP\u534f\u8bae\u4ece\u96f6\u5b9e\u73b0\uff1a\u624b\u5199\u4e00\u4e2a\u5b8c\u6574\u7684 Model Context Protocol \u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/97028.html","og_locale":"zh_CN","og_type":"article","og_title":"MCP\u534f\u8bae\u4ece\u96f6\u5b9e\u73b0\uff1a\u624b\u5199\u4e00\u4e2a\u5b8c\u6574\u7684 Model Context Protocol \u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u5f15\u8a00 2025-2026\u5e74\u662fAI Agent\u4ece\u6982\u5ff5\u8d70\u5411\u843d\u5730\u7684\u7206\u53d1\u671f\u3002\u4eceClaude Code\u3001Cursor\u5230Visual Studio Code Copilot&#xff0c;\u51e0\u4e4e\u4e3b\u6d41AI\u5e94\u7528\u90fd\u5728\u5411\"\u667a\u80fd\u4f53\"\u5f62\u6001\u6f14\u8fdb\u2014\u2014\u5b83\u4eec\u4e0d\u518d\u53ea\u662f\u95ee\u7b54\u673a\u5668\u4eba&#xff0c;\u800c\u662f\u80fd\u591f\u81ea\u4e3b\u8c03\u7528\u5de5\u5177\u3001\u8bfb\u53d6\u6587\u4ef6\u3001\u64cd\u4f5c\u6570\u636e\u5e93\u7684\u771f\u5b9e\u751f\u4ea7\u529b\u5de5\u5177\u3002 \u7136\u800c&#xff0c;\u8fd9\u4e9b\u80fd\u529b\u80cc\u540e\u6709\u4e00\u4e2a\u5173\u952e\u7684\u6807\u51c6\u5316\u534f\u8bae\u6b63\u5728\u6084\u7136\u98a0\u8986\u6574\u4e2a\u751f\u6001&#xff1a;MCP&#xff08;Model Context Protocol","og_url":"https:\/\/www.wsisp.com\/helps\/97028.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-28T14:16:31+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"15 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/97028.html","url":"https:\/\/www.wsisp.com\/helps\/97028.html","name":"MCP\u534f\u8bae\u4ece\u96f6\u5b9e\u73b0\uff1a\u624b\u5199\u4e00\u4e2a\u5b8c\u6574\u7684 Model Context Protocol \u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-28T14:16:31+00:00","dateModified":"2026-08-28T14:16:31+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/97028.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/97028.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/97028.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"MCP\u534f\u8bae\u4ece\u96f6\u5b9e\u73b0\uff1a\u624b\u5199\u4e00\u4e2a\u5b8c\u6574\u7684 Model Context Protocol \u670d\u52a1\u5668\u4e0e\u5ba2\u6237\u7aef"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/97028","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=97028"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/97028\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=97028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=97028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=97028"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=97028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}