{"id":46470,"date":"2025-07-30T03:12:43","date_gmt":"2025-07-29T19:12:43","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/46470.html"},"modified":"2025-07-30T03:12:43","modified_gmt":"2025-07-29T19:12:43","slug":"fastmcp%ef%bc%9a%e7%94%a8%e4%ba%8e%e6%9e%84%e5%bb%bamcp%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84%e5%bc%80%e6%ba%90python%e6%a1%86%e6%9e%b6","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/46470.html","title":{"rendered":"FastMCP\uff1a\u7528\u4e8e\u6784\u5efaMCP\u670d\u52a1\u5668\u7684\u5f00\u6e90Python\u6846\u67b6"},"content":{"rendered":"<p>\u5728\u4eba\u5de5\u667a\u80fd\u9886\u57df&#xff0c;\u6a21\u578b\u4e0a\u4e0b\u6587\u534f\u8bae&#xff08;Model Context Protocol&#xff0c;\u7b80\u79f0 MCP&#xff09;\u4f5c\u4e3a\u4e00\u79cd\u6807\u51c6\u5316\u7684\u534f\u8bae&#xff0c;\u4e3a\u5927\u578b\u8bed\u8a00\u6a21\u578b&#xff08;LLM&#xff09;\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u4e0a\u4e0b\u6587\u548c\u5de5\u5177\u652f\u6301\u3002\u800c FastMCP \u4f5c\u4e3a\u6784\u5efa MCP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684 Python \u6846\u67b6&#xff0c;\u4ee5\u5176\u7b80\u6d01\u7684 API \u8bbe\u8ba1\u3001\u9ad8\u6548\u7684\u5f00\u53d1\u4f53\u9a8c\u4ee5\u53ca\u5f3a\u5927\u7684\u6269\u5c55\u80fd\u529b&#xff0c;\u6b63\u9010\u6e10\u6210\u4e3a\u5f00\u53d1\u8005\u4eec\u7684\u9996\u9009\u5de5\u5177\u3002<\/p>\n<h4>\u4e00\u3001FastMCP \u7b80\u4ecb<\/h4>\n<p>FastMCP \u662f\u4e00\u4e2a\u7528\u4e8e\u6784\u5efa MCP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684 Python \u6846\u67b6&#xff0c;\u5176\u76ee\u6807\u662f\u8ba9\u5f00\u53d1\u8005\u80fd\u591f\u4ee5\u66f4\u5c11\u7684\u4ee3\u7801\u3001\u66f4\u9ad8\u7684\u6548\u7387\u6784\u5efa\u51fa\u529f\u80fd\u5f3a\u5927\u7684 MCP \u5e94\u7528\u3002\u76f8\u6bd4\u5b98\u65b9\u7684 MCP Python SDK&#xff0c;FastMCP \u5728\u591a\u4e2a\u65b9\u9762\u8fdb\u884c\u4e86\u4f18\u5316\u548c\u6539\u8fdb&#xff0c;\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u7684 API \u8bbe\u8ba1\u3001\u66f4\u9ad8\u6548\u7684\u5f00\u53d1\u4f53\u9a8c\u4ee5\u53ca\u66f4\u5f3a\u5927\u7684\u6269\u5c55\u80fd\u529b\u3002<\/p>\n<p>FastMCP \u7684\u6838\u5fc3\u4f18\u52bf\u4e3b\u8981\u4f53\u73b0\u5728\u4ee5\u4e0b\u51e0\u4e2a\u65b9\u9762&#xff1a;<\/p>\n<h5>&#xff08;\u4e00&#xff09;\u7b80\u6d01\u7684 API \u8bbe\u8ba1<\/h5>\n<p>FastMCP \u91c7\u7528\u4e86 Pythonic \u7684\u8bbe\u8ba1\u98ce\u683c&#xff0c;\u901a\u8fc7\u88c5\u9970\u5668&#xff08;Decorator&#xff09;\u5373\u53ef\u8f7b\u677e\u5b9a\u4e49\u5de5\u5177&#xff08;Tools&#xff09;\u3001\u8d44\u6e90&#xff08;Resources&#xff09;\u548c\u63d0\u793a&#xff08;Prompts&#xff09;\u3002\u8fd9\u79cd\u8bbe\u8ba1\u65b9\u5f0f\u6781\u5927\u5730\u51cf\u5c11\u4e86\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u7684\u6837\u677f\u4ee3\u7801&#xff0c;\u8ba9\u5f00\u53d1\u8005\u80fd\u591f\u66f4\u52a0\u4e13\u6ce8\u4e8e\u4e1a\u52a1\u903b\u8f91\u7684\u5b9e\u73b0\u3002<\/p>\n<h5>&#xff08;\u4e8c&#xff09;\u9ad8\u6548\u7684\u5f00\u53d1\u4f53\u9a8c<\/h5>\n<p>FastMCP \u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5185\u7f6e\u529f\u80fd&#xff0c;\u5982\u670d\u52a1\u5668\u7ec4\u5408\u3001\u8fdc\u7a0b\u670d\u52a1\u5668\u4ee3\u7406\u3001OpenAPI\/FastAPI \u96c6\u6210\u7b49&#xff0c;\u8fd9\u4e9b\u529f\u80fd\u4e0d\u4ec5\u63d0\u9ad8\u4e86\u5f00\u53d1\u6548\u7387&#xff0c;\u8fd8\u4e3a\u5f00\u53d1\u8005\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u7075\u6d3b\u6027\u3002\u6b64\u5916&#xff0c;FastMCP \u8fd8\u652f\u6301\u591a\u79cd\u5ba2\u6237\u7aef\/\u670d\u52a1\u7aef\u4f20\u8f93\u6a21\u5f0f&#xff0c;\u5305\u62ec Stdio\u3001SSE \u548c\u5185\u5b58\u4f20\u8f93&#xff0c;\u80fd\u591f\u6ee1\u8db3\u4e0d\u540c\u573a\u666f\u4e0b\u7684\u5f00\u53d1\u9700\u6c42\u3002<\/p>\n<h5>&#xff08;\u4e09&#xff09;\u5f3a\u5927\u7684\u6269\u5c55\u80fd\u529b<\/h5>\n<p>FastMCP \u7684\u8bbe\u8ba1\u5177\u6709\u9ad8\u5ea6\u7684\u53ef\u6269\u5c55\u6027&#xff0c;\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u8f7b\u677e\u6dfb\u52a0\u65b0\u7684\u529f\u80fd\u548c\u6a21\u5757\u3002\u65e0\u8bba\u662f\u6784\u5efa\u590d\u6742\u7684 AI \u5e94\u7528&#xff0c;\u8fd8\u662f\u8fdb\u884c\u7b80\u5355\u7684\u6570\u636e\u5904\u7406&#xff0c;FastMCP \u90fd\u80fd\u591f\u63d0\u4f9b\u5f3a\u5927\u7684\u652f\u6301\u3002<\/p>\n<h3>\u4e8c\u3001FastMCP\u529f\u80fd\u7279\u8272<\/h3>\n<ul>\n<li>\n<p>\u5feb\u901f\u5f00\u53d1&#xff1a;\u63d0\u4f9b\u9ad8\u5c42\u7ea7\u63a5\u53e3&#xff0c;\u5f00\u53d1\u8005\u4e0d\u9700\u8981\u5904\u7406\u590d\u6742\u7684\u534f\u8bae\u7ec6\u8282\u548c\u670d\u52a1\u5668\u7ba1\u7406&#xff0c;\u51cf\u5c11\u4e86\u7f16\u5199\u4ee3\u7801\u7684\u5de5\u4f5c\u91cf\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b80\u5355\u6613\u7528&#xff1a;\u4ec5\u9700\u5c11\u91cf\u7684\u6837\u677f\u4ee3\u7801\u5373\u53ef\u6784\u5efa MCP \u670d\u52a1\u5668&#xff0c;\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u88c5\u9970\u5668\u7684\u65b9\u5f0f&#xff0c;\u8f7b\u677e\u5b9a\u4e49\u5de5\u5177\u3001\u8d44\u6e90\u548c\u63d0\u793a&#xff0c;\u5927\u5927\u51cf\u5c11\u4e86\u5197\u4f59\u4ee3\u7801\u3002<\/p>\n<\/li>\n<li>\n<p>Pythonic \u98ce\u683c&#xff1a;\u5145\u5206\u5229\u7528\u4e86 Python \u7684\u8bed\u8a00\u7279\u6027&#xff0c;\u8ba9\u4ee3\u7801\u7f16\u5199\u66f4\u52a0\u7b26\u5408 Python \u7684\u7f16\u7a0b\u4e60\u60ef\u3002<\/p>\n<\/li>\n<li>\n<p>\u529f\u80fd\u5b8c\u6574&#xff1a;\u63d0\u4f9b\u5bf9 MCP \u6838\u5fc3\u89c4\u8303\u7684\u5b8c\u6574\u5b9e\u73b0&#xff0c;\u76ee\u524d\u6838\u5fc3\u529f\u80fd\u5df2\u7ecf\u80fd\u591f\u6ee1\u8db3\u5927\u591a\u6570\u5f00\u53d1\u9700\u6c42&#xff0c;\u5e76\u4ecd\u5904\u4e8e\u6d3b\u8dc3\u5f00\u53d1\u4e2d\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u4e09\u3001FastMCP\u6838\u5fc3\u7ec4\u4ef6<\/h3>\n<ul>\n<li>\n<p>\u5de5\u5177&#xff08;Tools&#xff09;&#xff1a;\u5b9a\u4e49 LLM \u53ef\u6267\u884c\u7684\u64cd\u4f5c&#xff08;\u5982\u8ba1\u7b97\u3001API \u8c03\u7528&#xff09;&#xff0c;\u652f\u6301\u540c\u6b65\u548c\u5f02\u6b65\u51fd\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u8d44\u6e90&#xff08;Resources&#xff09;&#xff1a;\u63d0\u4f9b\u7ed3\u6784\u5316\u6570\u636e\u8bbf\u95ee&#xff08;\u5982\u914d\u7f6e\u4fe1\u606f\u3001\u7528\u6237\u6570\u636e&#xff09;&#xff0c;\u652f\u6301\u52a8\u6001\u8def\u5f84\u53c2\u6570\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e0a\u4e0b\u6587&#xff08;Context&#xff09;&#xff1a;\u5185\u7f6e\u65e5\u5fd7\u8bb0\u5f55\u3001\u8fdb\u5ea6\u62a5\u544a\u3001\u8d44\u6e90\u8bfb\u53d6\u7b49\u80fd\u529b&#xff0c;\u589e\u5f3a\u4ea4\u4e92\u63a7\u5236\u3002<\/p>\n<\/li>\n<li>\n<p>\u63d0\u793a&#xff08;Prompts&#xff09;&#xff1a;\u53ef\u590d\u7528\u4ea4\u4e92\u6a21\u677f&#xff0c;\u6307\u5bfc LLM \u66f4\u9ad8\u6548\u5730\u4f7f\u7528\u5de5\u5177\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u56db\u3001\u4f18\u52bf<\/h3>\n<ul>\n<li>\n<p>\u5feb\u901f\u5f00\u53d1&#xff1a;\u901a\u8fc7\u9ad8\u7ea7\u63a5\u53e3&#xff0c;\u51cf\u5c11\u4ee3\u7801\u91cf&#xff0c;\u52a0\u901f\u5f00\u53d1\u3002<\/p>\n<\/li>\n<li>\n<p>\u7b80\u6d01\u6613\u7528&#xff1a;\u4f7f\u7528\u6700\u5c11\u7684\u6837\u677f\u4ee3\u7801\u6784\u5efa MCP \u670d\u52a1\u5668\u3002<\/p>\n<\/li>\n<li>\n<p>Pythonic&#xff1a;\u7b26\u5408 Python \u5f00\u53d1\u8005\u7684\u4e60\u60ef\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b8c\u6574\u5b9e\u73b0&#xff1a;\u5168\u9762\u652f\u6301 MCP \u6838\u5fc3\u89c4\u8303\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u4e94\u3001FastMCP\u4f7f\u7528\u573a\u666f<\/h3>\n<ul>\n<li>\n<p>ai\u00a0\u52a9\u624b\u5de5\u5177\u96c6&#xff1a;\u4e3a AI \u52a9\u624b\u63d0\u4f9b\u672c\u5730\u529f\u80fd\u6269\u5c55\u3002<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u5e93\u4ea4\u4e92&#xff1a;\u5b89\u5168\u5730\u66b4\u9732\u6570\u636e\u5e93\u67e5\u8be2\u529f\u80fd\u3002<\/p>\n<\/li>\n<li>\n<p>\u6587\u4ef6\u5904\u7406&#xff1a;\u8bfb\u53d6\u548c\u5904\u7406\u672c\u5730\u6587\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>API \u96c6\u6210&#xff1a;\u5c06\u73b0\u6709 API \u5305\u88c5\u4e3a AI \u53ef\u7528\u7684\u5de5\u5177\u3002<\/p>\n<\/li>\n<li>\n<p>\u667a\u80fd\u5ba2\u670d&#xff1a;\u53ef\u4ee5\u4f7f\u7528 FastMCP \u6784\u5efa\u670d\u52a1\u5668&#xff0c;\u4e3a\u5ba2\u670d\u4eba\u5458\u63d0\u4f9b\u5feb\u901f\u67e5\u8be2\u77e5\u8bc6\u5e93\u3001\u8c03\u7528\u6570\u636e\u5206\u6790\u5de5\u5177\u7b49\u529f\u80fd<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u5206\u6790&#xff1a;\u901a\u8fc7 FastMCP \u5c06\u5404\u79cd\u6570\u636e\u5206\u6790\u5de5\u5177\u96c6\u6210\u5230 LLM \u4e2d&#xff0c;\u8ba9\u7528\u6237\u80fd\u591f\u66f4\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u5206\u6790<\/p>\n<\/li>\n<\/ul>\n<h4>\u516d\u3001FastMCP \u4e0e\u5b98\u65b9 SDK \u7684\u5173\u7cfb<\/h4>\n<p>FastMCP 1.0 \u7684\u6838\u5fc3\u6982\u5ff5\u5df2\u7ecf\u88ab\u7eb3\u5165\u5b98\u65b9\u7684 MCP Python SDK&#xff0c;\u800c\u5f53\u524d\u7684 FastMCP 2.0 \u5219\u662f\u5728\u6b64\u57fa\u7840\u4e0a\u8fdb\u884c\u7684\u8fdb\u4e00\u6b65\u6269\u5c55\u548c\u4f18\u5316\u3002FastMCP 2.0 \u4e0d\u4ec5\u7ee7\u627f\u4e86 1.0 \u7248\u672c\u7684\u57fa\u7840\u529f\u80fd&#xff0c;\u8fd8\u5f15\u5165\u4e86\u5b8c\u6574\u7684\u5ba2\u6237\u7aef\u652f\u6301\u3001\u670d\u52a1\u5668\u7ec4\u5408\u3001OpenAPI\/FastAPI \u96c6\u6210\u3001\u8fdc\u7a0b\u670d\u52a1\u5668\u4ee3\u7406\u4ee5\u53ca\u5185\u7f6e\u6d4b\u8bd5\u5de5\u5177\u7b49\u65b0\u529f\u80fd&#xff0c;\u663e\u7740\u63d0\u5347\u4e86\u5f00\u53d1\u6548\u7387\u548c\u5e94\u7528\u7684\u7075\u6d3b\u6027\u3002<\/p>\n<h4>\u4e03\u3001\u5f00\u53d1\u793a\u4f8b<\/h4>\n<p>\u4e3a\u4e86\u66f4\u597d\u5730\u7406\u89e3 FastMCP \u7684\u5f3a\u5927\u529f\u80fd\u548c\u7b80\u6d01\u7684\u5f00\u53d1\u65b9\u5f0f&#xff0c;\u6211\u4eec\u4ee5\u4e00\u4e2a\u57fa\u4e8e FastMCP \u7684\u6570\u5b66\u8fd0\u7b97\u667a\u80fd\u95ee\u7b54\u5e94\u7528\u4e3a\u4f8b&#xff0c;\u8be6\u7ec6\u4ecb\u7ecd\u5176\u5f00\u53d1\u8fc7\u7a0b\u3002<\/p>\n<h5>&#xff08;\u4e00&#xff09;\u5b89\u88c5 FastMCP<\/h5>\n<p>\u9996\u5148&#xff0c;\u9700\u8981\u5b89\u88c5 FastMCP \u6846\u67b6\u3002\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\u5b8c\u6210\u5b89\u88c5&#xff1a;<\/p>\n<p>uv pip install fastmcp<\/p>\n<h5>&#xff08;\u4e8c&#xff09;\u670d\u52a1\u7aef\u5b9e\u73b0<\/h5>\n<p>\u670d\u52a1\u7aef\u7684\u5b9e\u73b0\u975e\u5e38\u7b80\u5355&#xff0c;\u53ea\u9700\u8981\u5b9a\u4e49\u51e0\u4e2a\u57fa\u672c\u7684\u6570\u5b66\u8fd0\u7b97\u5de5\u5177\u5373\u53ef\u3002\u4ee5\u4e0b\u662f\u670d\u52a1\u7aef\u7684\u4ee3\u7801\u793a\u4f8b&#xff1a;<\/p>\n<p>from fastmcp import FastMCP<\/p>\n<p>mcp &#061; FastMCP(name&#061;&#034;MyAssistantServer&#034;)<\/p>\n<p>&#064;mcp.tool()<br \/>\ndef add(a: float, b: float) -&gt; float:<br \/>\n    &#034;&#034;&#034;\u52a0\u6cd5\u8fd0\u7b97<\/p>\n<p>    \u53c2\u6570:<br \/>\n    a: \u7b2c\u4e00\u4e2a\u6570\u5b57<br \/>\n    b: \u7b2c\u4e8c\u4e2a\u6570\u5b57<\/p>\n<p>    \u8fd4\u56de:<br \/>\n    \u4e24\u6570\u4e4b\u548c<br \/>\n    &#034;&#034;&#034;<br \/>\n    return a &#043; b<\/p>\n<p>&#064;mcp.tool()<br \/>\ndef subtract(a: float, b: float) -&gt; float:<br \/>\n    &#034;&#034;&#034;\u51cf\u6cd5\u8fd0\u7b97<\/p>\n<p>    \u53c2\u6570:<br \/>\n    a: \u7b2c\u4e00\u4e2a\u6570\u5b57<br \/>\n    b: \u7b2c\u4e8c\u4e2a\u6570\u5b57<\/p>\n<p>    \u8fd4\u56de:<br \/>\n    \u4e24\u6570\u4e4b\u5dee (a &#8211; b)<br \/>\n    &#034;&#034;&#034;<br \/>\n    return a &#8211; b<\/p>\n<p>&#064;mcp.tool()<br \/>\ndef multiply(a: float, b: float) -&gt; float:<br \/>\n    &#034;&#034;&#034;\u4e58\u6cd5\u8fd0\u7b97<\/p>\n<p>    \u53c2\u6570:<br \/>\n    a: \u7b2c\u4e00\u4e2a\u6570\u5b57<br \/>\n    b: \u7b2c\u4e8c\u4e2a\u6570\u5b57<\/p>\n<p>    \u8fd4\u56de:<br \/>\n    \u4e24\u6570\u4e4b\u79ef<br \/>\n    &#034;&#034;&#034;<br \/>\n    return a * b<\/p>\n<p>&#064;mcp.tool()<br \/>\ndef divide(a: float, b: float) -&gt; float:<br \/>\n    &#034;&#034;&#034;\u9664\u6cd5\u8fd0\u7b97<\/p>\n<p>    \u53c2\u6570:<br \/>\n    a: \u88ab\u9664\u6570<br \/>\n    b: \u9664\u6570<\/p>\n<p>    \u8fd4\u56de:<br \/>\n    \u4e24\u6570\u4e4b\u5546 (a \/ b)<\/p>\n<p>    \u5f02\u5e38:<br \/>\n    ValueError: \u5f53\u9664\u6570\u4e3a\u96f6\u65f6<br \/>\n    &#034;&#034;&#034;<br \/>\n    if b &#061;&#061; 0:<br \/>\n        raise ValueError(&#034;\u9664\u6570\u4e0d\u80fd\u4e3a\u96f6&#034;)<br \/>\n    return a \/ b<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    mcp.run(transport&#061;&#039;sse&#039;, host&#061;&#034;127.0.0.1&#034;, port&#061;8001)<\/p>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d&#xff0c;\u6211\u4eec\u5b9a\u4e49\u4e86\u56db\u4e2a\u57fa\u672c\u7684\u6570\u5b66\u8fd0\u7b97\u5de5\u5177&#xff1a;\u52a0\u6cd5\u3001\u51cf\u6cd5\u3001\u4e58\u6cd5\u548c\u9664\u6cd5\u3002\u901a\u8fc7\u88c5\u9970\u5668\u00a0&#064;mcp.tool()&#xff0c;\u8fd9\u4e9b\u51fd\u6570\u88ab\u6ce8\u518c\u4e3a MCP \u670d\u52a1\u5668\u7684\u5de5\u5177&#xff0c;\u53ef\u4f9b\u5ba2\u6237\u7aef\u8c03\u7528\u3002\u6700\u540e&#xff0c;\u901a\u8fc7\u8c03\u7528\u00a0mcp.run()\u00a0\u65b9\u6cd5\u542f\u52a8\u670d\u52a1\u5668&#xff0c;\u5e76\u6307\u5b9a\u4f7f\u7528 SSE \u4f20\u8f93\u6a21\u5f0f\u3002<\/p>\n<h5>&#xff08;\u4e09&#xff09;\u5ba2\u6237\u7aef\u5b9e\u73b0<\/h5>\n<p>\u5ba2\u6237\u7aef\u7684\u5b9e\u73b0\u540c\u6837\u7b80\u5355\u3002\u901a\u8fc7\u4e00\u884c\u4ee3\u7801\u5373\u53ef\u521b\u5efa\u4e00\u4e2a MCP \u5ba2\u6237\u7aef&#xff0c;\u5e76\u8fde\u63a5\u5230\u670d\u52a1\u7aef\u3002\u4ee5\u4e0b\u662f\u5ba2\u6237\u7aef\u7684\u4ee3\u7801\u793a\u4f8b&#xff1a;<\/p>\n<p>from fastmcp import Client<br \/>\nimport asyncio<\/p>\n<p>async def main():<br \/>\n    # \u6d4b\u8bd5 mcp \u5ba2\u6237\u7aef\u7684\u529f\u80fd<br \/>\n    async with Client(&#034;http:\/\/127.0.0.1:8001\/sse&#034;) as mcp_client:<br \/>\n        tools &#061; await mcp_client.list_tools()<br \/>\n        print(f&#034;Available tools: {tools}&#034;)<br \/>\n        result &#061; await mcp_client.call_tool(&#034;add&#034;, {&#034;a&#034;: 5, &#034;b&#034;: 3})<br \/>\n        print(f&#034;Result: {result[0].text}&#034;)<\/p>\n<p>if __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    asyncio.run(main())<\/p>\n<p>\u5728\u4e0a\u8ff0\u4ee3\u7801\u4e2d&#xff0c;\u6211\u4eec\u901a\u8fc7\u00a0Client\u00a0\u7c7b\u521b\u5efa\u4e86\u4e00\u4e2a MCP \u5ba2\u6237\u7aef&#xff0c;\u5e76\u8fde\u63a5\u5230\u670d\u52a1\u7aef\u3002\u901a\u8fc7\u8c03\u7528\u00a0list_tools()\u00a0\u65b9\u6cd5&#xff0c;\u6211\u4eec\u53ef\u4ee5\u83b7\u53d6\u670d\u52a1\u7aef\u63d0\u4f9b\u7684\u6240\u6709\u5de5\u5177\u5217\u8868\u3002\u7136\u540e&#xff0c;\u901a\u8fc7\u8c03\u7528\u00a0call_tool()\u00a0\u65b9\u6cd5&#xff0c;\u6211\u4eec\u53ef\u4ee5\u8c03\u7528\u670d\u52a1\u7aef\u7684\u5de5\u5177\u5e76\u83b7\u53d6\u7ed3\u679c\u3002<\/p>\n<h5>&#xff08;\u56db&#xff09;\u6570\u5b66\u8fd0\u7b97\u667a\u80fd\u95ee\u7b54\u5e94\u7528<\/h5>\n<p>\u57fa\u4e8e FastMCP&#xff0c;\u6211\u4eec\u8fd8\u53ef\u4ee5\u6784\u5efa\u4e00\u4e2a\u6570\u5b66\u8fd0\u7b97\u667a\u80fd\u95ee\u7b54\u5e94\u7528\u3002\u8be5\u5e94\u7528\u901a\u8fc7\u4e0e\u5927\u8bed\u8a00\u6a21\u578b&#xff08;LLM&#xff09;\u8fdb\u884c\u4ea4\u4e92&#xff0c;\u6839\u636e\u7528\u6237\u7684\u8f93\u5165\u8c03\u7528\u76f8\u5e94\u7684\u5de5\u5177\u8fdb\u884c\u8ba1\u7b97&#xff0c;\u5e76\u8fd4\u56de\u7ed3\u679c\u3002\u4ee5\u4e0b\u662f\u8be5\u5e94\u7528\u7684\u4ee3\u7801\u793a\u4f8b&#xff1a;<\/p>\n<p>import asyncio<br \/>\nimport json<br \/>\nimport logging<br \/>\nimport os<br \/>\nfrom typing import List, Dict<\/p>\n<p>from fastmcp import Client<br \/>\nfrom openai import OpenAI<\/p>\n<p>class LLMClient:<br \/>\n    &#034;&#034;&#034;LLM\u5ba2\u6237\u7aef&#xff0c;\u8d1f\u8d23\u4e0e\u5927\u8bed\u8a00\u6a21\u578bAPI\u901a\u4fe1&#034;&#034;&#034;<\/p>\n<p>    def __init__(self, model_name: str, url: str, api_key: str) -&gt; None:<br \/>\n        self.model_name: str &#061; model_name<br \/>\n        self.url: str &#061; url<br \/>\n        self.client &#061; OpenAI(api_key&#061;api_key, base_url&#061;url)<\/p>\n<p>    def get_response(self, messages: List[Dict[str, str]]) -&gt; str:<br \/>\n        &#034;&#034;&#034;\u53d1\u9001\u6d88\u606f\u7ed9LLM\u5e76\u83b7\u53d6\u54cd\u5e94&#034;&#034;&#034;<br \/>\n        response &#061; self.client.chat.completions.create(<br \/>\n            model&#061;self.model_name,<br \/>\n            messages&#061;messages,<br \/>\n            stream&#061;False<br \/>\n        )<br \/>\n        return response.choices[0].message.content<\/p>\n<p>class ChatSession:<br \/>\n    &#034;&#034;&#034;\u804a\u5929\u4f1a\u8bdd&#xff0c;\u5904\u7406\u7528\u6237\u8f93\u5165\u548cLLM\u54cd\u5e94&#xff0c;\u5e76\u4e0eMCP\u5de5\u5177\u4ea4\u4e92&#034;&#034;&#034;<\/p>\n<p>    def __init__(self, llm_client: LLMClient, mcp_client: Client) -&gt; None:<br \/>\n        self.mcp_client: Client &#061; mcp_client<br \/>\n        self.llm_client: LLMClient &#061; llm_client<\/p>\n<p>    async def process_llm_response(self, llm_response: str) -&gt; str:<br \/>\n        &#034;&#034;&#034;\u5904\u7406LLM\u54cd\u5e94&#xff0c;\u89e3\u6790\u5de5\u5177\u8c03\u7528\u5e76\u6267\u884c&#034;&#034;&#034;<br \/>\n        try:<br \/>\n            # \u5c1d\u8bd5\u79fb\u9664\u53ef\u80fd\u7684markdown\u683c\u5f0f<br \/>\n            if llm_response.startswith(&#039;&#096;&#096;&#096;json&#039;):<br \/>\n                llm_response &#061; llm_response.strip(&#039;&#096;&#096;&#096;json&#039;).strip(&#039;&#096;&#096;&#096;&#039;).strip()<br \/>\n            tool_call &#061; json.loads(llm_response)<br \/>\n            if &#034;tool&#034; in tool_call and &#034;arguments&#034; in tool_call:<br \/>\n                # \u68c0\u67e5\u5de5\u5177\u662f\u5426\u53ef\u7528<br \/>\n                tools &#061; await self.mcp_client.list_tools()<br \/>\n                if any(tool.name &#061;&#061; tool_call[&#034;tool&#034;] for tool in tools):<br \/>\n                    try:<br \/>\n                        # \u6267\u884c\u5de5\u5177\u8c03\u7528<br \/>\n                        result &#061; await self.mcp_client.call_tool(<br \/>\n                            tool_call[&#034;tool&#034;], tool_call[&#034;arguments&#034;]<br \/>\n                        )<\/p>\n<p>                        return f&#034;Tool execution result: {result}&#034;<br \/>\n                    except Exception as e:<br \/>\n                        error_msg &#061; f&#034;Error executing tool: {str(e)}&#034;<br \/>\n                        logging.error(error_msg)<br \/>\n                        return error_msg<br \/>\n                return f&#034;No server found with tool: {tool_call[&#039;tool&#039;]}&#034;<br \/>\n            return llm_response<br \/>\n        except json.JSONDecodeError:<br \/>\n            # \u5982\u679c\u4e0d\u662fJSON\u683c\u5f0f&#xff0c;\u76f4\u63a5\u8fd4\u56de\u539f\u59cb\u54cd\u5e94<br \/>\n            return llm_response<\/p>\n<p>    async def start(self, system_message: str) -&gt; None:<br \/>\n        &#034;&#034;&#034;\u542f\u52a8\u804a\u5929\u4f1a\u8bdd\u7684\u4e3b\u5faa\u73af&#034;&#034;&#034;<br \/>\n        messages &#061; [{&#034;role&#034;: &#034;system&#034;, &#034;content&#034;: system_message}]<br \/>\n        while True:<br \/>\n            try:<br \/>\n                # \u83b7\u53d6\u7528\u6237\u8f93\u5165<br \/>\n                user_input &#061; input(&#034;\u7528\u6237: &#034;).strip().lower()<br \/>\n                if user_input in [&#034;quit&#034;, &#034;exit&#034;, &#034;\u9000\u51fa&#034;]:<br \/>\n                    print(&#039;AI\u52a9\u624b\u9000\u51fa&#039;)<br \/>\n                    break<br \/>\n                messages.append({&#034;role&#034;: &#034;user&#034;, &#034;content&#034;: user_input})<\/p>\n<p>                # \u83b7\u53d6LLM\u7684\u521d\u59cb\u54cd\u5e94<br \/>\n                llm_response &#061; self.llm_client.get_response(messages)<br \/>\n                print(&#034;\u52a9\u624b: &#034;, llm_response)<\/p>\n<p>                # \u5904\u7406\u53ef\u80fd\u7684\u5de5\u5177\u8c03\u7528<br \/>\n                result &#061; await self.process_llm_response(llm_response)<\/p>\n<p>                # \u5982\u679c\u5904\u7406\u7ed3\u679c\u4e0e\u539f\u59cb\u54cd\u5e94\u4e0d\u540c&#xff0c;\u8bf4\u660e\u6267\u884c\u4e86\u5de5\u5177\u8c03\u7528&#xff0c;\u9700\u8981\u8fdb\u4e00\u6b65\u5904\u7406<br \/>\n                while result !&#061; llm_response:<br \/>\n                    messages.append({&#034;role&#034;: &#034;assistant&#034;, &#034;content&#034;: llm_response})<br \/>\n                    messages.append({&#034;role&#034;: &#034;system&#034;, &#034;content&#034;: result})<\/p>\n<p>                    # \u5c06\u5de5\u5177\u6267\u884c\u7ed3\u679c\u53d1\u9001\u56deLLM\u83b7\u53d6\u65b0\u54cd\u5e94<br \/>\n                    llm_response &#061; self.llm_client.get_response(messages)<br \/>\n                    result &#061; await self.process_llm_response(llm_response)<br \/>\n                    print(&#034;\u52a9\u624b: &#034;, llm_response)<\/p>\n<p>                messages.append({&#034;role&#034;: &#034;assistant&#034;, &#034;content&#034;: llm_response})<\/p>\n<p>            except KeyboardInterrupt:<br \/>\n                print(&#039;AI\u52a9\u624b\u9000\u51fa&#039;)<br \/>\n                break<\/p>\n<p>async def main():<br \/>\n    async with Client(&#034;http:\/\/127.0.0.1:8001\/sse&#034;) as mcp_client:<br \/>\n        # \u521d\u59cb\u5316LLM\u5ba2\u6237\u7aef&#xff0c;\u4f7f\u7528\u901a\u4e49\u5343\u95ee\u6a21\u578b<br \/>\n        llm_client &#061; LLMClient(model_name&#061;&#039;qwen-plus-latest&#039;, api_key&#061;os.getenv(&#039;DASHSCOPE_API_KEY&#039;),<br \/>\n                               url&#061;&#039;https:\/\/dashscope.aliyuncs.com\/compatible-mode\/v1&#039;)<\/p>\n<p>        # \u83b7\u53d6\u53ef\u7528\u5de5\u5177\u5217\u8868\u5e76\u683c\u5f0f\u5316\u4e3a\u7cfb\u7edf\u63d0\u793a\u7684\u4e00\u90e8\u5206<br \/>\n        tools &#061; await mcp_client.list_tools()<br \/>\n        dict_list &#061; [tool.__dict__ for tool in tools]<br \/>\n        tools_description &#061; json.dumps(dict_list, ensure_ascii&#061;False)<\/p>\n<p>        # \u7cfb\u7edf\u63d0\u793a&#xff0c;\u6307\u5bfcLLM\u5982\u4f55\u4f7f\u7528\u5de5\u5177\u548c\u8fd4\u56de\u54cd\u5e94<br \/>\n        system_message &#061; f&#039;&#039;&#039;<br \/>\n                \u4f60\u662f\u4e00\u4e2a\u667a\u80fd\u52a9\u624b&#xff0c;\u4e25\u683c\u9075\u5faa\u4ee5\u4e0b\u534f\u8bae\u8fd4\u56de\u54cd\u5e94&#xff1a;<\/p>\n<p>                \u53ef\u7528\u5de5\u5177&#xff1a;{tools_description}<\/p>\n<p>                \u54cd\u5e94\u89c4\u5219&#xff1a;<br \/>\n                1\u3001\u5f53\u9700\u8981\u8ba1\u7b97\u65f6&#xff0c;\u8fd4\u56de\u4e25\u683c\u7b26\u5408\u4ee5\u4e0b\u683c\u5f0f\u7684\u7eaf\u51c0JSON&#xff1a;<br \/>\n                {{<br \/>\n                    &#034;tool&#034;: &#034;tool-name&#034;,<br \/>\n                    &#034;arguments&#034;: {{<br \/>\n                        &#034;argument-name&#034;: &#034;value&#034;<br \/>\n                    }}<br \/>\n                }}<br \/>\n                2\u3001\u7981\u6b62\u5305\u542b\u4ee5\u4e0b\u5185\u5bb9&#xff1a;<br \/>\n                 &#8211; Markdown\u6807\u8bb0&#xff08;\u5982&#096;&#096;&#096;json&#xff09;<br \/>\n                 &#8211; \u81ea\u7136\u8bed\u8a00\u89e3\u91ca&#xff08;\u5982&#034;\u7ed3\u679c&#xff1a;&#034;&#xff09;<br \/>\n                 &#8211; \u683c\u5f0f\u5316\u6570\u503c&#xff08;\u5fc5\u987b\u4fdd\u6301\u539f\u59cb\u7cbe\u5ea6&#xff09;<br \/>\n                 &#8211; \u5355\u4f4d\u7b26\u53f7&#xff08;\u5982\u5143\u3001kg&#xff09;<\/p>\n<p>                \u6821\u9a8c\u6d41\u7a0b&#xff1a;<br \/>\n                \u2713 \u53c2\u6570\u6570\u91cf\u4e0e\u5de5\u5177\u5b9a\u4e49\u4e00\u81f4<br \/>\n                \u2713 \u6570\u503c\u7c7b\u578b\u4e3anumber<br \/>\n                \u2713 JSON\u683c\u5f0f\u6709\u6548\u6027\u68c0\u67e5<\/p>\n<p>                \u6b63\u786e\u793a\u4f8b&#xff1a;<br \/>\n                \u7528\u6237&#xff1a;\u5355\u4ef788.5\u4e70235\u4e2a\u591a\u5c11\u94b1&#xff1f;<br \/>\n                \u54cd\u5e94&#xff1a;{{&#034;tool&#034;:&#034;multiply&#034;,&#034;arguments&#034;:{{&#034;a&#034;:88.5,&#034;b&#034;:235}}}}<\/p>\n<p>                \u9519\u8bef\u793a\u4f8b&#xff1a;<br \/>\n                \u7528\u6237&#xff1a;\u603b\u91d1\u989d\u662f\u591a\u5c11&#xff1f;<br \/>\n                \u9519\u8bef\u54cd\u5e94&#xff1a;\u603b\u4ef7500\u5143 \u2192 \u542b\u81ea\u7136\u8bed\u8a00<br \/>\n                \u9519\u8bef\u54cd\u5e94&#xff1a;&#096;&#096;&#096;json{{&#8230;}}&#096;&#096;&#096;\u2192 \u542bMarkdown<\/p>\n<p>                3\u3001\u5728\u6536\u5230\u5de5\u5177\u7684\u54cd\u5e94\u540e&#xff1a;<br \/>\n                 &#8211; \u5c06\u539f\u59cb\u6570\u636e\u8f6c\u5316\u4e3a\u81ea\u7136\u3001\u5bf9\u8bdd\u5f0f\u7684\u56de\u5e94<br \/>\n                 &#8211; \u4fdd\u6301\u56de\u590d\u7b80\u6d01\u4f46\u4fe1\u606f\u4e30\u5bcc<br \/>\n                 &#8211; \u805a\u7126\u4e8e\u6700\u76f8\u5173\u7684\u4fe1\u606f<br \/>\n                 &#8211; \u4f7f\u7528\u7528\u6237\u95ee\u9898\u4e2d\u7684\u9002\u5f53\u4e0a\u4e0b\u6587<br \/>\n                 &#8211; \u907f\u514d\u7b80\u5355\u91cd\u590d\u4f7f\u7528\u539f\u59cb\u6570\u636e<br \/>\n                &#039;&#039;&#039;<br \/>\n        # \u542f\u52a8\u804a\u5929\u4f1a\u8bdd<br \/>\n        chat_session &#061; ChatSession(llm_client&#061;llm_client, mcp_client&#061;mcp_client)<br \/>\n        await chat_session.start(system_message&#061;system_message)<\/p>\n<p>if __name__ &#061;&#061; &#034;__<br \/>\n__main__&#034;:<br \/>\n    asyncio.run(main())<\/p>\n<h5>&#xff08;\u4e94&#xff09;\u8fd0\u884c\u9a8c\u8bc1<\/h5>\n<p>\u8fd0\u884c\u670d\u52a1\u7aef\u4ee3\u7801&#xff1a;<\/p>\n<p>python fast_mcp_server.py<\/p>\n<p>\u8fd0\u884c\u5ba2\u6237\u7aef\u4ee3\u7801&#xff1a;<\/p>\n<p>python fast_mcp_client.py<\/p>\n<p>\u5728\u5ba2\u6237\u7aef\u4e2d\u8f93\u5165\u6570\u5b66\u95ee\u9898&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<p>\u7528\u6237: \u73b0\u5728\u8981\u8d2d\u4e70\u4e00\u6279\u8d27&#xff0c;\u5355\u4ef7\u662f 1034.32423&#xff0c;\u6570\u91cf\u662f 235326\u3002\u5546\u5bb6\u540e\u6765\u53c8\u8bf4&#xff0c;\u53ef\u4ee5\u5728\u8fd9\u4e2a\u57fa\u7840\u4e0a&#xff0c;\u625395\u6298&#xff0c;\u6298\u540e\u603b\u4ef7\u662f\u591a\u5c11&#xff1f;<\/p>\n<p>\u5ba2\u6237\u7aef\u4f1a\u8c03\u7528\u670d\u52a1\u7aef\u7684\u00a0multiply\u00a0\u5de5\u5177\u8fdb\u884c\u8ba1\u7b97&#xff0c;\u5e76\u8fd4\u56de\u7ed3\u679c&#xff1a;<\/p>\n<p>\u52a9\u624b:  {<br \/>\n  &#034;tool&#034;: &#034;multiply&#034;,<br \/>\n  &#034;arguments&#034;: {<br \/>\n    &#034;a&#034;: 1034.32423,<br \/>\n    &#034;b&#034;: 235326<br \/>\n  }<br \/>\n}<br \/>\n\u52a9\u624b:  {<br \/>\n  &#034;tool&#034;: &#034;multiply&#034;,<br \/>\n  &#034;arguments&#034;: {<br \/>\n    &#034;a&#034;: 243403383.74898,<br \/>\n    &#034;b&#034;: 0.95<br \/>\n  }<br \/>\n}<br \/>\n\u52a9\u624b:  \u6298\u540e\u603b\u4ef7\u662f231233214.56\u3002<\/p>\n<h4>\u516b\u3001FastMCP \u7684\u66f4\u591a\u529f\u80fd<\/h4>\n<p>\u9664\u4e86\u4e0a\u8ff0\u63d0\u5230\u7684\u529f\u80fd\u5916&#xff0c;FastMCP \u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591a\u5176\u4ed6\u5f3a\u5927\u7684\u529f\u80fd&#xff0c;\u4f8b\u5982&#xff1a;<\/p>\n<h5>&#xff08;\u4e00&#xff09;\u670d\u52a1\u5668\u7ec4\u5408<\/h5>\n<p>\u901a\u8fc7\u00a0mcp.mount()\u00a0\u6216\u00a0mcp.import_server()\u00a0\u65b9\u6cd5&#xff0c;\u53ef\u4ee5\u5c06\u591a\u4e2a\u00a0FastMCP\u00a0\u5b9e\u4f8b\u7ec4\u5408\u5230\u4e00\u4e2a\u7236\u670d\u52a1\u5668\u4e2d&#xff0c;\u4ece\u800c\u6784\u5efa\u51fa\u6a21\u5757\u5316\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u63d0\u9ad8\u4e86\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027&#xff0c;\u8fd8\u65b9\u4fbf\u4e86\u529f\u80fd\u7684\u6269\u5c55\u3002<\/p>\n<h5>&#xff08;\u4e8c&#xff09;OpenAPI\/FastAPI \u96c6\u6210<\/h5>\n<p>FastMCP \u63d0\u4f9b\u4e86\u4ece\u73b0\u6709\u7684 OpenAPI \u89c4\u8303\u6216 FastAPI \u5e94\u7528\u7a0b\u5e8f\u751f\u6210\u00a0FastMCP\u00a0\u670d\u52a1\u5668\u7684\u529f\u80fd\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f&#xff0c;\u5f00\u53d1\u8005\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u73b0\u6709\u7684 Web API \u96c6\u6210\u5230 MCP \u751f\u6001\u7cfb\u7edf\u4e2d&#xff0c;\u8fdb\u4e00\u6b65\u6269\u5c55\u4e86 MCP \u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<h5>&#xff08;\u4e09&#xff09;\u4ee3\u7406\u670d\u52a1\u5668<\/h5>\n<p>\u901a\u8fc7\u00a0FastMCP.as_proxy()\u00a0\u65b9\u6cd5&#xff0c;\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u4ee3\u7406\u670d\u52a1\u5668&#xff0c;\u8be5\u670d\u52a1\u5668\u53ef\u4ee5\u4f5c\u4e3a\u672c\u5730\u6216\u8fdc\u7a0b MCP \u670d\u52a1\u5668\u7684\u4e2d\u95f4\u5c42\u3002\u8fd9\u79cd\u65b9\u5f0f\u7279\u522b\u9002\u7528\u4e8e\u6865\u63a5\u4e0d\u540c\u7684\u4f20\u8f93\u534f\u8bae&#xff08;\u4f8b\u5982&#xff0c;\u5c06\u8fdc\u7a0b SSE \u670d\u52a1\u5668\u4ee3\u7406\u5230\u672c\u5730 Stdio \u5ba2\u6237\u7aef&#xff09;\u6216\u4e3a\u4e0d\u53d7\u63a7\u5236\u7684\u670d\u52a1\u5668\u6dfb\u52a0\u903b\u8f91\u5c42\u3002<\/p>\n<h5>&#xff08;\u56db&#xff09;\u5185\u7f6e\u6d4b\u8bd5\u5de5\u5177<\/h5>\n<p>FastMCP \u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5185\u7f6e\u6d4b\u8bd5\u5de5\u5177&#xff0c;\u652f\u6301\u901a\u8fc7\u5185\u5b58\u4f20\u8f93\u76f4\u63a5\u8fde\u63a5\u5230\u00a0FastMCP\u00a0\u670d\u52a1\u5668\u5b9e\u4f8b&#xff0c;\u4ece\u800c\u5728\u6d4b\u8bd5\u8fc7\u7a0b\u4e2d\u65e0\u9700\u8fdb\u884c\u8fdb\u7a0b\u7ba1\u7406\u548c\u7f51\u7edc\u8c03\u7528\u3002\u8fd9\u79cd\u65b9\u5f0f\u6781\u5927\u5730\u63d0\u9ad8\u4e86\u6d4b\u8bd5\u6548\u7387&#xff0c;\u964d\u4f4e\u4e86\u6d4b\u8bd5\u6210\u672c\u3002<\/p>\n<h4>\u4e94\u3001\u603b\u7ed3<\/h4>\n<p>FastMCP \u4f5c\u4e3a\u4e00\u4e2a\u9ad8\u6548\u3001\u7b80\u6d01\u4e14\u529f\u80fd\u5f3a\u5927\u7684 Python \u6846\u67b6&#xff0c;\u4e3a\u6784\u5efa MCP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u63d0\u4f9b\u4e86\u6781\u5927\u7684\u4fbf\u5229\u3002\u901a\u8fc7\u5176\u7b80\u6d01\u7684 API \u8bbe\u8ba1\u3001\u9ad8\u6548\u7684\u5f00\u53d1\u4f53\u9a8c\u548c\u5f3a\u5927\u7684\u6269\u5c55\u80fd\u529b&#xff0c;\u5f00\u53d1\u8005\u53ef\u4ee5\u5feb\u901f\u6784\u5efa\u51fa\u529f\u80fd\u4e30\u5bcc\u7684 MCP \u5e94\u7528\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u5de5\u5177\u5f00\u53d1&#xff0c;\u8fd8\u662f\u590d\u6742\u7684 AI \u5e94\u7528\u6784\u5efa&#xff0c;FastMCP \u90fd\u80fd\u591f\u6ee1\u8db3\u5f00\u53d1\u8005\u7684\u9700\u6c42\u3002<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb901\u6b21\uff0c\u70b9\u8d5e8\u6b21\uff0c\u6536\u85cf20\u6b21\u3002FastMCP \u662f\u4e00\u4e2a\u7528\u4e8e\u6784\u5efa MCP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684 Python \u6846\u67b6\uff0c\u5176\u76ee\u6807\u662f\u8ba9\u5f00\u53d1\u8005\u80fd\u591f\u4ee5\u66f4\u5c11\u7684\u4ee3\u7801\u3001\u66f4\u9ad8\u7684\u6548\u7387\u6784\u5efa\u51fa\u529f\u80fd\u5f3a\u5927\u7684 MCP \u5e94\u7528\u3002\u76f8\u6bd4\u5b98\u65b9\u7684 MCP Python SDK\uff0cFastMCP \u5728\u591a\u4e2a\u65b9\u9762\u8fdb\u884c\u4e86\u4f18\u5316\u548c\u6539\u8fdb\uff0c\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u7684 API \u8bbe\u8ba1\u3001\u66f4\u9ad8\u6548\u7684\u5f00\u53d1\u4f53\u9a8c\u4ee5\u53ca\u66f4\u5f3a\u5927\u7684\u6269\u5c55\u80fd\u529b_fastmcp openai<\/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":[53,81,227,43],"topic":[],"class_list":["post-46470","post","type-post","status-publish","format-standard","hentry","category-server","tag-ai","tag-python","tag-227","tag-43"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>FastMCP\uff1a\u7528\u4e8e\u6784\u5efaMCP\u670d\u52a1\u5668\u7684\u5f00\u6e90Python\u6846\u67b6 - \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\/46470.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"FastMCP\uff1a\u7528\u4e8e\u6784\u5efaMCP\u670d\u52a1\u5668\u7684\u5f00\u6e90Python\u6846\u67b6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb901\u6b21\uff0c\u70b9\u8d5e8\u6b21\uff0c\u6536\u85cf20\u6b21\u3002FastMCP \u662f\u4e00\u4e2a\u7528\u4e8e\u6784\u5efa MCP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684 Python \u6846\u67b6\uff0c\u5176\u76ee\u6807\u662f\u8ba9\u5f00\u53d1\u8005\u80fd\u591f\u4ee5\u66f4\u5c11\u7684\u4ee3\u7801\u3001\u66f4\u9ad8\u7684\u6548\u7387\u6784\u5efa\u51fa\u529f\u80fd\u5f3a\u5927\u7684 MCP \u5e94\u7528\u3002\u76f8\u6bd4\u5b98\u65b9\u7684 MCP Python SDK\uff0cFastMCP \u5728\u591a\u4e2a\u65b9\u9762\u8fdb\u884c\u4e86\u4f18\u5316\u548c\u6539\u8fdb\uff0c\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u7684 API \u8bbe\u8ba1\u3001\u66f4\u9ad8\u6548\u7684\u5f00\u53d1\u4f53\u9a8c\u4ee5\u53ca\u66f4\u5f3a\u5927\u7684\u6269\u5c55\u80fd\u529b_fastmcp openai\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/46470.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-29T19:12:43+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=\"5 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46470.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/46470.html\",\"name\":\"FastMCP\uff1a\u7528\u4e8e\u6784\u5efaMCP\u670d\u52a1\u5668\u7684\u5f00\u6e90Python\u6846\u67b6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-29T19:12:43+00:00\",\"dateModified\":\"2025-07-29T19:12:43+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/46470.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/46470.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/46470.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"FastMCP\uff1a\u7528\u4e8e\u6784\u5efaMCP\u670d\u52a1\u5668\u7684\u5f00\u6e90Python\u6846\u67b6\"}]},{\"@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":"FastMCP\uff1a\u7528\u4e8e\u6784\u5efaMCP\u670d\u52a1\u5668\u7684\u5f00\u6e90Python\u6846\u67b6 - \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\/46470.html","og_locale":"zh_CN","og_type":"article","og_title":"FastMCP\uff1a\u7528\u4e8e\u6784\u5efaMCP\u670d\u52a1\u5668\u7684\u5f00\u6e90Python\u6846\u67b6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb901\u6b21\uff0c\u70b9\u8d5e8\u6b21\uff0c\u6536\u85cf20\u6b21\u3002FastMCP \u662f\u4e00\u4e2a\u7528\u4e8e\u6784\u5efa MCP \u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684 Python \u6846\u67b6\uff0c\u5176\u76ee\u6807\u662f\u8ba9\u5f00\u53d1\u8005\u80fd\u591f\u4ee5\u66f4\u5c11\u7684\u4ee3\u7801\u3001\u66f4\u9ad8\u7684\u6548\u7387\u6784\u5efa\u51fa\u529f\u80fd\u5f3a\u5927\u7684 MCP \u5e94\u7528\u3002\u76f8\u6bd4\u5b98\u65b9\u7684 MCP Python SDK\uff0cFastMCP \u5728\u591a\u4e2a\u65b9\u9762\u8fdb\u884c\u4e86\u4f18\u5316\u548c\u6539\u8fdb\uff0c\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u7684 API \u8bbe\u8ba1\u3001\u66f4\u9ad8\u6548\u7684\u5f00\u53d1\u4f53\u9a8c\u4ee5\u53ca\u66f4\u5f3a\u5927\u7684\u6269\u5c55\u80fd\u529b_fastmcp openai","og_url":"https:\/\/www.wsisp.com\/helps\/46470.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-29T19:12:43+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"5 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/46470.html","url":"https:\/\/www.wsisp.com\/helps\/46470.html","name":"FastMCP\uff1a\u7528\u4e8e\u6784\u5efaMCP\u670d\u52a1\u5668\u7684\u5f00\u6e90Python\u6846\u67b6 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-29T19:12:43+00:00","dateModified":"2025-07-29T19:12:43+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/46470.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/46470.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/46470.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"FastMCP\uff1a\u7528\u4e8e\u6784\u5efaMCP\u670d\u52a1\u5668\u7684\u5f00\u6e90Python\u6846\u67b6"}]},{"@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\/46470","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=46470"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/46470\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=46470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=46470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=46470"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=46470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}