{"id":37648,"date":"2025-05-16T17:11:22","date_gmt":"2025-05-16T09:11:22","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/37648.html"},"modified":"2025-05-16T17:11:22","modified_gmt":"2025-05-16T09:11:22","slug":"%e4%b8%80%e6%96%87%e8%af%bb%e6%87%82%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8mcp%e5%88%9b%e5%bb%ba%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/37648.html","title":{"rendered":"\u4e00\u6587\u8bfb\u61c2\u5982\u4f55\u4f7f\u7528MCP\u521b\u5efa\u670d\u52a1\u5668"},"content":{"rendered":"<p>\u5982\u679c\u4f60\u5bf9MCP&#xff08;\u6a21\u578b\u4e0a\u4e0b\u6587\u534f\u8bae&#xff09;\u4e00\u7a8d\u4e0d\u901a&#xff0c;\u5728\u9605\u8bfb\u672c\u7bc7\u6587\u7ae0\u4e4b\u524d&#xff08;\u5728\u83b7\u5f97\u5bf9MCP\u6df1\u5ea6\u8ba4\u8bc6\u4e4b\u524d&#xff09;&#xff0c;\u4f60\u53ef\u4ee5\u7406\u89e3\u4e3a\u5b66\u4e60MCP\u5c31\u662f\u5728\u5b66\u4e60\u4e00\u4e2apython\u5de5\u5177\u5e93mcp&#xff0c;\u7c7b\u4f3c\u4e8e\u5176\u5b83python\u5de5\u5177\u5e93\u4e00\u6837&#xff0c;\u5982numpy\u3001sys\u3001opencv\u7b49&#xff0c;\u4f60\u9700\u8981\u5148\u5b89\u88c5mcp&#xff0c;\u5b66\u4e60mcp\u7684\u4e24\u4e2a\u6838\u5fc3\u529f\u80fd&#xff0c;\u4e00\u4e2a\u662f\u4f7f\u7528mcp\u6765\u521b\u5efamcp \u670d\u52a1\u5668&#xff0c;\u53e6\u4e00\u4e2a\u662f\u4f7f\u7528mcp\u6765\u521b\u5efamcp \u5ba2\u6237\u7aef\u3002\u8bf7\u6ce8\u610f&#xff0c;\u8bf7\u6ce8\u610f&#xff0c;\u8bf7\u6ce8\u610f&#xff0c;\u5728\u5f00\u6e90\u793e\u533a\u4e2d&#xff0c;\u5df2\u7ecf\u6709\u5f88\u591amcp\u670d\u52a1\u5668\u548cmcp\u5ba2\u6237\u7aef\u53ef\u7528\u4e86&#xff0c;\u53ef\u4ee5\u6309\u9700\u9009\u62e9&#xff1b;\u5f53\u7136&#xff0c;\u5982\u679c\u4f60\u6700\u540e\u53d1\u73b0\u6ca1\u6709\u4f60\u6240\u9700\u8981\u7684mcp\u670d\u52a1\u5668\u6216\u8005mcp\u5ba2\u6237\u7aef&#xff0c;\u4f60\u518d\u8fdb\u884c\u81ea\u5df1\u521b\u5efa<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091115-682701331b294.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091115-6827013375903.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u6240\u4ee5\u53c2\u8003\u8d44\u6599\u6765\u6e90\u4e8eMCP\u5b98\u65b9\u4ecb\u7ecd\u6587\u6863<\/p>\n<\/p>\n<h4>\u6587\u7ae0\u76ee\u5f55<\/h4>\n<ul>\n<li>\u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981MCP&#xff1f;<\/li>\n<li>\u4e8c\u3001\u4ec0\u4e48\u662fMCP&#xff1f;<\/li>\n<li>\u4e09\u3001\u5f00\u53d1\u8005\u5982\u4f55\u5f00\u53d1MCP\u670d\u52a1\u5668&#xff1f;<\/li>\n<li>\n<ul>\n<li>\u73b0\u6210\u7684MCP servers<\/li>\n<li>\u5f00\u53d1\u81ea\u5df1\u7684MCP servers<\/li>\n<li>\n<ul>\n<li>\u6211\u4eec\u5c06\u8981\u6784\u5efa\u7684\u5185\u5bb9<\/li>\n<li>\u6784\u5efa\u4f60\u7684\u670d\u52a1\u5668<\/li>\n<li>\n<ul>\n<li>\u914d\u7f6e\u73af\u5883<\/li>\n<li>\u5bfc\u5165\u5305\u5e76\u8bbe\u7f6e\u5b9e\u4f8b<\/li>\n<li>\u8f85\u52a9\u51fd\u6570<\/li>\n<li>\u5b9e\u65bd\u5de5\u5177\u6267\u884c<\/li>\n<li>\u8fd0\u884c\u670d\u52a1\u5668<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<li>\u4f7f\u7528 Claude \u684c\u9762\u8f6f\u4ef6\u5ba2\u6237\u7aef \u6d4b\u8bd5\u670d\u52a1\u5668<\/li>\n<li>\n<ul>\n<li>\u6dfb\u52a0\u670d\u52a1<\/li>\n<li>\u5224\u65ad\u670d\u52a1\u662f\u5426\u6dfb\u52a0\u6210\u529f<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u4e00\u3001\u4e3a\u4ec0\u4e48\u9700\u8981MCP&#xff1f;<\/h2>\n<p>\u8bbe\u60f3\u4e00\u4e2a\u573a\u666f&#xff0c;\u4f60\u73b0\u5728\u6709\u5f88\u591a\u5de5\u5177&#xff0c;\u9700\u8981\u8c03\u7528\u8fd9\u4e9b\u5de5\u5177&#xff0c;\u5e76\u4e14\u5c06\u5de5\u5177\u54cd\u5e94\u7ed3\u679c\u62fc\u63a5\u5230\u63d0\u793a\u8bcd\u4e2d&#xff0c;\u5c06\u63d0\u793a\u8bcd\u8f93\u5165\u7ed9\u5927\u6a21\u578b&#xff0c;\u5927\u6a21\u578b\u8fd4\u56de\u7ed3\u679c\u3002\u5f88\u660e\u663e&#xff0c;\u666e\u901a\u7684python API\u5b8c\u5168\u53ef\u4ee5\u5b9e\u73b0\u8fd9\u4e2a\u6d41\u7a0b\u3002\u4f46\u662f&#xff0c;\u51e0\u4e4e\u6bcf\u4e2a\u5de5\u5177&#xff0c;\u4f60\u90fd\u9700\u8981\u5199\u4e00\u4e2a\u7279\u5b9a\u8c03\u7528\u5927\u6a21\u578b\u7684\u4e0a\u8ff0\u6d41\u7a0b&#xff08;\u56e0\u4e3a\u6bcf\u4e2a\u5de5\u5177\u7684\u8fd4\u56de\u7ed3\u679c\u4e0d\u540c&#xff09;\u3002\u8fd9\u5c31\u5f88\u4f4e\u6548\u3002<\/p>\n<p>\u73b0\u5728\u6709\u4e00\u4e2a\u6587\u4ef6\u7cfb\u7edf\u670d\u52a1&#xff0c;\u8be5\u670d\u52a1\u63d0\u4f9b\u4ee5\u4e0b\u5de5\u5177&#xff1a;\u79fb\u52a8\u6587\u4ef6\u3001\u590d\u5236\u6587\u4ef6\u3001\u5220\u9664\u6587\u4ef6\u3001\u65b0\u5efa\u6587\u4ef6\u3001\u6587\u4ef6\u91cd\u547d\u540d\u3002mcp\u7684\u51fa\u73b0\u53ef\u4ee5\u7edf\u4e00\u4e0d\u540c\u5de5\u5177\u548c\u5927\u6a21\u578b\u7684\u4ea4\u4e92\u65b9\u5f0f\u3002&#xff08;\u5982\u4f55\u7edf\u4e00\u4ea4\u4e92\u65b9\u5f0f\u8bf7\u8010\u5fc3\u5f80\u4e0b\u9605\u8bfb&#xff09;<\/p>\n<p>\u73b0\u5728\u8fd8\u51fa\u73b0\u4e86\u53e6\u4e00\u4e2a\u670d\u52a1\u53eb\u6d4f\u89c8\u5668\u670d\u52a1&#xff0c;\u8be5\u670d\u52a1\u63d0\u4f9b\u4ee5\u4e0b\u5de5\u5177&#xff1a;\u6253\u5f00\u7f51\u9875\u3001\u4e0b\u8f7d\u6587\u4ef6\u3002mcp\u7684\u51fa\u73b0\u53ef\u4ee5\u7edf\u4e00\u4e0d\u540c\u670d\u52a1\u4e0d\u540c\u5de5\u5177\u548c\u5927\u6a21\u578b\u7684\u4ea4\u4e92\u65b9\u5f0f\u3002<\/p>\n<p>\u73b0\u5728\u8fd8\u6709\u4e00\u4e2a\u670d\u52a1\u53ebPostgreSQL \u670d\u52a1&#xff0c;\u8be5\u670d\u52a1\u63d0\u4f9b\u4ee5\u4e0b\u5de5\u5177&#xff1a;\u67e5\u8be2\u6570\u636e\u3001\u5220\u9664\u6570\u636e\u3001\u65b0\u589e\u6570\u636e\u3001\u66f4\u6539\u6570\u636e\u3002mvp\u7684\u51fa\u73b0\u53ef\u4ee5\u7edf\u4e00\u4e0d\u540c\u670d\u52a1\u4e0d\u540c\u6570\u636e\u6e90\u548c\u5927\u6a21\u578b\u7684\u4ea4\u4e92\u65b9\u5f0f<\/p>\n<p>\u8bf4\u5f97\u6982\u62ec\u6027\u4e00\u4e9b&#xff1a;<\/p>\n<p>\u6570\u636e\u4e0e\u5de5\u5177\u672c\u8eab\u662f\u5ba2\u89c2\u5b58\u5728\u7684&#xff0c;\u53ea\u4e0d\u8fc7\u6211\u4eec\u5e0c\u671b\u5c06\u6570\u636e\u8fde\u63a5\u5230\u6a21\u578b\u7684\u8fd9\u4e2a\u73af\u8282\u53ef\u4ee5\u66f4\u667a\u80fd\u66f4\u7edf\u4e00\u3002Anthropic\u516c\u53f8 \u57fa\u4e8e\u8fd9\u6837\u7684\u75db\u70b9\u8bbe\u8ba1\u4e86 MCP&#xff0c;\u5145\u5f53 AI \u6a21\u578b\u7684&#034;\u4e07\u80fd\u8f6c\u63a5\u5934&#034;&#xff0c;\u8ba9 LLM \u80fd\u8f7b\u677e\u7684\u83b7\u53d6\u6570\u636e\u6216\u8005\u8c03\u7528\u5de5\u5177\u3002<\/p>\n<h2>\u4e8c\u3001\u4ec0\u4e48\u662fMCP&#xff1f;<\/h2>\n<p>MCP\u7684\u5b9a\u4e49\u5f88\u7b80\u5355&#xff1a;<\/p>\n<p>MCP \u662f\u4e00\u4e2a\u5f00\u653e\u534f\u8bae&#xff0c;\u5b83\u6807\u51c6\u5316\u4e86\u5e94\u7528\u7a0b\u5e8f\u5982\u4f55\u5411 LLM \u63d0\u4f9b\u4e0a\u4e0b\u6587\u3002<\/p>\n<p>\u5982\u4f55\u7406\u89e3\u8fd9\u4e2a\u6982\u5ff5\u5462&#xff1f;\u5b98\u65b9\u7ed9\u51fa\u4e86USB-C\u7684\u4f8b\u5b50&#xff0c;\u4e0b\u9762\u4ee5\u7535\u8111\u8fde\u63a5\u786c\u76d8\u4e3a\u4f8b\u5b50\u8fdb\u884c\u7c7b\u6bd4\u3002<\/p>\n<p>\u7535\u8111\u53ef\u4ee5\u901a\u8fc7\u7535\u8111\u4e0a\u9762\u7684USB-C\u63a5\u53e3\u3001USB-C\u7ebf\u53bb\u5b9e\u73b0\u8fde\u63a5\u786c\u76d8\u3001\u8bfb\u53d6\u6570\u636e\u7684\u529f\u80fd\u3002\u8fd9\u91cc\u7684\u7535\u8111\u5c31\u662fMCP\u4e2d\u7684mcp \u5ba2\u6237\u7aef\u7684\u6982\u5ff5&#xff0c;\u786c\u76d8\u5c31\u662fmcp \u670d\u52a1\u5668\u7684\u6982\u5ff5\u3002\u6709\u4e9b\u786c\u76d8\u53ea\u80fd\u652f\u6301USB-B\u63a5\u53e3&#xff0c;\u90a3\u4e48\u4f60\u5c31\u9700\u8981\u4e00\u4e2a\u63a5\u53e3\u8f6c\u6362\u5668&#xff0c;\u5c06USB-B\u8f6c\u6362\u6210USB-C\u63a5\u53e3\u624d\u80fd\u8ba9\u786c\u76d8\u548c\u7535\u8111\u8fdb\u884c\u8fde\u63a5\u3002\u6700\u540e\u7684\u7ed3\u679c\u5c31\u662f&#xff0c;\u5982\u679c\u4f60\u60f3\u8981\u901a\u8fc7USB-C\u63a5\u53e3\u6765\u5b9e\u73b0\u786c\u76d8\u3001\u7535\u8111\u7684\u8fde\u63a5&#xff0c;\u90a3\u4e48\u786c\u76d8\u548c\u7535\u8111\u90fd\u5fc5\u987b\u6709USB-C\u63a5\u53e3\u3002USB-C\u63a5\u53e3\u7edf\u4e00\u4e86USB-A\u3001USB-B\u3001HDML\u7b49\u6240\u6709\u7535\u8111\u63a5\u53e3\u3002<\/p>\n<p>\u8bf4\u5f97\u6982\u62ec\u6027\u4e00\u4e9b&#xff1a;<\/p>\n<p>\u628a MCP \u60f3\u8c61\u6210\u4eba\u5de5\u667a\u80fd\u5e94\u7528\u7684 USB-C \u7aef\u53e3\u3002\u5c31\u50cf USB-C \u63d0\u4f9b\u4e86\u5c06\u8bbe\u5907\u8fde\u63a5\u5230\u5404\u79cd\u5916\u8bbe\u548c\u914d\u4ef6\u7684\u6807\u51c6\u5316\u65b9\u5f0f\u4e00\u6837&#xff0c;MCP \u4e5f\u63d0\u4f9b\u4e86\u5c06\u4eba\u5de5\u667a\u80fd\u6a21\u578b\u8fde\u63a5\u5230\u4e0d\u540c\u6570\u636e\u6e90\u548c\u5de5\u5177\u7684\u6807\u51c6\u5316\u65b9\u5f0f\u3002<\/p>\n<p>MCP \u53ef\u5e2e\u52a9\u60a8\u5728 LLM \u7684\u57fa\u7840\u4e0a\u6784\u5efaAgent\u548c\u590d\u6742\u7684\u5de5\u4f5c\u6d41\u7a0b\u3002LLM \u7ecf\u5e38\u9700\u8981\u4e0e\u6570\u636e\u548c\u5de5\u5177\u96c6\u6210&#xff0c;\u800c MCP \u53ef\u63d0\u4f9b\u4ee5\u4e0b\u529f\u80fd&#xff1a;<\/p>\n<ul>\n<li>\u751f\u6001\u5065\u5168&#xff1a;\u9884\u5148\u5efa\u7acb\u7684mcp\u670d\u52a1\u5668\u53ef\u4ee5\u4e0d\u65ad\u65b0\u589e&#xff0c;\u5927\u6a21\u578b\u53ef\u4ee5\u901a\u8fc7MCP\u7b80\u5355\u3001\u65b9\u4fbf\u8fdb\u884c\u8c03\u7528<\/li>\n<li>\u5927\u6a21\u578b\u7edf\u4e00\u6027&#xff1a;\u5c31\u7b97mcp \u670d\u52a1\u5668\u4e0d\u65ad\u65b0\u589e\u548c\u6269\u5c55&#xff0c;\u5927\u6a21\u578b\u63d0\u4f9b\u5546\u548c\u7c7b\u578b\u53ef\u4ee5\u968f\u610f\u5207\u6362&#xff0c; LLM \u63d0\u4f9b\u5546\u548c\u4f9b\u5e94\u5546\u4e4b\u95f4\u5207\u6362\u7684\u7075\u6d3b\u6027\u975e\u5e38\u597d<\/li>\n<li>\u6570\u636e\u5b89\u5168&#xff1a;mcp\u670d\u52a1\u5668\u7684\u654f\u611f\u6570\u636e\u4fdd\u7559\u5728\u672c\u5730&#xff0c;\u662f\u4fdd\u62a4\u57fa\u7840\u5927\u6a21\u578b\u5e94\u7528\u67b6\u6784\u5185\u6570\u636e\u5b89\u5168\u7684\u6700\u4f73\u5b9e\u8df5<\/li>\n<\/ul>\n<h2>\u4e09\u3001\u5f00\u53d1\u8005\u5982\u4f55\u5f00\u53d1MCP\u670d\u52a1\u5668&#xff1f;<\/h2>\n<h3>\u73b0\u6210\u7684MCP servers<\/h3>\n<p>\u5e76\u4e14\u5b98\u65b9\u4e5f\u63d0\u4f9b\u4e86\u975e\u5e38\u591a\u73b0\u6210\u7684 MCP Servers&#xff0c;\u4f60\u53ea\u9700\u8981\u9009\u62e9\u4f60\u5e0c\u671b\u63a5\u5165\u7684\u5de5\u5177&#xff0c;\u7136\u540e\u63a5\u5165\u5373\u53ef\u3002\u73b0\u6210\u53ef\u7528\u7684MCP servers\u5982\u4e0b&#xff1a;<\/p>\n<p>1. awesome-mcp-servers<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091116-6827013411edf.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>2. MCP Servers<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091116-6827013497704.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> 3.MCP\u5b98\u65b9\u63d0\u4f9b\u7684servers<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091117-6827013528cba.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<h3>\u5f00\u53d1\u81ea\u5df1\u7684MCP servers<\/h3>\n<p>\u5f00\u59cb\u6784\u5efa\u60a8\u81ea\u5df1\u7684\u670d\u52a1\u5668&#xff0c;\u4ee5\u4fbf\u5728 Claude \u684c\u9762\u8f6f\u4ef6 \u548c \u5176\u4ed6\u5ba2\u6237\u7aef\u4e2d\u4f7f\u7528\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091117-68270135adb9b.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5728\u672c\u6559\u7a0b\u4e2d&#xff0c;\u6211\u4eec\u5c06\u6784\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 MCP \u5929\u6c14\u670d\u52a1\u5668&#xff0c;\u5e76\u5c06\u5176\u8fde\u63a5\u5230\u4e00\u4e2a\u4e3b\u673a&#xff0c;\u4e3b\u673a\u5c31\u662fClaude\u684c\u9762\u8f6f\u4ef6\u3002\u6211\u4eec\u5c06\u4ece\u57fa\u672c\u8bbe\u7f6e\u5f00\u59cb&#xff0c;\u7136\u540e\u9010\u6b65\u5904\u7406\u66f4\u590d\u6742\u7684\u5e94\u7528\u573a\u666f\u3002<\/p>\n<h4>\u6211\u4eec\u5c06\u8981\u6784\u5efa\u7684\u5185\u5bb9<\/h4>\n<p>\u8bb8\u591a LLMs \u76ee\u524d\u6ca1\u6709\u83b7\u53d6\u5929\u6c14\u9884\u62a5\u548c\u4e25\u91cd\u5929\u6c14\u8b66\u62a5\u7684\u80fd\u529b\u3002\u8ba9\u6211\u4eec\u4f7f\u7528 MCP \u6765\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898&#xff01;<\/p>\n<p>\u6211\u4eec\u5c06\u6784\u5efa\u4e00\u4e2a\u670d\u52a1\u5668&#xff0c;\u5b83\u66b4\u9732\u4e24\u4e2a\u5de5\u5177&#xff1a;get-alerts \u548c get-forecast\u3002\u7136\u540e\u6211\u4eec\u5c06\u670d\u52a1\u5668\u8fde\u63a5\u5230\u4e00\u4e2a MCP \u4e3b\u673a&#xff08;\u5728\u8fd9\u79cd\u793a\u4f8b\u4e2d&#xff0c;MCP\u4e3b\u673a\u662fClaude \u684c\u9762\u8f6f\u4ef6&#xff09;<\/p>\n<p>\u8bf7\u6ce8\u610f&#xff01;&#xff01;&#xff01;<\/p>\n<p>\u670d\u52a1\u5668\u53ef\u4ee5\u8fde\u63a5\u5230\u4efb\u4f55\u5ba2\u6237\u7aef\u3002\u6211\u4eec\u5728\u8fd9\u91cc\u9009\u62e9\u4e86 Claude\u684c\u9762\u8f6f\u4ef6 \u4ee5\u7b80\u5316\u64cd\u4f5c\u3002\u5982\u4f55\u6784\u5efaMCP \u5ba2\u6237\u7aef&#xff0c;\u8bf7\u53c2\u8003\u4e0b\u8282\u5185\u5bb9<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091118-68270136bae6e.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> \u6700\u7ec8\u7684\u6548\u679c\u56fe\u5982\u4e0b&#xff0c;\u8ddfclaude\u5927\u6a21\u578b\u54a8\u8be2\u5929\u6c14\u60c5\u51b5&#xff0c;\u5927\u6a21\u578b\u53ef\u4ee5\u8c03\u7528\u81ea\u5b9a\u4e49\u7684\u5929\u6c14\u670d\u52a1\u5668\u7684\u5de5\u5177\u8fdb\u884c\u56de\u7b54\u3002 <img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091119-682701374fbcb.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091119-68270137b4abc.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/> MCP \u670d\u52a1\u5668\u53ef\u4ee5\u63d0\u4f9b\u4e09\u79cd\u4e3b\u8981\u529f\u80fd&#xff1a;<\/p>\n<li>\u8d44\u6e90 &#xff1a;\u53ef\u4ee5\u88ab\u5ba2\u6237\u7aef\u8bfb\u53d6\u7684\u7c7b\u4f3c\u6587\u4ef6\u7684\u6570\u636e&#xff08;\u5982 API \u54cd\u5e94\u6216\u6587\u4ef6\u5185\u5bb9&#xff09;<\/li>\n<li>\u5de5\u5177 &#xff1a;\u53ef\u4ee5\u88ab LLM \u8c03\u7528\u7684\u529f\u80fd&#xff08;\u9700\u7528\u6237\u6279\u51c6&#xff09;<\/li>\n<li>\u63d0\u793a : \u9884\u5199\u597d\u7684\u6a21\u677f&#xff0c;\u5e2e\u52a9\u7528\u6237\u5b8c\u6210\u7279\u5b9a\u4efb\u52a1<\/li>\n<p>\u8fd9\u7bc7\u6559\u7a0b\u4e3b\u8981\u5c06\u4e13\u6ce8\u4e8e\u5de5\u5177\u3002<\/p>\n<h4>\u6784\u5efa\u4f60\u7684\u670d\u52a1\u5668<\/h4>\n<p>\u9700\u8981\u63d0\u524d\u5b89\u88c5\u597duv\u3001python3.10\u3001Python MCP SDK 1.2.0\u3002\u8fd9\u4e2a\u670d\u52a1\u5668\u9ed8\u8ba4\u5728Linux\u670d\u52a1\u5668\u4e0a\u9762\u642d\u5efa<\/p>\n<p>\u8ba9\u6211\u4eec\u5f00\u59cb\u6784\u5efa\u6211\u4eec\u7684\u5929\u6c14\u670d\u52a1\u5668&#xff01;\u5b8c\u6574\u4ee3\u7801\u5982\u4e0b&#xff0c;\u8ddf\u5b98\u7f51\u4e0d\u4e00\u6837&#xff0c;\u4e0b\u9762\u7684\u4ee3\u7801\u6211\u662f\u5728\u5b98\u65b9\u4ee3\u7801\u7684\u57fa\u7840\u4e0a\u6dfb\u52a0\u4e86\u4e2d\u6587\u6ce8\u91ca<\/p>\n<p><span class=\"token comment\">#!\/usr\/bin\/env python<\/span><br \/>\n<span class=\"token comment\"># -*- coding:utf-8 -*-<\/span><br \/>\n<span class=\"token triple-quoted-string string\">&#034;&#034;&#034;<br \/>\n&#064;author: Junius<br \/>\n&#064;Email: see619055&#064;gmail.com<br \/>\n&#064;time: 2025\/5\/12 17:54<br \/>\n&#064;file: weather<br \/>\n&#064;project: OpenAppAI<br \/>\n&#064;describe: TODO<br \/>\n&#034;&#034;&#034;<\/span><br \/>\n<span class=\"token keyword\">from<\/span> typing <span class=\"token keyword\">import<\/span> Any  <span class=\"token comment\"># \u5bfc\u5165 Any \u7c7b\u578b&#xff0c;\u7528\u4e8e\u7075\u6d3b\u7684\u7c7b\u578b\u6ce8\u89e3<\/span><br \/>\n<span class=\"token keyword\">import<\/span> httpx  <span class=\"token comment\"># \u5bfc\u5165 httpx \u5e93&#xff0c;\u7528\u4e8e\u53d1\u8d77\u5f02\u6b65 HTTP \u8bf7\u6c42<\/span><br \/>\n<span class=\"token keyword\">from<\/span> mcp<span class=\"token punctuation\">.<\/span>server<span class=\"token punctuation\">.<\/span>fastmcp <span class=\"token keyword\">import<\/span> FastMCP  <span class=\"token comment\"># \u5bfc\u5165 FastMCP \u6846\u67b6&#xff0c;\u7528\u4e8e\u6784\u5efa MCP \u670d\u52a1\u5668<\/span><\/p>\n<p><span class=\"token comment\"># \u521d\u59cb\u5316\u4e00\u4e2a\u540d\u4e3a &#034;weather&#034; \u7684 FastMCP \u670d\u52a1\u5668\u5b9e\u4f8b<\/span><br \/>\nmcp <span class=\"token operator\">&#061;<\/span> FastMCP<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;weather&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u5b9a\u4e49 NWS&#xff08;\u7f8e\u56fd\u56fd\u5bb6\u6c14\u8c61\u5c40&#xff09;API \u7684\u57fa\u7840 URL<\/span><br \/>\nNWS_API_BASE <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;https:\/\/api.weather.gov&#034;<\/span><br \/>\n<span class=\"token comment\"># \u8bbe\u7f6e User-Agent \u8bf7\u6c42\u5934&#xff0c;\u6807\u8bc6\u5ba2\u6237\u7aef\u8eab\u4efd<\/span><br \/>\nUSER_AGENT <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;weather-app\/1.0&#034;<\/span><\/p>\n<p><span class=\"token keyword\">async<\/span> <span class=\"token keyword\">def<\/span> <span class=\"token function\">make_nws_request<\/span><span class=\"token punctuation\">(<\/span>url<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\">dict<\/span><span class=\"token punctuation\">[<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> Any<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">|<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u5411 NWS API \u53d1\u8d77\u8bf7\u6c42&#xff0c;\u5e76\u8fdb\u884c\u9519\u8bef\u5904\u7406&#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token comment\"># \u8bbe\u7f6e\u8bf7\u6c42\u5934&#xff0c;\u5305\u542b User-Agent \u548c Accept \u5185\u5bb9\u7c7b\u578b<\/span><br \/>\n    headers <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token string\">&#034;User-Agent&#034;<\/span><span class=\"token punctuation\">:<\/span> USER_AGENT<span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string\">&#034;Accept&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;application\/geo&#043;json&#034;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\"># \u4f7f\u7528 httpx \u5f02\u6b65\u5ba2\u6237\u7aef\u53d1\u8d77\u8bf7\u6c42<\/span><br \/>\n    <span class=\"token keyword\">async<\/span> <span class=\"token keyword\">with<\/span> httpx<span class=\"token punctuation\">.<\/span>AsyncClient<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> client<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token comment\"># \u5411\u6307\u5b9a URL \u53d1\u8d77 GET \u8bf7\u6c42&#xff0c;\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\u4e3a 30 \u79d2<\/span><br \/>\n            response <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> client<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span>url<span class=\"token punctuation\">,<\/span> headers<span class=\"token operator\">&#061;<\/span>headers<span class=\"token punctuation\">,<\/span> timeout<span class=\"token operator\">&#061;<\/span><span class=\"token number\">30.0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token comment\"># \u5982\u679c\u54cd\u5e94\u72b6\u6001\u7801\u8868\u793a\u9519\u8bef&#xff08;\u5982 4xx\u30015xx&#xff09;&#xff0c;\u629b\u51fa\u5f02\u5e38<\/span><br \/>\n            response<span class=\"token punctuation\">.<\/span>raise_for_status<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token comment\"># \u8fd4\u56de\u89e3\u6790\u540e\u7684 JSON \u6570\u636e<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> response<span class=\"token punctuation\">.<\/span>json<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">except<\/span> Exception<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token comment\"># \u5982\u679c\u53d1\u751f\u4efb\u4f55\u5f02\u5e38&#xff0c;\u8fd4\u56de None \u8868\u793a\u8bf7\u6c42\u5931\u8d25<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">None<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">format_alert<\/span><span class=\"token punctuation\">(<\/span>feature<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">dict<\/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;\u5c06\u8b66\u62a5\u4fe1\u606f\u683c\u5f0f\u5316\u4e3a\u53ef\u8bfb\u6027\u5f3a\u7684\u5b57\u7b26\u4e32&#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token comment\"># \u63d0\u53d6 feature \u5b57\u5178\u4e2d\u7684 &#039;properties&#039; \u90e8\u5206<\/span><br \/>\n    props <span class=\"token operator\">&#061;<\/span> feature<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;properties&#034;<\/span><span class=\"token punctuation\">]<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5c06\u8b66\u62a5\u4fe1\u606f\u4ee5\u7ed3\u6784\u5316\u6587\u672c\u5f62\u5f0f\u8fd4\u56de&#xff0c;\u5404\u5b57\u6bb5\u4f7f\u7528 get \u65b9\u6cd5\u907f\u514d KeyError<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;&#034;&#034;<br \/>\nEvent: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>props<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;event&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;Unknown&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">                # \u8b66\u62a5\u4e8b\u4ef6\u540d\u79f0&#xff0c;\u82e5\u65e0\u5219\u663e\u793a Unknown<br \/>\nArea: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>props<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;areaDesc&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;Unknown&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">              # \u8b66\u62a5\u5f71\u54cd\u533a\u57df\u63cf\u8ff0&#xff0c;\u82e5\u65e0\u5219\u663e\u793a Unknown<br \/>\nSeverity: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>props<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;severity&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;Unknown&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">          # \u8b66\u62a5\u4e25\u91cd\u7a0b\u5ea6&#xff0c;\u82e5\u65e0\u5219\u663e\u793a Unknown<br \/>\nDescription: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>props<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;description&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;No description available&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">  # \u8b66\u62a5\u63cf\u8ff0&#xff0c;\u82e5\u65e0\u5219\u63d0\u793a\u65e0\u63cf\u8ff0<br \/>\nInstructions: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>props<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;instruction&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;No specific instructions provided&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">  # \u8b66\u62a5\u5e94\u5bf9\u5efa\u8bae&#xff0c;\u82e5\u65e0\u5219\u63d0\u793a\u65e0\u6307\u4ee4<br \/>\n&#034;&#034;&#034;<\/span><\/span><\/p>\n<p><span class=\"token comment\"># \u4f7f\u7528 &#064;mcp.tool() \u88c5\u9970\u5668\u6ce8\u518c get_alerts \u4e3a MCP \u5de5\u5177&#xff0c;\u7528\u4e8e\u83b7\u53d6\u5929\u6c14\u8b66\u62a5<\/span><br \/>\n<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\">get_alerts<\/span><span class=\"token punctuation\">(<\/span>state<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 triple-quoted-string string\">&#034;&#034;&#034;\u83b7\u53d6\u67d0\u4e2a\u7f8e\u56fd\u5dde\u7684\u5929\u6c14\u8b66\u62a5\u3002<\/p>\n<p>    \u53c2\u6570:<br \/>\n        state: \u4e24\u4f4d\u5b57\u6bcd\u7684\u7f8e\u56fd\u5dde\u4ee3\u7801&#xff08;\u4f8b\u5982 CA, NY&#xff09;<br \/>\n    &#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token comment\"># \u6784\u9020\u8bf7\u6c42 URL&#xff0c;\u7528\u4e8e\u6839\u636e\u5dde\u4ee3\u7801\u83b7\u53d6\u8b66\u62a5\u4fe1\u606f<\/span><br \/>\n    url <span class=\"token operator\">&#061;<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>NWS_API_BASE<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\/alerts\/active\/area\/<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>state<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><br \/>\n    <span class=\"token comment\"># \u8c03\u7528 make_nws_request \u5f02\u6b65\u53d1\u8d77 HTTP \u8bf7\u6c42\u83b7\u53d6\u6570\u636e<\/span><br \/>\n    data <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> make_nws_request<span class=\"token punctuation\">(<\/span>url<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5982\u679c\u8fd4\u56de\u7684\u6570\u636e\u4e3a\u7a7a\u6216\u4e0d\u5305\u542b features \u5b57\u6bb5&#xff0c;\u8868\u793a\u65e0\u6cd5\u83b7\u53d6\u8b66\u62a5\u4fe1\u606f<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token keyword\">not<\/span> data <span class=\"token keyword\">or<\/span> <span class=\"token string\">&#034;features&#034;<\/span> <span class=\"token keyword\">not<\/span> <span class=\"token keyword\">in<\/span> data<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;Unable to fetch alerts or no alerts found.&#034;<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5982\u679c features \u662f\u7a7a\u5217\u8868&#xff0c;\u8868\u793a\u5f53\u524d\u8be5\u5dde\u6ca1\u6709\u6d3b\u52a8\u8b66\u62a5<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token keyword\">not<\/span> data<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;features&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;No active alerts for this state.&#034;<\/span><\/p>\n<p>    <span class=\"token comment\"># \u904d\u5386\u6240\u6709 feature \u5e76\u4f7f\u7528 format_alert \u683c\u5f0f\u5316\u8b66\u62a5\u4fe1\u606f<\/span><br \/>\n    alerts <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span>format_alert<span class=\"token punctuation\">(<\/span>feature<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">for<\/span> feature <span class=\"token keyword\">in<\/span> data<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;features&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><br \/>\n    <span class=\"token comment\"># \u5c06\u591a\u4e2a\u8b66\u62a5\u4fe1\u606f\u7528 &#034;&#8212;&#034; \u5206\u9694\u540e\u62fc\u63a5\u6210\u5b57\u7b26\u4e32\u8fd4\u56de<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;\\\\n&#8212;\\\\n&#034;<\/span><span class=\"token punctuation\">.<\/span>join<span class=\"token punctuation\">(<\/span>alerts<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u4f7f\u7528 &#064;mcp.tool() \u88c5\u9970\u5668\u6ce8\u518c get_forecast \u4e3a MCP \u5de5\u5177&#xff0c;\u7528\u4e8e\u83b7\u53d6\u5929\u6c14\u9884\u62a5<\/span><br \/>\n<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\">get_forecast<\/span><span class=\"token punctuation\">(<\/span>latitude<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">float<\/span><span class=\"token punctuation\">,<\/span> longitude<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">float<\/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;\u83b7\u53d6\u67d0\u4e2a\u4f4d\u7f6e\u7684\u5929\u6c14\u9884\u62a5\u3002<\/p>\n<p>    \u53c2\u6570:<br \/>\n        latitude: \u5730\u7406\u7eac\u5ea6<br \/>\n        longitude: \u5730\u7406\u7ecf\u5ea6<br \/>\n    &#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token comment\"># \u7b2c\u4e00\u6b65&#xff1a;\u6784\u9020 URL \u83b7\u53d6\u70b9\u4f4d\u4fe1\u606f&#xff08;\u5305\u542b\u9884\u62a5\u7f51\u683c\u94fe\u63a5&#xff09;<\/span><br \/>\n    points_url <span class=\"token operator\">&#061;<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>NWS_API_BASE<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\/points\/<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>latitude<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">,<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>longitude<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><br \/>\n    <span class=\"token comment\"># \u53d1\u8d77\u5f02\u6b65\u8bf7\u6c42\u83b7\u53d6\u70b9\u4f4d\u6570\u636e<\/span><br \/>\n    points_data <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> make_nws_request<span class=\"token punctuation\">(<\/span>points_url<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5982\u679c\u70b9\u4f4d\u6570\u636e\u4e3a\u7a7a&#xff0c;\u8fd4\u56de\u9519\u8bef\u63d0\u793a<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token keyword\">not<\/span> points_data<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;Unable to fetch forecast data for this location.&#034;<\/span><\/p>\n<p>    <span class=\"token comment\"># \u4ece\u70b9\u4f4d\u6570\u636e\u4e2d\u63d0\u53d6\u8be6\u7ec6\u7684\u5929\u6c14\u9884\u62a5 URL<\/span><br \/>\n    forecast_url <span class=\"token operator\">&#061;<\/span> points_data<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;properties&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;forecast&#034;<\/span><span class=\"token punctuation\">]<\/span><br \/>\n    <span class=\"token comment\"># \u53d1\u8d77\u5f02\u6b65\u8bf7\u6c42\u83b7\u53d6\u5177\u4f53\u7684\u5929\u6c14\u9884\u62a5\u6570\u636e<\/span><br \/>\n    forecast_data <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> make_nws_request<span class=\"token punctuation\">(<\/span>forecast_url<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5982\u679c\u8be6\u7ec6\u9884\u62a5\u6570\u636e\u4e3a\u7a7a&#xff0c;\u8fd4\u56de\u9519\u8bef\u63d0\u793a<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token keyword\">not<\/span> forecast_data<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;Unable to fetch detailed forecast.&#034;<\/span><\/p>\n<p>    <span class=\"token comment\"># \u63d0\u53d6\u5404\u65f6\u95f4\u6bb5\u7684\u9884\u62a5\u4fe1\u606f<\/span><br \/>\n    periods <span class=\"token operator\">&#061;<\/span> forecast_data<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;properties&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;periods&#034;<\/span><span class=\"token punctuation\">]<\/span><br \/>\n    forecasts <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><\/p>\n<p>    <span class=\"token comment\"># \u904d\u5386\u524d5\u4e2a\u65f6\u95f4\u6bb5&#xff0c;\u683c\u5f0f\u5316\u8f93\u51fa\u5929\u6c14\u4fe1\u606f<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> period <span class=\"token keyword\">in<\/span> periods<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span>  <span class=\"token comment\"># \u53ea\u663e\u793a\u6700\u8fd15\u4e2a\u65f6\u95f4\u6bb5<\/span><br \/>\n        forecast <span class=\"token operator\">&#061;<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;&#034;&#034;<br \/>\n<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>period<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;name&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">:                    # \u65f6\u95f4\u6bb5\u540d\u79f0&#xff08;\u5982 Tonight, Thursday&#xff09;<br \/>\nTemperature: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>period<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;temperature&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\u00b0<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>period<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;temperatureUnit&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">   # \u6e29\u5ea6\u53ca\u5355\u4f4d<br \/>\nWind: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>period<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;windSpeed&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>period<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;windDirection&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">             # \u98ce\u901f\u548c\u98ce\u5411<br \/>\nForecast: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>period<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;detailedForecast&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">                            # \u8be6\u7ec6\u9884\u62a5\u63cf\u8ff0<br \/>\n&#034;&#034;&#034;<\/span><\/span><br \/>\n        forecasts<span class=\"token punctuation\">.<\/span>append<span class=\"token punctuation\">(<\/span>forecast<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u5c06\u6bcf\u4e2a\u65f6\u95f4\u6bb5\u7684\u9884\u62a5\u6dfb\u52a0\u5230\u5217\u8868<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5c06\u591a\u4e2a\u65f6\u95f4\u6bb5\u7684\u9884\u62a5\u4fe1\u606f\u7528 &#034;&#8212;&#034; \u5206\u9694\u540e\u62fc\u63a5\u6210\u5b57\u7b26\u4e32\u8fd4\u56de<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;\\\\n&#8212;\\\\n&#034;<\/span><span class=\"token punctuation\">.<\/span>join<span class=\"token punctuation\">(<\/span>forecasts<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u5982\u679c\u8be5\u6587\u4ef6\u4f5c\u4e3a\u4e3b\u7a0b\u5e8f\u8fd0\u884c&#xff0c;\u5219\u6267\u884c\u4ee5\u4e0b\u4ee3\u7801<\/span><br \/>\n<span class=\"token keyword\">if<\/span> __name__ <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#034;__main__&#034;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u521d\u59cb\u5316\u5e76\u8fd0\u884c FastMCP \u670d\u52a1\u5668&#xff0c;\u4f7f\u7528\u6807\u51c6\u8f93\u5165\u8f93\u51fa&#xff08;stdio&#xff09;\u4f5c\u4e3a\u901a\u4fe1\u534f\u8bae<\/span><br \/>\n    mcp<span class=\"token punctuation\">.<\/span>run<span class=\"token punctuation\">(<\/span>transport<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;stdio&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<h5>\u914d\u7f6e\u73af\u5883<\/h5>\n<p>\u73b0\u5728&#xff0c;\u8ba9\u6211\u4eec\u521b\u5efa\u5e76\u8bbe\u7f6e\u6211\u4eec\u7684\u9879\u76ee&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u4f7f\u7528 uv \u5de5\u5177\u521d\u59cb\u5316\u4e00\u4e2a\u540d\u4e3a weather \u7684\u65b0\u9879\u76ee\u76ee\u5f55\u3002\u8fd9\u4f1a\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u57fa\u7840 pyproject.toml \u6587\u4ef6\u7684\u65b0\u6587\u4ef6\u5939&#xff0c;\u7528\u4e8e\u7ba1\u7406 Python \u9879\u76ee\u3002<\/span><br \/>\nuv init weather<br \/>\n<span class=\"token builtin class-name\">cd<\/span> weather<\/p>\n<p><span class=\"token comment\"># \u4f7f\u7528 uv \u521b\u5efa\u4e00\u4e2a\u9694\u79bb\u7684 Python \u865a\u62df\u73af\u5883&#xff08;virtual environment&#xff09;&#xff0c;\u4ee5\u4fbf\u8be5\u9879\u76ee\u6709\u72ec\u7acb\u7684\u4f9d\u8d56\u5305&#xff0c;\u4e0d\u4f1a\u4e0e\u5176\u4ed6\u9879\u76ee\u51b2\u7a81\u3002<\/span><br \/>\nuv venv<br \/>\n<span class=\"token comment\"># \u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/span><br \/>\n<span class=\"token builtin class-name\">source<\/span> .venv\/bin\/activate<\/p>\n<p><span class=\"token comment\"># &#034;mcp[cli]&#034;&#xff1a;\u8868\u793a\u5b89\u88c5 mcp \u5305&#xff0c;\u5e76\u989d\u5916\u5b89\u88c5\u5176 CLI&#xff08;\u547d\u4ee4\u884c\u63a5\u53e3&#xff09;\u76f8\u5173\u4f9d\u8d56<\/span><br \/>\n<span class=\"token comment\"># httpx&#xff1a;\u4e00\u4e2a\u652f\u6301\u5f02\u6b65\u8bf7\u6c42\u7684 HTTP \u5ba2\u6237\u7aef\u5e93&#xff0c;\u7528\u4e8e\u53d1\u8d77\u7f51\u7edc\u8bf7\u6c42\u3002<\/span><br \/>\nuv <span class=\"token function\">add<\/span> <span class=\"token string\">&#034;mcp[cli]&#034;<\/span> httpx<\/p>\n<p><span class=\"token comment\"># \u521b\u5efa\u670d\u52a1\u5668\u4ee3\u7801\u6587\u4ef6<\/span><br \/>\n<span class=\"token function\">touch<\/span> weather.py<\/p>\n<h5>\u5bfc\u5165\u5305\u5e76\u8bbe\u7f6e\u5b9e\u4f8b<\/h5>\n<p>\u5c06\u4ee5\u4e0b\u5185\u5bb9\u6dfb\u52a0\u5230 weather.py \u7684\u9876\u90e8&#xff1a; python weather.py: <\/p>\n<p><span class=\"token keyword\">from<\/span> typing <span class=\"token keyword\">import<\/span> Any  <span class=\"token comment\"># \u5bfc\u5165 Any \u7c7b\u578b&#xff0c;\u7528\u4e8e\u7075\u6d3b\u7684\u7c7b\u578b\u6ce8\u89e3<\/span><br \/>\n<span class=\"token keyword\">import<\/span> httpx  <span class=\"token comment\"># \u5bfc\u5165 httpx \u5e93&#xff0c;\u7528\u4e8e\u53d1\u8d77\u5f02\u6b65 HTTP \u8bf7\u6c42<\/span><br \/>\n<span class=\"token keyword\">from<\/span> mcp<span class=\"token punctuation\">.<\/span>server<span class=\"token punctuation\">.<\/span>fastmcp <span class=\"token keyword\">import<\/span> FastMCP  <span class=\"token comment\"># \u5bfc\u5165 FastMCP \u6846\u67b6&#xff0c;\u7528\u4e8e\u6784\u5efa MCP \u670d\u52a1\u5668<\/span><\/p>\n<p><span class=\"token comment\"># \u521d\u59cb\u5316\u4e00\u4e2a\u540d\u4e3a &#034;weather&#034; \u7684 FastMCP \u670d\u52a1\u5668\u5b9e\u4f8b<\/span><br \/>\nmcp <span class=\"token operator\">&#061;<\/span> FastMCP<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#034;weather&#034;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u5b9a\u4e49 NWS&#xff08;\u7f8e\u56fd\u56fd\u5bb6\u6c14\u8c61\u5c40&#xff09;API \u7684\u57fa\u7840 URL<\/span><br \/>\nNWS_API_BASE <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;https:\/\/api.weather.gov&#034;<\/span><br \/>\n<span class=\"token comment\"># \u8bbe\u7f6e User-Agent \u8bf7\u6c42\u5934&#xff0c;\u6807\u8bc6\u5ba2\u6237\u7aef\u8eab\u4efd<\/span><br \/>\nUSER_AGENT <span class=\"token operator\">&#061;<\/span> <span class=\"token string\">&#034;weather-app\/1.0&#034;<\/span><\/p>\n<p>FastMCP \u7c7b\u4f7f\u7528 Python \u7c7b\u578b\u63d0\u793a\u548c\u6587\u6863\u5b57\u7b26\u4e32\u81ea\u52a8\u751f\u6210\u5de5\u5177\u5b9a\u4e49&#xff0c;\u4f7f\u5176\u5bb9\u6613\u521b\u5efa\u548c\u7ef4\u62a4 MCP \u5de5\u5177\u3002<\/p>\n<h5>\u8f85\u52a9\u51fd\u6570<\/h5>\n<p>\u63a5\u4e0b\u6765&#xff0c;\u8ba9\u6211\u4eec\u6dfb\u52a0\u7528\u4e8e\u67e5\u8be2\u548c\u683c\u5f0f\u5316\u6765\u81ea\u56fd\u5bb6\u6c14\u8c61\u670d\u52a1 API \u7684\u6570\u636e\u7684\u8f85\u52a9\u51fd\u6570&#xff1a;<\/p>\n<p><span class=\"token keyword\">async<\/span> <span class=\"token keyword\">def<\/span> <span class=\"token function\">make_nws_request<\/span><span class=\"token punctuation\">(<\/span>url<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\">dict<\/span><span class=\"token punctuation\">[<\/span><span class=\"token builtin\">str<\/span><span class=\"token punctuation\">,<\/span> Any<span class=\"token punctuation\">]<\/span> <span class=\"token operator\">|<\/span> <span class=\"token boolean\">None<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">&#034;&#034;&#034;\u5411 NWS API \u53d1\u8d77\u8bf7\u6c42&#xff0c;\u5e76\u8fdb\u884c\u9519\u8bef\u5904\u7406&#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token comment\"># \u8bbe\u7f6e\u8bf7\u6c42\u5934&#xff0c;\u5305\u542b User-Agent \u548c Accept \u5185\u5bb9\u7c7b\u578b<\/span><br \/>\n    headers <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token string\">&#034;User-Agent&#034;<\/span><span class=\"token punctuation\">:<\/span> USER_AGENT<span class=\"token punctuation\">,<\/span><br \/>\n        <span class=\"token string\">&#034;Accept&#034;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">&#034;application\/geo&#043;json&#034;<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><\/p>\n<p>    <span class=\"token comment\"># \u4f7f\u7528 httpx \u5f02\u6b65\u5ba2\u6237\u7aef\u53d1\u8d77\u8bf7\u6c42<\/span><br \/>\n    <span class=\"token keyword\">async<\/span> <span class=\"token keyword\">with<\/span> httpx<span class=\"token punctuation\">.<\/span>AsyncClient<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">as<\/span> client<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">try<\/span><span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token comment\"># \u5411\u6307\u5b9a URL \u53d1\u8d77 GET \u8bf7\u6c42&#xff0c;\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\u4e3a 30 \u79d2<\/span><br \/>\n            response <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> client<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span>url<span class=\"token punctuation\">,<\/span> headers<span class=\"token operator\">&#061;<\/span>headers<span class=\"token punctuation\">,<\/span> timeout<span class=\"token operator\">&#061;<\/span><span class=\"token number\">30.0<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token comment\"># \u5982\u679c\u54cd\u5e94\u72b6\u6001\u7801\u8868\u793a\u9519\u8bef&#xff08;\u5982 4xx\u30015xx&#xff09;&#xff0c;\u629b\u51fa\u5f02\u5e38<\/span><br \/>\n            response<span class=\"token punctuation\">.<\/span>raise_for_status<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n            <span class=\"token comment\"># \u8fd4\u56de\u89e3\u6790\u540e\u7684 JSON \u6570\u636e<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> response<span class=\"token punctuation\">.<\/span>json<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">except<\/span> Exception<span class=\"token punctuation\">:<\/span><br \/>\n            <span class=\"token comment\"># \u5982\u679c\u53d1\u751f\u4efb\u4f55\u5f02\u5e38&#xff0c;\u8fd4\u56de None \u8868\u793a\u8bf7\u6c42\u5931\u8d25<\/span><br \/>\n            <span class=\"token keyword\">return<\/span> <span class=\"token boolean\">None<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">format_alert<\/span><span class=\"token punctuation\">(<\/span>feature<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">dict<\/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;\u5c06\u8b66\u62a5\u4fe1\u606f\u683c\u5f0f\u5316\u4e3a\u53ef\u8bfb\u6027\u5f3a\u7684\u5b57\u7b26\u4e32&#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token comment\"># \u63d0\u53d6 feature \u5b57\u5178\u4e2d\u7684 &#039;properties&#039; \u90e8\u5206<\/span><br \/>\n    props <span class=\"token operator\">&#061;<\/span> feature<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;properties&#034;<\/span><span class=\"token punctuation\">]<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5c06\u8b66\u62a5\u4fe1\u606f\u4ee5\u7ed3\u6784\u5316\u6587\u672c\u5f62\u5f0f\u8fd4\u56de&#xff0c;\u5404\u5b57\u6bb5\u4f7f\u7528 get \u65b9\u6cd5\u907f\u514d KeyError<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;&#034;&#034;<br \/>\nEvent: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>props<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;event&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;Unknown&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">                # \u8b66\u62a5\u4e8b\u4ef6\u540d\u79f0&#xff0c;\u82e5\u65e0\u5219\u663e\u793a Unknown<br \/>\nArea: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>props<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;areaDesc&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;Unknown&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">              # \u8b66\u62a5\u5f71\u54cd\u533a\u57df\u63cf\u8ff0&#xff0c;\u82e5\u65e0\u5219\u663e\u793a Unknown<br \/>\nSeverity: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>props<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;severity&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;Unknown&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">          # \u8b66\u62a5\u4e25\u91cd\u7a0b\u5ea6&#xff0c;\u82e5\u65e0\u5219\u663e\u793a Unknown<br \/>\nDescription: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>props<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;description&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;No description available&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">  # \u8b66\u62a5\u63cf\u8ff0&#xff0c;\u82e5\u65e0\u5219\u63d0\u793a\u65e0\u63cf\u8ff0<br \/>\nInstructions: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>props<span class=\"token punctuation\">.<\/span>get<span class=\"token punctuation\">(<\/span><span class=\"token string\">&#039;instruction&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;No specific instructions provided&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">  # \u8b66\u62a5\u5e94\u5bf9\u5efa\u8bae&#xff0c;\u82e5\u65e0\u5219\u63d0\u793a\u65e0\u6307\u4ee4<br \/>\n&#034;&#034;&#034;<\/span><\/span><\/p>\n<h5>\u5b9e\u65bd\u5de5\u5177\u6267\u884c<\/h5>\n<p>\u6dfb\u52a0\u5de5\u5177\u6267\u884c\u5904\u7406\u5668&#xff0c;\u5de5\u5177\u6267\u884c\u5904\u7406\u5668\u8d1f\u8d23\u5b9e\u9645\u6267\u884c\u6bcf\u4e2a\u5de5\u5177\u7684\u903b\u8f91\u3002\u4f7f\u7528&#064;mcp.tool()\u8fdb\u884c\u88c5\u9970\u7684\u5f02\u6b65\u51fd\u6570\u5c31\u662f\u5de5\u5177\u6267\u884c\u5904\u7406\u5668\u3002<\/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\">get_alerts<\/span><span class=\"token punctuation\">(<\/span>state<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 triple-quoted-string string\">&#034;&#034;&#034;\u83b7\u53d6\u67d0\u4e2a\u7f8e\u56fd\u5dde\u7684\u5929\u6c14\u8b66\u62a5\u3002<\/p>\n<p>    \u53c2\u6570:<br \/>\n        state: \u4e24\u4f4d\u5b57\u6bcd\u7684\u7f8e\u56fd\u5dde\u4ee3\u7801&#xff08;\u4f8b\u5982 CA, NY&#xff09;<br \/>\n    &#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token comment\"># \u6784\u9020\u8bf7\u6c42 URL&#xff0c;\u7528\u4e8e\u6839\u636e\u5dde\u4ee3\u7801\u83b7\u53d6\u8b66\u62a5\u4fe1\u606f<\/span><br \/>\n    url <span class=\"token operator\">&#061;<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>NWS_API_BASE<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\/alerts\/active\/area\/<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>state<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><br \/>\n    <span class=\"token comment\"># \u8c03\u7528 make_nws_request \u5f02\u6b65\u53d1\u8d77 HTTP \u8bf7\u6c42\u83b7\u53d6\u6570\u636e<\/span><br \/>\n    data <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> make_nws_request<span class=\"token punctuation\">(<\/span>url<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5982\u679c\u8fd4\u56de\u7684\u6570\u636e\u4e3a\u7a7a\u6216\u4e0d\u5305\u542b features \u5b57\u6bb5&#xff0c;\u8868\u793a\u65e0\u6cd5\u83b7\u53d6\u8b66\u62a5\u4fe1\u606f<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token keyword\">not<\/span> data <span class=\"token keyword\">or<\/span> <span class=\"token string\">&#034;features&#034;<\/span> <span class=\"token keyword\">not<\/span> <span class=\"token keyword\">in<\/span> data<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;Unable to fetch alerts or no alerts found.&#034;<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5982\u679c features \u662f\u7a7a\u5217\u8868&#xff0c;\u8868\u793a\u5f53\u524d\u8be5\u5dde\u6ca1\u6709\u6d3b\u52a8\u8b66\u62a5<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token keyword\">not<\/span> data<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;features&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;No active alerts for this state.&#034;<\/span><\/p>\n<p>    <span class=\"token comment\"># \u904d\u5386\u6240\u6709 feature \u5e76\u4f7f\u7528 format_alert \u683c\u5f0f\u5316\u8b66\u62a5\u4fe1\u606f<\/span><br \/>\n    alerts <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span>format_alert<span class=\"token punctuation\">(<\/span>feature<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">for<\/span> feature <span class=\"token keyword\">in<\/span> data<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;features&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">]<\/span><br \/>\n    <span class=\"token comment\"># \u5c06\u591a\u4e2a\u8b66\u62a5\u4fe1\u606f\u7528 &#034;&#8212;&#034; \u5206\u9694\u540e\u62fc\u63a5\u6210\u5b57\u7b26\u4e32\u8fd4\u56de<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;\\\\n&#8212;\\\\n&#034;<\/span><span class=\"token punctuation\">.<\/span>join<span class=\"token punctuation\">(<\/span>alerts<span class=\"token punctuation\">)<\/span><\/p>\n<p><span class=\"token comment\"># \u4f7f\u7528 &#064;mcp.tool() \u88c5\u9970\u5668\u6ce8\u518c get_forecast \u4e3a MCP \u5de5\u5177&#xff0c;\u7528\u4e8e\u83b7\u53d6\u5929\u6c14\u9884\u62a5<\/span><br \/>\n<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\">get_forecast<\/span><span class=\"token punctuation\">(<\/span>latitude<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">float<\/span><span class=\"token punctuation\">,<\/span> longitude<span class=\"token punctuation\">:<\/span> <span class=\"token builtin\">float<\/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;\u83b7\u53d6\u67d0\u4e2a\u4f4d\u7f6e\u7684\u5929\u6c14\u9884\u62a5\u3002<\/p>\n<p>    \u53c2\u6570:<br \/>\n        latitude: \u5730\u7406\u7eac\u5ea6<br \/>\n        longitude: \u5730\u7406\u7ecf\u5ea6<br \/>\n    &#034;&#034;&#034;<\/span><br \/>\n    <span class=\"token comment\"># \u7b2c\u4e00\u6b65&#xff1a;\u6784\u9020 URL \u83b7\u53d6\u70b9\u4f4d\u4fe1\u606f&#xff08;\u5305\u542b\u9884\u62a5\u7f51\u683c\u94fe\u63a5&#xff09;<\/span><br \/>\n    points_url <span class=\"token operator\">&#061;<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>NWS_API_BASE<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\/points\/<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>latitude<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">,<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>longitude<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">&#034;<\/span><\/span><br \/>\n    <span class=\"token comment\"># \u53d1\u8d77\u5f02\u6b65\u8bf7\u6c42\u83b7\u53d6\u70b9\u4f4d\u6570\u636e<\/span><br \/>\n    points_data <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> make_nws_request<span class=\"token punctuation\">(<\/span>points_url<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5982\u679c\u70b9\u4f4d\u6570\u636e\u4e3a\u7a7a&#xff0c;\u8fd4\u56de\u9519\u8bef\u63d0\u793a<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token keyword\">not<\/span> points_data<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;Unable to fetch forecast data for this location.&#034;<\/span><\/p>\n<p>    <span class=\"token comment\"># \u4ece\u70b9\u4f4d\u6570\u636e\u4e2d\u63d0\u53d6\u8be6\u7ec6\u7684\u5929\u6c14\u9884\u62a5 URL<\/span><br \/>\n    forecast_url <span class=\"token operator\">&#061;<\/span> points_data<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;properties&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;forecast&#034;<\/span><span class=\"token punctuation\">]<\/span><br \/>\n    <span class=\"token comment\"># \u53d1\u8d77\u5f02\u6b65\u8bf7\u6c42\u83b7\u53d6\u5177\u4f53\u7684\u5929\u6c14\u9884\u62a5\u6570\u636e<\/span><br \/>\n    forecast_data <span class=\"token operator\">&#061;<\/span> <span class=\"token keyword\">await<\/span> make_nws_request<span class=\"token punctuation\">(<\/span>forecast_url<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5982\u679c\u8be6\u7ec6\u9884\u62a5\u6570\u636e\u4e3a\u7a7a&#xff0c;\u8fd4\u56de\u9519\u8bef\u63d0\u793a<\/span><br \/>\n    <span class=\"token keyword\">if<\/span> <span class=\"token keyword\">not<\/span> forecast_data<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;Unable to fetch detailed forecast.&#034;<\/span><\/p>\n<p>    <span class=\"token comment\"># \u63d0\u53d6\u5404\u65f6\u95f4\u6bb5\u7684\u9884\u62a5\u4fe1\u606f<\/span><br \/>\n    periods <span class=\"token operator\">&#061;<\/span> forecast_data<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;properties&#034;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">[<\/span><span class=\"token string\">&#034;periods&#034;<\/span><span class=\"token punctuation\">]<\/span><br \/>\n    forecasts <span class=\"token operator\">&#061;<\/span> <span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">]<\/span><\/p>\n<p>    <span class=\"token comment\"># \u904d\u5386\u524d5\u4e2a\u65f6\u95f4\u6bb5&#xff0c;\u683c\u5f0f\u5316\u8f93\u51fa\u5929\u6c14\u4fe1\u606f<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> period <span class=\"token keyword\">in<\/span> periods<span class=\"token punctuation\">[<\/span><span class=\"token punctuation\">:<\/span><span class=\"token number\">5<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">:<\/span>  <span class=\"token comment\"># \u53ea\u663e\u793a\u6700\u8fd15\u4e2a\u65f6\u95f4\u6bb5<\/span><br \/>\n        forecast <span class=\"token operator\">&#061;<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f&#034;&#034;&#034;<br \/>\n<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>period<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;name&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">:                    # \u65f6\u95f4\u6bb5\u540d\u79f0&#xff08;\u5982 Tonight, Thursday&#xff09;<br \/>\nTemperature: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>period<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;temperature&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\u00b0<\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>period<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;temperatureUnit&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">   # \u6e29\u5ea6\u53ca\u5355\u4f4d<br \/>\nWind: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>period<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;windSpeed&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\"> <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>period<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;windDirection&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">             # \u98ce\u901f\u548c\u98ce\u5411<br \/>\nForecast: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<\/span>period<span class=\"token punctuation\">[<\/span><span class=\"token string\">&#039;detailedForecast&#039;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">                            # \u8be6\u7ec6\u9884\u62a5\u63cf\u8ff0<br \/>\n&#034;&#034;&#034;<\/span><\/span><br \/>\n        forecasts<span class=\"token punctuation\">.<\/span>append<span class=\"token punctuation\">(<\/span>forecast<span class=\"token punctuation\">)<\/span>  <span class=\"token comment\"># \u5c06\u6bcf\u4e2a\u65f6\u95f4\u6bb5\u7684\u9884\u62a5\u6dfb\u52a0\u5230\u5217\u8868<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5c06\u591a\u4e2a\u65f6\u95f4\u6bb5\u7684\u9884\u62a5\u4fe1\u606f\u7528 &#034;&#8212;&#034; \u5206\u9694\u540e\u62fc\u63a5\u6210\u5b57\u7b26\u4e32\u8fd4\u56de<\/span><br \/>\n    <span class=\"token keyword\">return<\/span> <span class=\"token string\">&#034;\\\\n&#8212;\\\\n&#034;<\/span><span class=\"token punctuation\">.<\/span>join<span class=\"token punctuation\">(<\/span>forecasts<span class=\"token punctuation\">)<\/span><\/p>\n<h5>\u8fd0\u884c\u670d\u52a1\u5668<\/h5>\n<p>\u6700\u540e&#xff0c;\u8ba9\u6211\u4eec\u521d\u59cb\u5316\u5e76\u8fd0\u884c\u670d\u52a1\u5668&#xff1a;<\/p>\n<p><span class=\"token comment\"># \u5982\u679c\u8be5\u6587\u4ef6\u4f5c\u4e3a\u4e3b\u7a0b\u5e8f\u8fd0\u884c&#xff0c;\u5219\u6267\u884c\u4ee5\u4e0b\u4ee3\u7801<\/span><br \/>\n<span class=\"token keyword\">if<\/span> __name__ <span class=\"token operator\">&#061;&#061;<\/span> <span class=\"token string\">&#034;__main__&#034;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u521d\u59cb\u5316\u5e76\u8fd0\u884c FastMCP \u670d\u52a1\u5668&#xff0c;\u4f7f\u7528\u6807\u51c6\u8f93\u5165\u8f93\u51fa&#xff08;stdio&#xff09;\u4f5c\u4e3a\u901a\u4fe1\u534f\u8bae<\/span><br \/>\n    mcp<span class=\"token punctuation\">.<\/span>run<span class=\"token punctuation\">(<\/span>transport<span class=\"token operator\">&#061;<\/span><span class=\"token string\">&#039;stdio&#039;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u4f60\u7684\u670d\u52a1\u5668\u5df2\u7ecf\u5b8c\u6210&#xff01;\u8fd0\u884c uv run weather.py \u786e\u8ba4\u4e00\u5207\u6b63\u5e38\u3002<\/p>\n<p>\u73b0\u5728\u4ece\u73b0\u6709\u7684 MCP \u4e3b\u673a Claude for Desktop \u6d4b\u8bd5\u4f60\u7684\u670d\u52a1\u5668\u3002<\/p>\n<h3>\u4f7f\u7528 Claude \u684c\u9762\u8f6f\u4ef6\u5ba2\u6237\u7aef \u6d4b\u8bd5\u670d\u52a1\u5668<\/h3>\n<p>Claude for Desktop \u76ee\u524d\u5c1a\u672a\u5728 Linux \u4e0a\u63d0\u4f9b\u3002Linux \u7528\u6237\u53ef\u4ee5\u7ee7\u7eed\u9605\u8bfb \u6784\u5efa\u5ba2\u6237\u7aef \u6559\u7a0b&#xff0c;\u4ee5\u6784\u5efa\u4e00\u4e2a\u8fde\u63a5\u5230\u6211\u4eec\u521a\u521a\u6784\u5efa\u7684\u670d\u52a1\u5668\u7684 MCP \u5ba2\u6237\u7aef\u3002<\/p>\n<p>\u4f60\u9700\u8981\u5b89\u88c5\u597d Claude \u684c\u9762\u8f6f\u4ef6&#xff0c;\u8bf7\u4ece\u5b98\u7f51\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u3002<\/p>\n<h4>\u6dfb\u52a0\u670d\u52a1<\/h4>\n<p>\u6211\u4eec\u9700\u8981\u4e3a\u60f3\u8981\u4f7f\u7528\u7684\u4efb\u610f MCP \u670d\u52a1\u5668\u914d\u7f6e Claude for Desktop\u3002\u4e3a\u6b64&#xff0c;\u8bf7\u5728\u6587\u672c\u7f16\u8f91\u5668\u4e2d\u6253\u5f00\u60a8\u7684 Claude for Desktop App \u914d\u7f6e\u6587\u4ef6 ~\/Library\/Application Support\/Claude\/claude_desktop_config.json&#xff08;\u8f6f\u4ef6\u5b89\u88c5\u5728\u82f9\u679c\u7cfb\u7edf\u4e2d\u7684\u8def\u5f84&#xff09; \u3002\u5982\u679c\u6587\u4ef6\u4e0d\u5b58\u5728&#xff0c;\u8bf7\u786e\u4fdd\u521b\u5efa\u8be5\u6587\u4ef6\u3002<\/p>\n<p>~\/AppData\\\\Claude\\\\claude_desktop_config.json&#xff08;window\u7cfb\u7edf\u7684\u914d\u7f6e\u6587\u4ef6\u8def\u5f84&#xff09;<\/p>\n<p>\u7136\u540e\u60a8\u5c06\u5728 mcpServers \u952e\u4e2d\u6dfb\u52a0\u60a8\u7684\u670d\u52a1\u5668\u3002\u53ea\u6709\u5728\u81f3\u5c11\u914d\u7f6e\u4e86\u4e00\u4e2a\u670d\u52a1\u5668\u7684\u60c5\u51b5\u4e0b&#xff0c;MCP UI \u5143\u7d20\u624d\u4f1a\u5728 Claude for Desktop \u4e2d\u663e\u793a\u3002<\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b&#xff0c;\u6211\u4eec\u5c06\u50cf\u8fd9\u6837\u6dfb\u52a0\u6211\u4eec\u7684\u5355\u4e2a\u5929\u6c14\u670d\u52a1\u5668&#xff1a;<\/p>\n<p>\u82f9\u679c\u7cfb\u7edf\u4e0b\u7684\u914d\u7f6e<\/p>\n<p><span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token string\">&#034;mcpServers&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token string\">&#034;weather&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token string\">&#034;command&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;uv&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token string\">&#034;args&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n                <span class=\"token string\">&#034;&#8211;directory&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                <span class=\"token string\">&#034;\/ABSOLUTE\/PATH\/TO\/PARENT\/FOLDER\/weather&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                <span class=\"token string\">&#034;run&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                <span class=\"token string\">&#034;weather.py&#034;<\/span><br \/>\n            <span class=\"token punctuation\">]<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>window\u7cfb\u7edf\u4e0b\u7684\u914d\u7f6e<\/p>\n<p><span class=\"token punctuation\">{<\/span><br \/>\n    <span class=\"token string\">&#034;mcpServers&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n        <span class=\"token string\">&#034;weather&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">{<\/span><br \/>\n            <span class=\"token string\">&#034;command&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token string\">&#034;uv&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n            <span class=\"token string\">&#034;args&#034;<\/span><span class=\"token operator\">:<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n                <span class=\"token string\">&#034;&#8211;directory&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                <span class=\"token string\">&#034;C:\\\\\\\\ABSOLUTE\\\\\\\\PATH\\\\\\\\TO\\\\\\\\PARENT\\\\\\\\FOLDER\\\\\\\\weather&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                <span class=\"token string\">&#034;run&#034;<\/span><span class=\"token punctuation\">,<\/span><br \/>\n                <span class=\"token string\">&#034;weather.py&#034;<\/span><br \/>\n            <span class=\"token punctuation\">]<\/span><br \/>\n        <span class=\"token punctuation\">}<\/span><br \/>\n    <span class=\"token punctuation\">}<\/span><br \/>\n<span class=\"token punctuation\">}<\/span><\/p>\n<p>\u60a8\u53ef\u80fd\u9700\u8981\u5728 command \u5b57\u6bb5\u4e2d\u8f93\u5165 uv \u53ef\u6267\u884c\u6587\u4ef6\u7684\u5b8c\u6574\u8def\u5f84\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728 MacOS\/Linux \u4e0a\u8fd0\u884c which uv \u6216\u5728 Windows \u4e0a\u8fd0\u884c where uv \u6765\u83b7\u53d6\u5b83\u3002\u786e\u4fdd\u4f60\u4f20\u9012\u7684\u662f\u670d\u52a1\u5668\u7684\u7edd\u5bf9\u8def\u5f84\u3002<\/p>\n<p>\u8fd9\u544a\u8bc9 Claude\u684c\u9762\u8f6f\u4ef6&#xff1a;<\/p>\n<ul>\n<li>\u6709\u4e00\u4e2a\u540d\u4e3a\u201cweather\u201d\u7684 MCP \u670d\u52a1\u5668<\/li>\n<li>\u901a\u8fc7\u8fd0\u884c uv &#8211;directory \/ABSOLUTE\/PATH\/TO\/PARENT\/FOLDER\/weather run weather.py \u6765\u542f\u52a8\u5b83\u3002<\/li>\n<\/ul>\n<p>\u4fdd\u5b58\u6587\u4ef6&#xff0c;\u5e76\u91cd\u542f Claude \u684c\u9762\u8f6f\u4ef6\u3002<\/p>\n<h4>\u5224\u65ad\u670d\u52a1\u662f\u5426\u6dfb\u52a0\u6210\u529f<\/h4>\n<p>\u8ba9\u6211\u4eec\u786e\u4fdd Desktop \u7248\u672c\u7684 Claude \u80fd\u591f\u8bc6\u522b\u6211\u4eec\u5728 weather \u670d\u52a1\u5668\u4e2d\u66b4\u9732\u7684\u4e24\u4e2a\u5de5\u5177\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u67e5\u627e\u9524\u5b50 \u56fe\u6807\u6765\u786e\u8ba4\u8fd9\u4e00\u70b9\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091120-6827013822c15.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u70b9\u51fb\u9524\u5b50\u56fe\u6807\u540e&#xff0c;\u4f60\u5e94\u8be5\u770b\u5230\u5217\u51fa\u7684\u4e24\u79cd\u5de5\u5177&#xff1a;<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091120-682701382e684.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u5982\u679c\u9524\u5b50\u56fe\u6807\u5df2\u51fa\u73b0&#xff0c;\u60a8\u73b0\u5728\u53ef\u4ee5\u901a\u8fc7\u5728 Claude for Desktop \u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u6d4b\u8bd5\u60a8\u7684\u670d\u52a1\u5668:<\/p>\n<ul>\n<li>What\u2019s the weather in Sacramento?<\/li>\n<li>What are the active weather alerts in Texas?<\/li>\n<\/ul>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091120-682701383fca2.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091120-682701389d8e3.png\" alt=\"\u5728\u8fd9\u91cc\u63d2\u5165\u56fe\u7247\u63cf\u8ff0\" \/><\/p>\n<p>\u4e0b\u4e00\u671f\u8bb2\u89e3&#xff1a;\u5982\u4f55\u6784\u5efaMCP\u5ba2\u6237\u7aef&#xff0c;\u6b22\u8fce\u5173\u6ce8~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb908\u6b21\uff0c\u70b9\u8d5e8\u6b21\uff0c\u6536\u85cf20\u6b21\u3002\u6587\u7ae0\u8bb0\u5f55\u5982\u4f55\u521b\u5efaMCP\u670d\u52a1\u5668_\u521b\u5efa mcp<\/p>\n","protected":false},"author":2,"featured_media":37635,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3264,75,73],"topic":[],"class_list":["post-37648","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-claude","tag-llm","tag-mcp"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4e00\u6587\u8bfb\u61c2\u5982\u4f55\u4f7f\u7528MCP\u521b\u5efa\u670d\u52a1\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\/37648.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4e00\u6587\u8bfb\u61c2\u5982\u4f55\u4f7f\u7528MCP\u521b\u5efa\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb908\u6b21\uff0c\u70b9\u8d5e8\u6b21\uff0c\u6536\u85cf20\u6b21\u3002\u6587\u7ae0\u8bb0\u5f55\u5982\u4f55\u521b\u5efaMCP\u670d\u52a1\u5668_\u521b\u5efa mcp\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/37648.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-16T09:11:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091115-682701331b294.png\" \/>\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=\"7 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/37648.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/37648.html\",\"name\":\"\u4e00\u6587\u8bfb\u61c2\u5982\u4f55\u4f7f\u7528MCP\u521b\u5efa\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-16T09:11:22+00:00\",\"dateModified\":\"2025-05-16T09:11:22+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/37648.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/37648.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/37648.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4e00\u6587\u8bfb\u61c2\u5982\u4f55\u4f7f\u7528MCP\u521b\u5efa\u670d\u52a1\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":"\u4e00\u6587\u8bfb\u61c2\u5982\u4f55\u4f7f\u7528MCP\u521b\u5efa\u670d\u52a1\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\/37648.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4e00\u6587\u8bfb\u61c2\u5982\u4f55\u4f7f\u7528MCP\u521b\u5efa\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb908\u6b21\uff0c\u70b9\u8d5e8\u6b21\uff0c\u6536\u85cf20\u6b21\u3002\u6587\u7ae0\u8bb0\u5f55\u5982\u4f55\u521b\u5efaMCP\u670d\u52a1\u5668_\u521b\u5efa mcp","og_url":"https:\/\/www.wsisp.com\/helps\/37648.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-16T09:11:22+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250516091115-682701331b294.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"7 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/37648.html","url":"https:\/\/www.wsisp.com\/helps\/37648.html","name":"\u4e00\u6587\u8bfb\u61c2\u5982\u4f55\u4f7f\u7528MCP\u521b\u5efa\u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-16T09:11:22+00:00","dateModified":"2025-05-16T09:11:22+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/37648.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/37648.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/37648.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4e00\u6587\u8bfb\u61c2\u5982\u4f55\u4f7f\u7528MCP\u521b\u5efa\u670d\u52a1\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\/37648","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=37648"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/37648\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/37635"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=37648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=37648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=37648"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=37648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}