{"id":37315,"date":"2025-05-15T15:16:13","date_gmt":"2025-05-15T07:16:13","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/37315.html"},"modified":"2025-05-15T15:16:13","modified_gmt":"2025-05-15T07:16:13","slug":"fastmcp-v2%ef%bc%9a%e6%9e%84%e5%bb%bamcp%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%92%8c%e5%ae%a2%e6%88%b7%e7%ab%af%e7%9a%84python%e5%88%a9%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/37315.html","title":{"rendered":"FastMCP v2\uff1a\u6784\u5efaMCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684Python\u5229\u5668"},"content":{"rendered":"<h2>FastMCP v2&#xff1a;\u6784\u5efaMCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684Python\u5229\u5668<\/h2>\n<h3>\u5f15\u8a00<\/h3>\n<p>\u5728\u4eba\u5de5\u667a\u80fd\u4e0e\u5927\u8bed\u8a00\u6a21\u578b&#xff08;LLMs&#xff09;\u7684\u5e94\u7528\u573a\u666f\u4e2d&#xff0c;\u5982\u4f55\u9ad8\u6548\u5730\u6784\u5efa\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u4ee5\u5b9e\u73b0\u6570\u636e\u4ea4\u4e92\u4e0e\u529f\u80fd\u8c03\u7528\u662f\u5173\u952e\u95ee\u9898\u3002Model Context Protocol (MCP) \u4e3a\u6b64\u63d0\u4f9b\u4e86\u4e00\u79cd\u6807\u51c6&#xff0c;\u800cFastMCP v2\u5219\u662f\u57fa\u4e8ePython\u5b9e\u73b0\u7684\u7528\u4e8e\u6784\u5efaMCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684\u5f3a\u5927\u5de5\u5177\u3002\u5b83\u5728\u539f\u6709\u7248\u672c\u57fa\u7840\u4e0a\u8fdb\u884c\u4e86\u663e\u8457\u6269\u5c55&#xff0c;\u5f15\u5165\u4e86\u4e30\u5bcc\u7684\u9ad8\u7ea7\u7279\u6027&#xff0c;\u8ba9\u5f00\u53d1\u8005\u80fd\u591f\u66f4\u8f7b\u677e\u5730\u521b\u5efa\u548c\u7ba1\u7406MCP\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<h3>\u4ec0\u4e48\u662fFastMCP v2<\/h3>\n<p>FastMCP v2\u662fFastMCP 1.0\u7684\u7ee7\u4efb\u8005&#xff0c;\u662f\u4e00\u4e2a\u4e13\u6ce8\u4e8e\u7b80\u5316MCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u5f00\u53d1\u7684Python\u5e93\u3002\u5b83\u901a\u8fc7\u7b80\u6d01\u7684Python\u63a5\u53e3\u548c\u4e30\u5bcc\u7684\u529f\u80fd\u7279\u6027&#xff0c;\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u5b9e\u73b0\u5de5\u5177\u3001\u8d44\u6e90\u3001\u63d0\u793a\u7b49\u7ec4\u4ef6\u7684\u6ce8\u518c\u4e0e\u7ba1\u7406&#xff0c;\u540c\u65f6\u652f\u6301\u670d\u52a1\u5668\u4ee3\u7406\u3001\u7ec4\u5408\u4ee5\u53ca\u4e0eOpenAPI\/FastAPI\u96c6\u6210\u7b49\u9ad8\u7ea7\u529f\u80fd\u3002<\/p>\n<h4>\u4e3b\u8981\u7279\u70b9<\/h4>\n<ul>\n<li>\u7b80\u6d01\u7684Python\u63a5\u53e3&#xff1a;\u4f7f\u7528\u88c5\u9970\u5668\u548c\u7b80\u5355\u7684\u51fd\u6570\u8c03\u7528&#xff0c;\u8ba9\u5f00\u53d1\u8005\u53ef\u4ee5\u7528\u6700\u5c11\u7684\u4ee3\u7801\u5b8c\u6210\u590d\u6742\u7684MCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u5f00\u53d1\u3002<\/li>\n<li>\u529f\u80fd\u4e30\u5bcc&#xff1a;\u652f\u6301\u5de5\u5177\u3001\u8d44\u6e90\u3001\u6a21\u677f\u3001\u63d0\u793a\u3001\u4e0a\u4e0b\u6587\u7b49\u6838\u5fc3\u6982\u5ff5&#xff0c;\u6ee1\u8db3\u5404\u79cd\u5e94\u7528\u573a\u666f\u9700\u6c42\u3002<\/li>\n<li>\u9ad8\u7ea7\u7279\u6027&#xff1a;\u5305\u62ec\u670d\u52a1\u5668\u4ee3\u7406\u3001\u670d\u52a1\u5668\u7ec4\u5408\u3001OpenAPI\/FastAPI\u96c6\u6210\u7b49&#xff0c;\u65b9\u4fbf\u4e0e\u73b0\u6709\u7cfb\u7edf\u96c6\u6210\u3002<\/li>\n<\/ul>\n<h3>\u5b89\u88c5<\/h3>\n<p>\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u4f7f\u7528pip\u5b89\u88c5FastMCP&#xff1a;<\/p>\n<p>pip <span class=\"token function\">install<\/span> fastmcp<\/p>\n<h3>\u6838\u5fc3\u529f\u80fd\u53ca\u7528\u9014<\/h3>\n<h4>1. \u5de5\u5177&#xff08;Tools&#xff09;<\/h4>\n<p>\u5de5\u5177\u662fFastMCP\u4e2d\u7528\u4e8e\u6267\u884c\u7279\u5b9a\u4efb\u52a1\u7684\u53ef\u8c03\u7528\u51fd\u6570&#xff0c;\u7c7b\u4f3c\u4e8eHTTP\u7684 POST\/PUT \u8bf7\u6c42\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d&#xff0c;\u5de5\u5177\u53ef\u4ee5\u7528\u4e8e\u6570\u636e\u5904\u7406\u3001\u6a21\u578b\u8c03\u7528\u3001\u6587\u4ef6\u64cd\u4f5c\u7b49\u5404\u79cd\u4efb\u52a1\u3002<\/p>\n<h5>\u5de5\u5177\u6ce8\u518c<\/h5>\n<p>\u53ef\u4ee5\u901a\u8fc7 &#064;mcp.tool() \u88c5\u9970\u5668\u5c06\u4e00\u4e2a\u51fd\u6570\u6ce8\u518c\u4e3a\u5de5\u5177\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> fastmcp <span class=\"token keyword\">import<\/span> FastMCP<\/p>\n<p>mcp <span class=\"token operator\">&#061;<\/span> FastMCP<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Demo &#x1f680;&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token decorator annotation punctuation\">&#064;mcp<span class=\"token punctuation\">.<\/span>tool<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">add<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">,<\/span> b<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;Add two numbers&#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> a <span class=\"token operator\">&#043;<\/span> b<\/p>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d&#xff0c;add \u51fd\u6570\u88ab\u6ce8\u518c\u4e3a\u4e00\u4e2a\u5de5\u5177&#xff0c;\u7528\u4e8e\u5c06\u4e24\u4e2a\u6574\u6570\u76f8\u52a0\u3002\u5de5\u5177\u7684\u6587\u6863\u5b57\u7b26\u4e32\u4f1a\u88ab\u7528\u4f5c\u5de5\u5177\u7684\u63cf\u8ff0&#xff0c;\u65b9\u4fbf\u5176\u4ed6\u5f00\u53d1\u8005\u7406\u89e3\u5de5\u5177\u7684\u7528\u9014\u3002<\/p>\n<h5>\u5de5\u5177\u8c03\u7528<\/h5>\n<p>\u5728\u5ba2\u6237\u7aef\u53ef\u4ee5\u901a\u8fc7 Client \u7c7b\u8c03\u7528\u6ce8\u518c\u7684\u5de5\u5177\u3002\u793a\u4f8b\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> fastmcp<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>client <span class=\"token keyword\">import<\/span> Client<br \/>\n<span class=\"token keyword\">from<\/span> mcp<span class=\"token punctuation\">.<\/span>types <span class=\"token keyword\">import<\/span> TextContent<\/p>\n<p><span class=\"token keyword\">async<\/span> <span class=\"token keyword\">def<\/span> <span class=\"token function\">test_call_tool<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">async<\/span> <span class=\"token keyword\">with<\/span> Client<span class=\"token punctuation\">(<\/span>mcp<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> client<span class=\"token punctuation\">:<\/span><br \/>\n        result <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> client<span class=\"token punctuation\">.<\/span>call_tool<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;add&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;a&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;b&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">assert<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n        <span class=\"token keyword\">assert<\/span> <span class=\"token builtin\">isinstance<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> TextContent<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">assert<\/span> result<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span>text <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#034;3&#034;<\/span><\/p>\n<h4>2. \u8d44\u6e90\u4e0e\u6a21\u677f&#xff08;Resources &amp; Templates&#xff09;<\/h4>\n<p>\u8d44\u6e90\u7c7b\u4f3c\u4e8eHTTP\u7684 GET \u8bf7\u6c42&#xff0c;\u7528\u4e8e\u52a0\u8f7d\u4fe1\u606f\u5230\u4e0a\u4e0b\u6587\u3002\u6a21\u677f\u5219\u662f\u7528\u4e8e\u52a8\u6001\u751f\u6210\u8d44\u6e90\u7684\u4e00\u79cd\u673a\u5236\u3002\u8d44\u6e90\u53ef\u4ee5\u662f\u6587\u4ef6\u5185\u5bb9\u3001\u6570\u636e\u5e93\u67e5\u8be2\u7ed3\u679c\u7b49\u3002<\/p>\n<h5>\u8d44\u6e90\u6ce8\u518c<\/h5>\n<p>\u53ef\u4ee5\u901a\u8fc7 &#064;mcp.resource() \u88c5\u9970\u5668\u5c06\u4e00\u4e2a\u51fd\u6570\u6ce8\u518c\u4e3a\u8d44\u6e90\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> fastmcp <span class=\"token keyword\">import<\/span> FastMCP<br \/>\n<span class=\"token keyword\">from<\/span> pathlib <span class=\"token keyword\">import<\/span> Path<\/p>\n<p>mcp <span class=\"token operator\">&#061;<\/span> FastMCP<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Demo &#x1f680;&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\ntest_dir <span class=\"token operator\">&#061;<\/span> Path<span class=\"token punctuation\">(<\/span>__file__<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>parent<\/p>\n<p><span class=\"token decorator annotation punctuation\">&#064;mcp<span class=\"token punctuation\">.<\/span>resource<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;file:\/\/test_dir\/config.json&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">read_config_json<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;Read the config.json file&#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token punctuation\">(<\/span>test_dir <span class=\"token operator\">\/<\/span> <span class=\"token string\">&#034;config.json&#034;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>read_text<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">except<\/span> FileNotFoundError<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;File not found&#034;<\/span><\/p>\n<p>\u8fd9\u4e2a\u4f8b\u5b50\u4e2d&#xff0c;read_config_json \u51fd\u6570\u88ab\u6ce8\u518c\u4e3a\u4e00\u4e2a\u8d44\u6e90&#xff0c;\u7528\u4e8e\u8bfb\u53d6 config.json \u6587\u4ef6\u7684\u5185\u5bb9\u3002<\/p>\n<h5>\u8d44\u6e90\u8bfb\u53d6<\/h5>\n<p>\u5728\u5ba2\u6237\u7aef\u53ef\u4ee5\u901a\u8fc7 Client \u7c7b\u8bfb\u53d6\u6ce8\u518c\u7684\u8d44\u6e90\u3002\u793a\u4f8b\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> fastmcp<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>client <span class=\"token keyword\">import<\/span> Client<br \/>\n<span class=\"token keyword\">from<\/span> mcp<span class=\"token punctuation\">.<\/span>types <span class=\"token keyword\">import<\/span> TextResourceContents<\/p>\n<p><span class=\"token keyword\">async<\/span> <span class=\"token keyword\">def<\/span> <span class=\"token function\">test_read_resource<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">async<\/span> <span class=\"token keyword\">with<\/span> Client<span class=\"token punctuation\">(<\/span>mcp<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> client<span class=\"token punctuation\">:<\/span><br \/>\n        result <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> client<span class=\"token punctuation\">.<\/span>read_resource<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;file:\/\/test_dir\/config.json&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">assert<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n        <span class=\"token keyword\">assert<\/span> <span class=\"token builtin\">isinstance<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> TextResourceContents<span class=\"token punctuation\">)<\/span><\/p>\n<h4>3. \u63d0\u793a&#xff08;Prompts&#xff09;<\/h4>\n<p>\u63d0\u793a\u662f\u53ef\u91cd\u7528\u7684\u6a21\u677f&#xff0c;\u7528\u4e8e\u5b9a\u4e49\u4e0eLLM\u7684\u4ea4\u4e92\u6a21\u5f0f\u3002\u5728\u4e0e\u5927\u8bed\u8a00\u6a21\u578b\u4ea4\u4e92\u65f6&#xff0c;\u63d0\u793a\u53ef\u4ee5\u5e2e\u52a9\u5f15\u5bfc\u6a21\u578b\u751f\u6210\u66f4\u7b26\u5408\u9884\u671f\u7684\u7ed3\u679c\u3002<\/p>\n<h5>\u63d0\u793a\u6ce8\u518c<\/h5>\n<p>\u53ef\u4ee5\u901a\u8fc7 &#064;mcp.prompt() \u88c5\u9970\u5668\u5c06\u4e00\u4e2a\u51fd\u6570\u6ce8\u518c\u4e3a\u63d0\u793a\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> fastmcp <span class=\"token keyword\">import<\/span> FastMCP<\/p>\n<p>mcp <span class=\"token operator\">&#061;<\/span> FastMCP<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Demo &#x1f680;&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token decorator annotation punctuation\">&#064;mcp<span class=\"token punctuation\">.<\/span>prompt<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">def<\/span> <span class=\"token function\">explain_sql<\/span><span class=\"token punctuation\">(<\/span>query<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Explaining SQL query:\\\\n<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>query<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><\/p>\n<p>\u8fd9\u91cc&#xff0c;explain_sql \u51fd\u6570\u88ab\u6ce8\u518c\u4e3a\u4e00\u4e2a\u63d0\u793a&#xff0c;\u7528\u4e8e\u89e3\u91caSQL\u67e5\u8be2\u3002<\/p>\n<h5>\u63d0\u793a\u4f7f\u7528<\/h5>\n<p>\u5728\u5ba2\u6237\u7aef\u53ef\u4ee5\u901a\u8fc7 Client \u7c7b\u83b7\u53d6\u6ce8\u518c\u7684\u63d0\u793a\u3002\u793a\u4f8b\u5982\u4e0b&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> fastmcp<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>client <span class=\"token keyword\">import<\/span> Client<\/p>\n<p><span class=\"token keyword\">async<\/span> <span class=\"token keyword\">def<\/span> <span class=\"token function\">test_get_prompt<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">async<\/span> <span class=\"token keyword\">with<\/span> Client<span class=\"token punctuation\">(<\/span>mcp<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> client<span class=\"token punctuation\">:<\/span><br \/>\n        result <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> client<span class=\"token punctuation\">.<\/span>get_prompt<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;explain_sql&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;query&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;SELECT * FROM users&#034;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">assert<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">.<\/span>messages<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">1<\/span><\/p>\n<h4>4. \u4e0a\u4e0b\u6587&#xff08;Context&#xff09;<\/h4>\n<p>\u4e0a\u4e0b\u6587\u63d0\u4f9b\u4e86\u5728\u5de5\u5177\u6267\u884c\u8fc7\u7a0b\u4e2d\u5171\u4eab\u4fe1\u606f\u7684\u673a\u5236\u3002\u53ef\u4ee5\u901a\u8fc7 get_context() \u51fd\u6570\u83b7\u53d6\u5f53\u524d\u4e0a\u4e0b\u6587\u3002\u4f8b\u5982&#xff0c;\u5728\u5de5\u5177\u6267\u884c\u8fc7\u7a0b\u4e2d\u8bb0\u5f55\u65e5\u5fd7&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> fastmcp <span class=\"token keyword\">import<\/span> FastMCP<br \/>\n<span class=\"token keyword\">from<\/span> fastmcp<span class=\"token punctuation\">.<\/span>server<span class=\"token punctuation\">.<\/span>context <span class=\"token keyword\">import<\/span> get_context<\/p>\n<p>mcp <span class=\"token operator\">&#061;<\/span> FastMCP<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Demo &#x1f680;&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token decorator annotation punctuation\">&#064;mcp<span class=\"token punctuation\">.<\/span>tool<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">async<\/span> <span class=\"token keyword\">def<\/span> <span class=\"token function\">some_tool<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    context <span class=\"token operator\">&#061;<\/span> get_context<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">await<\/span> context<span class=\"token punctuation\">.<\/span>info<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Tool execution started&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u5de5\u5177\u903b\u8f91<\/span><br \/>\n    <span class=\"token keyword\">await<\/span> context<span class=\"token punctuation\">.<\/span>info<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Tool execution finished&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;Tool result&#034;<\/span><\/p>\n<h4>5. MCP\u5ba2\u6237\u7aef<\/h4>\n<p>FastMCP v2\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5ba2\u6237\u7aef\u529f\u80fd&#xff0c;\u7528\u4e8e\u4e0eMCP\u670d\u52a1\u5668\u8fdb\u884c\u4ea4\u4e92\u3002\u5ba2\u6237\u7aef\u53ef\u4ee5\u8c03\u7528\u670d\u52a1\u5668\u4e0a\u6ce8\u518c\u7684\u5de5\u5177\u3001\u8bfb\u53d6\u8d44\u6e90\u3001\u83b7\u53d6\u63d0\u793a\u7b49\u3002<\/p>\n<h5>\u5ba2\u6237\u7aef\u4f7f\u7528\u793a\u4f8b<\/h5>\n<p><span class=\"token keyword\">from<\/span> fastmcp<span class=\"token punctuation\">.<\/span>client<span class=\"token punctuation\">.<\/span>client <span class=\"token keyword\">import<\/span> Client<br \/>\n<span class=\"token keyword\">from<\/span> fastmcp <span class=\"token keyword\">import<\/span> FastMCP<br \/>\n<span class=\"token keyword\">from<\/span> mcp<span class=\"token punctuation\">.<\/span>types <span class=\"token keyword\">import<\/span> TextContent<\/p>\n<p><span class=\"token keyword\">async<\/span> <span class=\"token keyword\">def<\/span> <span class=\"token function\">test_client<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    mcp <span class=\"token operator\">&#061;<\/span> FastMCP<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;Demo &#x1f680;&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token decorator annotation punctuation\">&#064;mcp<span class=\"token punctuation\">.<\/span>tool<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">def<\/span> <span class=\"token function\">add<\/span><span class=\"token punctuation\">(<\/span>a<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">,<\/span> b<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">int<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;Add two numbers&#034;&#034;&#034;<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> a <span class=\"token operator\">&#043;<\/span> b<\/p>\n<p>    <span class=\"token keyword\">async<\/span> <span class=\"token keyword\">with<\/span> Client<span class=\"token punctuation\">(<\/span>mcp<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> client<span class=\"token punctuation\">:<\/span><br \/>\n        result <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> client<span class=\"token punctuation\">.<\/span>call_tool<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;add&#034;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token punctuation\">{<\/span><span class=\"token string\">&#034;a&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#034;b&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">assert<\/span> <span class=\"token builtin\">len<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token number\">1<\/span><br \/>\n        <span class=\"token keyword\">assert<\/span> <span class=\"token builtin\">isinstance<\/span><span class=\"token punctuation\">(<\/span>result<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">,<\/span> TextContent<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">assert<\/span> result<span class=\"token punctuation\">[<\/span><span class=\"token number\">0<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">.<\/span>text <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#034;3&#034;<\/span><\/p>\n<h3>\u9ad8\u7ea7\u7279\u6027<\/h3>\n<h4>1. \u4ee3\u7406\u670d\u52a1\u5668&#xff08;Proxy Servers&#xff09;<\/h4>\n<p>FastMCP\u652f\u6301\u4ee3\u7406\u670d\u52a1\u5668\u529f\u80fd&#xff0c;\u5141\u8bb8\u5c06\u8bf7\u6c42\u8f6c\u53d1\u5230\u5176\u4ed6MCP\u670d\u52a1\u5668\u3002\u8fd9\u5728\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\u975e\u5e38\u6709\u7528&#xff0c;\u53ef\u4ee5\u5b9e\u73b0\u8d1f\u8f7d\u5747\u8861\u548c\u670d\u52a1\u62c6\u5206\u3002<\/p>\n<h4>2. \u7ec4\u5408MCP\u670d\u52a1\u5668&#xff08;Composing MCP Servers&#xff09;<\/h4>\n<p>\u53ef\u4ee5\u5c06\u591a\u4e2aMCP\u670d\u52a1\u5668\u7ec4\u5408\u5728\u4e00\u8d77&#xff0c;\u5f62\u6210\u4e00\u4e2a\u66f4\u5927\u7684\u670d\u52a1\u5668\u3002\u4f8b\u5982&#xff1a;<\/p>\n<p><span class=\"token keyword\">from<\/span> fastmcp <span class=\"token keyword\">import<\/span> FastMCP<\/p>\n<p>main_app <span class=\"token operator\">&#061;<\/span> FastMCP<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;MainApp&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\napi_app <span class=\"token operator\">&#061;<\/span> FastMCP<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;APIApp&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">fetch_data<\/span><span class=\"token punctuation\">(<\/span>query<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token operator\">&gt;<\/span> <span class=\"token builtin\">str<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;Data for query: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>query<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><\/p>\n<p>api_app<span class=\"token punctuation\">.<\/span>add_tool<span class=\"token punctuation\">(<\/span>fetch_data<span class=\"token punctuation\">,<\/span> name<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#034;get_data&#034;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">await<\/span> main_app<span class=\"token punctuation\">.<\/span>import_server<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;api&#034;<\/span><span class=\"token punctuation\">,<\/span> api_app<span class=\"token punctuation\">)<\/span><\/p>\n<h4>3. OpenAPI &amp; FastAPI \u751f\u6210<\/h4>\n<p>FastMCP\u652f\u6301\u4e0eOpenAPI\u548cFastAPI\u96c6\u6210&#xff0c;\u53ef\u4ee5\u81ea\u52a8\u751f\u6210API\u6587\u6863\u548c\u63a5\u53e3\u3002\u8fd9\u4f7f\u5f97\u5f00\u53d1\u8005\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06MCP\u670d\u52a1\u5668\u96c6\u6210\u5230\u73b0\u6709\u7684Web\u5e94\u7528\u4e2d\u3002<\/p>\n<h3>\u8fd0\u884c\u670d\u52a1\u5668<\/h3>\n<p>\u5728\u7f16\u5199\u597d\u670d\u52a1\u5668\u4ee3\u7801\u540e&#xff0c;\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\u670d\u52a1\u5668&#xff1a;<\/p>\n<p>fastmcp run server.py<\/p>\n<h3>\u603b\u7ed3<\/h3>\n<p>FastMCP v2\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u3001\u6613\u4e8e\u4f7f\u7528\u7684Python\u5e93&#xff0c;\u4e3a\u6784\u5efaMCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u548c\u7b80\u6d01\u7684\u63a5\u53e3\u3002\u901a\u8fc7\u672c\u6587\u7684\u8be6\u7ec6\u4ecb\u7ecd\u548c\u4ee3\u7801\u793a\u4f8b&#xff0c;\u4f60\u5e94\u8be5\u5bf9FastMCP v2\u7684\u6838\u5fc3\u6982\u5ff5\u3001\u529f\u80fd\u7528\u9014\u548c\u4f7f\u7528\u65b9\u6cd5\u6709\u4e86\u66f4\u6df1\u5165\u7684\u4e86\u89e3\u3002\u5e0c\u671b\u4f60\u80fd\u5229\u7528FastMCP v2\u6784\u5efa\u51fa\u66f4\u52a0\u9ad8\u6548\u3001\u5f3a\u5927\u7684MCP\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f&#xff0c;\u8bf7\u53c2\u8003FastMCP\u7684\u5b98\u65b9\u6587\u6863&#xff1a;gofastmcp.com\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb743\u6b21\uff0c\u70b9\u8d5e26\u6b21\uff0c\u6536\u85cf20\u6b21\u3002FastMCP v2\u662fFastMCP 1.0\u7684\u7ee7\u4efb\u8005\uff0c\u662f\u4e00\u4e2a\u4e13\u6ce8\u4e8e\u7b80\u5316MCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u5f00\u53d1\u7684Python\u5e93\u3002\u5b83\u901a\u8fc7\u7b80\u6d01\u7684Python\u63a5\u53e3\u548c\u4e30\u5bcc\u7684\u529f\u80fd\u7279\u6027\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u5b9e\u73b0\u5de5\u5177\u3001\u8d44\u6e90\u3001\u63d0\u793a\u7b49\u7ec4\u4ef6\u7684\u6ce8\u518c\u4e0e\u7ba1\u7406\uff0c\u540c\u65f6\u652f\u6301\u670d\u52a1\u5668\u4ee3\u7406\u3001\u7ec4\u5408\u4ee5\u53ca\u4e0eOpenAPI\/FastAPI\u96c6\u6210\u7b49\u9ad8\u7ea7\u529f\u80fd\u3002<\/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":[81,43,3224,44],"topic":[],"class_list":["post-37315","post","type-post","status-publish","format-standard","hentry","category-server","tag-python","tag-43","tag-3224","tag-44"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>FastMCP v2\uff1a\u6784\u5efaMCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684Python\u5229\u5668 - \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\/37315.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"FastMCP v2\uff1a\u6784\u5efaMCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684Python\u5229\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb743\u6b21\uff0c\u70b9\u8d5e26\u6b21\uff0c\u6536\u85cf20\u6b21\u3002FastMCP v2\u662fFastMCP 1.0\u7684\u7ee7\u4efb\u8005\uff0c\u662f\u4e00\u4e2a\u4e13\u6ce8\u4e8e\u7b80\u5316MCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u5f00\u53d1\u7684Python\u5e93\u3002\u5b83\u901a\u8fc7\u7b80\u6d01\u7684Python\u63a5\u53e3\u548c\u4e30\u5bcc\u7684\u529f\u80fd\u7279\u6027\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u5b9e\u73b0\u5de5\u5177\u3001\u8d44\u6e90\u3001\u63d0\u793a\u7b49\u7ec4\u4ef6\u7684\u6ce8\u518c\u4e0e\u7ba1\u7406\uff0c\u540c\u65f6\u652f\u6301\u670d\u52a1\u5668\u4ee3\u7406\u3001\u7ec4\u5408\u4ee5\u53ca\u4e0eOpenAPI\/FastAPI\u96c6\u6210\u7b49\u9ad8\u7ea7\u529f\u80fd\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/37315.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-15T07:16:13+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=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/37315.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/37315.html\",\"name\":\"FastMCP v2\uff1a\u6784\u5efaMCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684Python\u5229\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-15T07:16:13+00:00\",\"dateModified\":\"2025-05-15T07:16:13+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/37315.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/37315.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/37315.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"FastMCP v2\uff1a\u6784\u5efaMCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684Python\u5229\u5668\"}]},{\"@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 v2\uff1a\u6784\u5efaMCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684Python\u5229\u5668 - \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\/37315.html","og_locale":"zh_CN","og_type":"article","og_title":"FastMCP v2\uff1a\u6784\u5efaMCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684Python\u5229\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb743\u6b21\uff0c\u70b9\u8d5e26\u6b21\uff0c\u6536\u85cf20\u6b21\u3002FastMCP v2\u662fFastMCP 1.0\u7684\u7ee7\u4efb\u8005\uff0c\u662f\u4e00\u4e2a\u4e13\u6ce8\u4e8e\u7b80\u5316MCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u5f00\u53d1\u7684Python\u5e93\u3002\u5b83\u901a\u8fc7\u7b80\u6d01\u7684Python\u63a5\u53e3\u548c\u4e30\u5bcc\u7684\u529f\u80fd\u7279\u6027\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u5b9e\u73b0\u5de5\u5177\u3001\u8d44\u6e90\u3001\u63d0\u793a\u7b49\u7ec4\u4ef6\u7684\u6ce8\u518c\u4e0e\u7ba1\u7406\uff0c\u540c\u65f6\u652f\u6301\u670d\u52a1\u5668\u4ee3\u7406\u3001\u7ec4\u5408\u4ee5\u53ca\u4e0eOpenAPI\/FastAPI\u96c6\u6210\u7b49\u9ad8\u7ea7\u529f\u80fd\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/37315.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-15T07:16:13+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/37315.html","url":"https:\/\/www.wsisp.com\/helps\/37315.html","name":"FastMCP v2\uff1a\u6784\u5efaMCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684Python\u5229\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-15T07:16:13+00:00","dateModified":"2025-05-15T07:16:13+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/37315.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/37315.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/37315.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"FastMCP v2\uff1a\u6784\u5efaMCP\u670d\u52a1\u5668\u548c\u5ba2\u6237\u7aef\u7684Python\u5229\u5668"}]},{"@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\/37315","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=37315"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/37315\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=37315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=37315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=37315"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=37315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}