{"id":49832,"date":"2025-07-30T20:03:07","date_gmt":"2025-07-30T12:03:07","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/49832.html"},"modified":"2025-07-30T20:03:07","modified_gmt":"2025-07-30T12:03:07","slug":"%e4%bd%bf%e7%94%a8-elasticsearch-%e6%9e%84%e5%bb%ba%e4%b8%80%e4%b8%aa%e7%94%a8%e4%ba%8e%e7%9c%9f%e5%ae%9e%e5%81%a5%e5%ba%b7%e6%95%b0%e6%8d%ae%e7%9a%84-mcp-%e6%9c%8d%e5%8a%a1%e5%99%a8","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/49832.html","title":{"rendered":"\u4f7f\u7528 Elasticsearch \u6784\u5efa\u4e00\u4e2a\u7528\u4e8e\u771f\u5b9e\u5065\u5eb7\u6570\u636e\u7684 MCP \u670d\u52a1\u5668"},"content":{"rendered":"<p>\u4f5c\u8005&#xff1a;\u6765\u81ea Elastic\u00a0Alex Salgado<\/p>\n<p class=\"img-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"467\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120304-688a09f859b06.webp\" width=\"800\" \/><\/p>\n<p>\u5b66\u4e60\u5982\u4f55\u4f7f\u7528 FastMCP \u548c Elasticsearch \u6784\u5efa\u4e00\u4e2a MCP \u670d\u52a1\u5668\u6765\u7ba1\u7406\u548c\u641c\u7d22\u6570\u636e\u3002<\/p>\n<\/p>\n<p>Elasticsearch \u5177\u5907\u4e0e\u4e1a\u754c\u9886\u5148\u7684\u751f\u6210\u5f0f AI \u5de5\u5177\u548c\u670d\u52a1\u5546\u7684\u539f\u751f\u96c6\u6210\u3002\u67e5\u770b\u6211\u4eec\u7684\u7f51\u7edc\u7814\u8ba8\u4f1a&#xff0c;\u4e86\u89e3\u5982\u4f55\u8d85\u8d8a RAG \u57fa\u7840&#xff0c;\u6216\u4f7f\u7528 Elastic \u5411\u91cf\u6570\u636e\u5e93\u6784\u5efa\u53ef\u6295\u5165\u751f\u4ea7\u7684\u5e94\u7528\u3002<\/p>\n<p>\u4e3a\u4e86\u6784\u5efa\u6700\u9002\u5408\u4f60\u7528\u4f8b\u7684\u641c\u7d22\u89e3\u51b3\u65b9\u6848&#xff0c;\u73b0\u5728\u5c31\u5f00\u59cb\u514d\u8d39\u7684\u4e91\u8bd5\u7528&#xff0c;\u6216\u5728\u672c\u5730\u673a\u5668\u4e0a\u8bd5\u7528 Elastic\u3002<\/p>\n<hr \/>\n<p>\u5927\u578b\u8bed\u8a00\u6a21\u578b&#xff08;LLMs&#xff09;\u662f\u9769\u547d\u6027\u7684\u5de5\u5177&#xff0c;\u4f46\u5f53\u5b83\u4eec\u62e5\u6709\u5b9e\u65f6\u4e0a\u4e0b\u6587\u5e76\u80fd\u4e0e\u5916\u90e8\u4e16\u754c\u4ea4\u4e92\u65f6&#xff0c;\u5176\u771f\u6b63\u6f5c\u529b\u624d\u80fd\u88ab\u91ca\u653e\u3002\u6a21\u578b\u4e0a\u4e0b\u6587\u534f\u8bae&#xff08;Model Context Protocol &#8211;\u00a0MCP&#xff09;\u5c31\u50cf\u4e00\u5ea7\u6865\u6881&#xff0c;\u5c06\u4f60\u7684 LLM \u8fde\u63a5\u5230\u771f\u5b9e\u6570\u636e\u548c\u5916\u90e8\u5de5\u5177\u3002\u901a\u8fc7\u63d0\u4f9b\u8fd9\u4e9b\u4e0a\u4e0b\u6587&#xff0c;LLM \u80fd\u591f\u7ed9\u51fa\u66f4\u76f8\u5173\u3001\u66f4\u771f\u5b9e\u7684\u54cd\u5e94\u3002<\/p>\n<p>\u5c3d\u7ba1\u4f20\u7edf\u7684 RAG&#xff08;\u68c0\u7d22\u589e\u5f3a\u751f\u6210&#xff09;\u4e3a LLM \u63d0\u4f9b\u4e0a\u4e0b\u6587&#xff0c;\u4f46\u5b83\u901a\u5e38\u4f9d\u8d56\u4e8e\u9884\u5148\u5b58\u50a8\u5728\u6570\u636e\u5e93\u6216\u79c1\u6709\u6570\u636e\u96c6\u4e2d\u7684\u9759\u6001\u4fe1\u606f\u3002\u76f8\u6bd4\u4e4b\u4e0b&#xff0c;MCP \u53ef\u4ee5\u5c06\u6765\u81ea\u6570\u636e\u5e93\u3001API\u3001\u4f20\u611f\u5668\u548c\u5176\u4ed6\u6570\u636e\u6d41\u7b49\u5404\u79cd\u7cfb\u7edf\u7684\u52a8\u6001\u5b9e\u65f6\u4fe1\u606f\u4f5c\u4e3a\u4e0a\u4e0b\u6587\u5f15\u5165\u3002<\/p>\n<p>\u5728\u8fd9\u7bc7\u535a\u5ba2\u4e2d&#xff0c;\u4f60\u5c06\u5b66\u4e60\u5982\u4f55\u4f7f\u7528 FastMCP \u548c Elasticsearch \u6784\u5efa\u4e00\u4e2a MCP \u670d\u52a1\u5668\u6765\u7ba1\u7406\u548c\u641c\u7d22\u6570\u636e\u3002\u4f5c\u4e3a\u793a\u4f8b&#xff0c;\u6211\u4eec\u5c06\u4f7f\u7528 Apple Watch \u6570\u636e&#xff0c;\u6f14\u793a\u5982\u4f55\u5c06\u539f\u59cb\u4fe1\u606f\u8f6c\u5316\u4e3a\u667a\u80fd\u6d1e\u5bdf\u3002<\/p>\n<p>  <img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120304-688a09f8736b0.webp\" \/> <\/p>\n<p>   \u4f7f\u7528\u81ea\u7136\u8bed\u8a00\u4ee5\u82f1\u6587\u3001\u8461\u8404\u7259\u6587\u6216\u4e2d\u6587\u63d0\u51fa\u5173\u4e8e\u4f60\u6570\u636e\u7684\u590d\u6742\u95ee\u9898\u3002<\/p>\n<h2>\u4e3a\u4ec0\u4e48\u9009\u62e9 MCP&#xff1f;<\/h2>\n<p>MCP \u662f\u4e00\u4e2a\u5f00\u653e\u534f\u8bae&#xff0c;\u7528\u4e8e\u6807\u51c6\u5316 LLMs \u5982\u4f55\u4e0e\u5916\u90e8\u6570\u636e\u6e90\u548c\u5de5\u5177\u4ea4\u4e92\u3002\u60f3\u4e86\u89e3\u8be6\u7ec6\u4ecb\u7ecd&#xff0c;\u8bf7\u53c2\u9605 JD Armada \u7684\u6587\u7ae0&#xff1a; MCP&#xff08;Model Context Protocol&#xff0c;\u6a21\u578b\u4e0a\u4e0b\u6587\u534f\u8bae&#xff09;\u7684\u5f53\u524d\u72b6\u6001\u3002<\/p>\n<\/p>\n<h3>MCP \u5728 LLM Agent \u5f00\u53d1\u4e2d\u7684\u4f18\u52bf<\/h3>\n<p>\u4f7f\u7528 MCP \u4e3a\u57fa\u4e8e LLM \u7684 Agent \u5f00\u53d1\u5e26\u6765\u591a\u4e2a\u4f18\u52bf&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u804c\u8d23\u5206\u79bb&#xff1a;MCP \u5c06\u4e0a\u4e0b\u6587\u903b\u8f91&#xff08;\u6570\u636e\u548c\u5de5\u5177&#xff09;\u4e0e LLM \u4ea4\u4e92\u5206\u79bb&#xff0c;\u4f7f\u5f00\u53d1\u66f4\u6709\u6761\u7406\u3002<\/p>\n<\/li>\n<li>\n<p>\u6807\u51c6\u5316&#xff1a;\u9075\u5faa\u6807\u51c6\u534f\u8bae&#xff0c;\u5f00\u53d1\u8005\u53ef\u4ee5\u6784\u5efa\u517c\u5bb9\u4efb\u4f55 MCP \u5ba2\u6237\u7aef\u7684\u5de5\u5177&#xff0c;\u65e0\u8bba\u4f7f\u7528\u54ea\u4e2a LLM\u3002<\/p>\n<\/li>\n<li>\n<p>\u53ef\u91cd\u7528\u6027&#xff1a;\u5df2\u521b\u5efa\u7684\u5de5\u5177\u548c\u8d44\u6e90\u53ef\u4ee5\u8f7b\u677e\u590d\u7528\u4e8e\u4e0d\u540c\u9879\u76ee\u548c\u4e0a\u4e0b\u6587\u4e2d\u3002<\/p>\n<\/li>\n<li>\n<p>\u53ef\u6269\u5c55\u6027&#xff1a;\u901a\u8fc7 MCP&#xff0c;\u53ef\u4ee5\u6a2a\u5411\u6269\u5c55&#xff0c;\u6dfb\u52a0\u66f4\u591a\u670d\u52a1\u5668\u4ee5\u5904\u7406\u4e0d\u540c\u7684\u77e5\u8bc6\u9886\u57df\u6216\u529f\u80fd\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>MCP \u7684\u4e09\u4e2a\u6838\u5fc3\u539f\u8bed<\/h3>\n<p>MCP \u5b9a\u4e49\u4e86\u4e09\u4e2a\u4e3b\u8981\u7ec4\u4ef6&#xff0c;\u7528\u4e8e\u5efa\u7acb LLM \u4e0e\u5916\u90e8\u7cfb\u7edf\u4ea4\u4e92\u7684\u6807\u51c6&#xff1a;<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120304-688a09f8a223b.webp\" \/><\/p>\n<p>1) Resources&#xff1a;LLM \u7684 \u201c\u773c\u775b\u201d<\/p>\n<ul>\n<li>\n<p>\u529f\u80fd&#xff1a;\u901a\u8fc7\u76f4\u63a5\u66b4\u9732\u6570\u636e\u4e3a LLM \u63d0\u4f9b\u4e0a\u4e0b\u6587<\/p>\n<\/li>\n<li>\n<p>\u884c\u4e3a&#xff1a;\u7c7b\u4f3c REST API \u4e2d\u7684 GET \u7aef\u70b9&#xff0c;\u53ea\u8bfb\u53d6\u6570\u636e\u4e0d\u505a\u4fee\u6539<\/p>\n<\/li>\n<li>\n<p>\u793a\u4f8b&#xff1a; health:\/\/steps\/latest &#8211; \u83b7\u53d6\u6700\u65b0\u7684\u6b65\u6570\u8bb0\u5f55<\/p>\n<\/li>\n<li>\n<p>URI \u6a21\u5f0f&#xff1a;\u4f7f\u7528\u57df\u540d\u547d\u540d\u7a7a\u95f4\u6a21\u5f0f<\/p>\n<\/li>\n<\/ul>\n<p>2) Tools&#xff1a;LLM \u7684 \u201c\u624b\u201d<\/p>\n<ul>\n<li>\n<p>\u529f\u80fd&#xff1a;\u652f\u6301\u6267\u884c\u64cd\u4f5c\u548c\u8ba1\u7b97&#xff0c;\u662f\u5904\u7406\u590d\u6742\u67e5\u8be2\u548c\u5206\u6790\u7684\u5173\u952e<\/p>\n<\/li>\n<li>\n<p>\u884c\u4e3a&#xff1a;\u7c7b\u4f3c REST API \u4e2d\u7684 POST \u7aef\u70b9&#xff0c;\u4f1a\u6267\u884c\u64cd\u4f5c&#xff0c;\u53ef\u80fd\u6709\u526f\u4f5c\u7528<\/p>\n<\/li>\n<li>\n<p>\u7279\u70b9&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u63a5\u53d7\u7ed3\u6784\u5316\u53c2\u6570<\/p>\n<\/li>\n<li>\n<p>\u6839\u636e\u53c2\u6570\u6267\u884c\u52a8\u6001\u903b\u8f91<\/p>\n<\/li>\n<li>\n<p>\u4e3b\u52a8\u5904\u7406\u548c\u64cd\u4f5c\u6570\u636e&#xff0c;\u800c\u4e0d\u4ec5\u4ec5\u662f\u83b7\u53d6\u6570\u636e<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>3) Prompts&#xff1a;LLM \u7684 \u201c\u5730\u56fe\u201d&#xff08;MCP \u7279\u6709&#xff09;<\/p>\n<ul>\n<li>\n<p>\u529f\u80fd&#xff1a;\u4e3a\u5e38\u89c1\u4efb\u52a1\u63d0\u4f9b\u53ef\u91cd\u7528\u7684\u547d\u4ee4\u6a21\u677f&#xff0c;\u4e0e\u4f20\u7edf\u5c06\u7528\u6237\u8f93\u5165\u548c\u4efb\u52a1\u8bf4\u660e\u6df7\u5408\u7684 Prompt \u4e0d\u540c<\/p>\n<\/li>\n<li>\n<p>\u884c\u4e3a&#xff1a;\u4f5c\u4e3a\u5df2\u6ce8\u518c\u6a21\u677f\u51fa\u73b0&#xff0c;\u53ef\u4f5c\u4e3a\u659c\u6760\u547d\u4ee4\u4f7f\u7528<\/p>\n<\/li>\n<li>\n<p>\u793a\u4f8b&#xff1a;\/daily_report &#8211; \u89e6\u53d1\u9884\u8bbe\u7684\u5206\u6790\u5de5\u4f5c\u6d41<\/p>\n<\/li>\n<li>\n<p>\u76ee\u7684&#xff1a;\u89c4\u8303\u5e38\u89c1\u4ea4\u4e92\u4e0e\u5de5\u4f5c\u6d41\u7a0b<\/p>\n<\/li>\n<\/ul>\n<h2>\u6784\u5efa\u4f60\u81ea\u5df1\u7684 MCP \u670d\u52a1\u5668<\/h2>\n<\/p>\n<h3>\u89e3\u51b3\u65b9\u6848\u67b6\u6784<\/h3>\n<p>\u5728\u5f00\u59cb\u7f16\u7801\u4e4b\u524d&#xff0c;\u5148\u4e86\u89e3\u4e00\u4e0b\u6211\u4eec\u8981\u6784\u5efa\u7684\u5185\u5bb9&#xff1a;<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120304-688a09f8dbeae.webp\" \/><\/p>\n<p>\u6211\u4eec\u7684 MCP \u670d\u52a1\u5668\u5145\u5f53 LLM Agent \u548c\u4f60\u7684 Elasticsearch \u6570\u636e\u4e4b\u95f4\u7684\u6865\u6881&#xff0c;\u4f7f\u4f60\u80fd\u591f\u5bf9\u7ed3\u6784\u5316\u5065\u5eb7\u6570\u636e\u8fdb\u884c\u81ea\u7136\u8bed\u8a00\u67e5\u8be2\u3002<\/p>\n<\/p>\n<h3>\u524d\u63d0\u6761\u4ef6<\/h3>\n<p>\u672c\u6587\u5047\u8bbe\u4f60\u5df2\u5b89\u88c5\u4ee5\u4e0b\u6280\u672f&#xff1a;<\/p>\n<ul>\n<li>\n<p>Python 3.10&#043;<\/p>\n<\/li>\n<li>\n<p>Elasticsearch&#xff08;\u5feb\u901f\u5b89\u88c5\u6307\u5357&#xff09;<\/p>\n<\/li>\n<li>\n<p>Claude Desktop&#xff08;\u514d\u8d39\u4e0b\u8f7d&#xff09;<\/p>\n<\/li>\n<li>\n<p>Python \u7684 uv \u5305\u7ba1\u7406\u5668&#xff08;\u89c1\u5b89\u88c5\u8bf4\u660e&#xff09;<\/p>\n<\/li>\n<\/ul>\n<h3>\u5b8c\u6574\u9879\u76ee\u4ee3\u7801\u6258\u7ba1\u5728 GitHub<\/h3>\n<p>\u6574\u4e2a\u9879\u76ee\u5305\u542b\u811a\u672c\u548c\u793a\u4f8b\u6570\u636e&#xff0c;\u5747\u6258\u7ba1\u5728\u8fd9\u4e2a GitHub \u4ed3\u5e93\u4e2d\u3002\u5982\u679c\u4f60\u613f\u610f&#xff0c;\u53ef\u4ee5\u6309\u7167 README.md \u6587\u4ef6\u4e2d\u7684\u8bf4\u660e\u5feb\u901f\u5b8c\u6210\u73af\u5883\u642d\u5efa\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\u4e2d\u514b\u9686\u8be5\u4ed3\u5e93&#xff0c;\u4f7f\u7528\u8f85\u52a9\u811a\u672c\u5982 ingest_data.py \u6765\u51c6\u5907\u6570\u636e\u5e93&#xff0c;\u7136\u540e\u518d\u7ee7\u7eed\u540e\u7eed\u7ae0\u8282\u3002<\/p>\n<p>git clone https:\/\/github.com\/salgado\/apple-watch-health-mcp.git<br \/>\ncd apple-watch-health-mcp <\/p>\n<p>\u5f53\u4f60\u5217\u51fa\u6587\u4ef6\u5939\u5185\u5bb9&#xff08;\u4f7f\u7528 ls \u547d\u4ee4&#xff09;\u65f6&#xff0c;\u4f60\u5e94\u8be5\u770b\u5230\u4ee5\u4e0b\u6587\u4ef6&#xff1a;<\/p>\n<ul>\n<li>\n<p>apple_watch_mcp.py&#xff1a;MCP \u670d\u52a1\u5668\u7684\u5b8c\u6574\u811a\u672c&#xff0c;\u5305\u542b\u6240\u6709\u5b9e\u73b0\u7684 Resources\u3001Tools \u548c Prompts\u3002<\/p>\n<\/li>\n<li>\n<p>ingest_data.py&#xff1a;\u8f85\u52a9\u811a\u672c&#xff0c;\u7528\u4e8e\u5c06\u793a\u4f8b\u6570\u636e\u5bfc\u5165\u5230\u4f60\u7684 Elasticsearch \u5b9e\u4f8b\u3002<\/p>\n<\/li>\n<li>\n<p>sample_data.json&#xff1a;\u5305\u542b\u865a\u6784 Apple Health \u6b65\u6570\u6570\u636e\u7684\u793a\u4f8b JSON \u6587\u4ef6\u3002<\/p>\n<\/li>\n<li>\n<p>README.md&#xff1a;\u5b8c\u6574\u89e3\u51b3\u65b9\u6848\u7684\u8fd0\u884c\u8bf4\u660e\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u5728 Python \u4e2d\u8bbe\u7f6e FastMCP \u6846\u67b6<\/h3>\n<p>\u73b0\u5728&#xff0c;\u8ba9\u6211\u4eec\u4e3a MCP \u670d\u52a1\u5668\u642d\u5efa\u73af\u5883\u3002FastMCP \u662f\u4e00\u4e2a Python \u6846\u67b6&#xff0c;\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u4e0e MCP \u534f\u8bae\u517c\u5bb9\u7684\u5b8c\u6574\u670d\u52a1\u5668\u3002<\/p>\n<\/p>\n<h3>MCP &#043; Elasticsearch \u6709\u4e24\u79cd\u96c6\u6210\u65b9\u5f0f<\/h3>\n<p>\u5728\u6784\u5efa\u81ea\u5b9a\u4e49\u670d\u52a1\u5668\u4e4b\u524d&#xff0c;\u4e86\u89e3\u4e24\u79cd\u96c6\u6210 MCP \u4e0e Elasticsearch \u7684\u65b9\u5f0f\u5f88\u91cd\u8981&#xff1a;<\/p>\n<\/p>\n<p>1) \u5b98\u65b9\u65b9\u6848&#xff1a;\u4f7f\u7528 Elastic MCP Server<\/p>\n<ul>\n<li>\n<p>\u901a\u7528&#xff1a;\u9002\u7528\u4e8e\u5927\u591a\u6570\u7528\u4f8b<\/p>\n<\/li>\n<li>\n<p>\u914d\u7f6e\u7b80\u5355&#xff1a;\u5feb\u901f\u8f7b\u677e\u642d\u5efa<\/p>\n<\/li>\n<li>\n<p>\u5b9a\u5236\u6709\u9650&#xff1a;\u7279\u5b9a\u573a\u666f\u7075\u6d3b\u6027\u8f83\u4f4e<\/p>\n<\/li>\n<li>\n<p>\u64cd\u4f5c\u53d7\u9650&#xff1a;\u64b0\u5199\u65f6\u4ec5\u652f\u6301\u57fa\u672c\u67e5\u8be2\u64cd\u4f5c<\/p>\n<\/li>\n<li>\n<p>\u535a\u5ba2&#xff1a;\u5c06\u4ee3\u7406\u8fde\u63a5\u5230 Elasticsearch \u4f7f\u7528\u6a21\u578b\u4e0a\u4e0b\u6587\u534f\u8bae<\/p>\n<\/li>\n<\/ul>\n<p>2) \u81ea\u5b9a\u4e49\u65b9\u6848&#xff1a;\u6784\u5efa\u4f60\u81ea\u5df1\u7684 MCP \u670d\u52a1\u5668&#xff08;\u672c\u6587\u91cd\u70b9&#xff09;<\/p>\n<ul>\n<li>\n<p>\u9886\u57df\u4e13\u7528&#xff1a;\u9488\u5bf9\u7279\u5b9a\u7528\u4f8b\u4f18\u5316<\/p>\n<\/li>\n<li>\n<p>\u9700\u8981\u7f16\u7a0b&#xff1a;\u5f00\u53d1\u5de5\u4f5c\u91cf\u8f83\u5927<\/p>\n<\/li>\n<li>\n<p>\u5b8c\u5168\u63a7\u5236&#xff1a;\u529f\u80fd\u7075\u6d3b\u53ef\u63a7<\/p>\n<\/li>\n<\/ul>\n<p>\u9996\u5148&#xff0c;\u8fdb\u5165\u9879\u76ee\u6587\u4ef6\u5939&#xff0c;\u4f7f\u7528 uv \u7ba1\u7406\u4f9d\u8d56&#xff1a;<\/p>\n<p># Navigate to the repository folder<br \/>\ncd apple-watch-health-mcp<\/p>\n<p># Create and initialize a new project<br \/>\nuv init <\/p>\n<p># Create and activate a virtual environment<br \/>\nuv venv<br \/>\nsource .venv\/bin\/activate <\/p>\n<p># Install required dependencies<br \/>\nuv add &#034;mcp[cli]&#034; &#034;elasticsearch&gt;&#061;8.0.0,&lt;9.0.0&#034; aiohttp pydantic<\/p>\n<p># Set up environment variable for API key (after creating it in Elasticsearch)<br \/>\nexport ES_API_KEY&#061;&#034;your_encoded_api_key_here&#034; <\/p>\n<p>\u6ce8\u610f&#xff0c;\u6211\u4eec\u6307\u5b9a\u4e86\u4e0e\u672c\u535a\u5ba2\u4e2d\u4f7f\u7528\u7684 Elasticsearch v8.x \u670d\u52a1\u5668\u517c\u5bb9\u7684\u5e93\u7248\u672c\u3002<\/p>\n<\/p>\n<h2>\u7528\u4f8b&#xff1a;\u57fa\u4e8e Apple HealthKit \u6570\u636e\u7684\u77e5\u8bc6\u5e93\u52a9\u624b<\/h2>\n<p>  <img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120305-688a09f9230d3.webp\" \/> <\/p>\n<p>   \u56fe\u7247\u6765\u6e90\u6539\u7f16\u81ea Norah Sakal&#xff1a;<br \/>\n   What is Model Context Protocol (MCP)? How it simplifies AI integrations compared to APIs | AI Agents That Work<\/p>\n<h3>\u5bfc\u51fa Apple Watch \u6570\u636e<\/h3>\n<p>\u8981\u83b7\u53d6 Apple HealthKit \u6570\u636e&#xff0c;\u8bf7\u53c2\u9605 Apple \u5b98\u65b9\u5bfc\u51fa\u6307\u5357\u3002\u5bfc\u51fa\u4f1a\u751f\u6210\u5305\u542b\u6240\u6709\u5065\u5eb7\u8bb0\u5f55\u7684 XML \u6587\u4ef6\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120305-688a09f94a99a.webp\" \/><\/p>\n<\/p>\n<h3>\u4f7f\u7528\u793a\u4f8b\u6570\u636e\u8bbe\u7f6e Elasticsearch<\/h3>\n<p>\u5728\u521b\u5efa MCP \u670d\u52a1\u5668\u4e4b\u524d&#xff0c;\u6211\u4eec\u9700\u8981\u7528\u793a\u4f8b\u6570\u636e\u51c6\u5907 Elasticsearch\u3002\u4ed3\u5e93\u4e2d\u5df2\u5305\u542b\u4e00\u4e2a\u82f9\u679c\u5065\u5eb7\u6b65\u6570\u6570\u636e\u6587\u4ef6&#xff08;sample_data.json&#xff09;\u548c\u4e00\u4e2a\u5bfc\u5165\u811a\u672c&#xff08;ingest_data.py&#xff09;\u3002 \u8981\u51c6\u5907 Elasticsearch&#xff0c;\u8bf7\u5728\u7ec8\u7aef\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff1a;<\/p>\n<p># Set the environment variable with Elasticsearch API KEY<br \/>\nexport ES_API_KEY&#061;&#034;ES_API_KEY&#034;<br \/>\npython ingest_data.py <\/p>\n<p>\u8be5\u811a\u672c\u5c06\u4f1a&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u8fde\u63a5\u5230 http:\/\/localhost:9200 \u7684 Elasticsearch<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528\u6b63\u786e\u7684\u6620\u5c04\u521b\u5efa\u7d22\u5f15<\/p>\n<\/li>\n<li>\n<p>\u4ece JSON \u6587\u4ef6\u63d2\u5165\u6570\u636e<\/p>\n<\/li>\n<\/ul>\n<p>\u5982\u679c\u4f60\u60f3\u4f7f\u7528\u5176\u4ed6\u8fde\u63a5\u9009\u9879&#xff0c;\u6bd4\u5982 Elastic Cloud&#xff0c;\u8bf7\u67e5\u9605\u76f8\u5173\u6587\u6863\u3002\u9ed8\u8ba4\u914d\u7f6e\u4f7f\u7528&#xff1a;<\/p>\n<p>ES_HOST &#061; &#034;http:\/\/localhost:9200&#034;<br \/>\nES_INDEX &#061; &#034;apple-health-steps&#034;<br \/>\nES_API_KEY &#061; os.getenv(&#039;ES_API_KEY&#039;) <\/p>\n<p>\u8fc7\u7a0b\u7ed3\u675f\u65f6\u4f60\u5e94\u8be5\u4f1a\u770b\u5230\u6210\u529f\u6d88\u606f\u3002<\/p>\n<p>Connecting to Elasticsearch at http:\/\/localhost:9200&#8230;<br \/>\nConnection successful!<br \/>\nIndex &#039;apple-health-steps&#039; found. Deleting&#8230;<br \/>\nIndex deleted.<br \/>\nCreating index &#039;apple-health-steps&#039; with the specified mapping&#8230;<br \/>\nIndex created successfully.<br \/>\nReading data from &#039;sample_data.json&#039; for ingestion&#8230;<br \/>\nIngestion complete. Documents successfully ingested: 68<br \/>\nFinal check: The index &#039;apple-health-steps&#039; now contains 68 documents. <\/p>\n<p>\u811a\u672c\u6267\u884c\u5b8c\u6210\u540e&#xff0c;\u7d22\u5f15\u5c06\u88ab\u521b\u5efa\u5e76\u586b\u5145\u793a\u4f8b\u6570\u636e\u3002\u8be5\u7d22\u5f15\u9075\u5faa\u4ee5\u4e0b\u6a21\u5f0f&#xff0c;\u5bf9\u5e94\u4ece Apple Watch \u5bfc\u51fa\u7684\u6b65\u6570\u6570\u636e XML \u6587\u4ef6\u4e2d\u7684\u5b57\u6bb5&#xff1a;<\/p>\n<p>GET \/apple-health-steps\/_mapping<br \/>\n{<br \/>\n  &#034;apple-health-steps&#034;: {<br \/>\n    &#034;mappings&#034;: {<br \/>\n      &#034;properties&#034;: {<br \/>\n        &#034;creationDate&#034;: { &#034;type&#034;: &#034;date&#034;, &#034;format&#034;: &#034;yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis&#034; },<br \/>\n        &#034;day&#034;: { &#034;type&#034;: &#034;date&#034;, &#034;format&#034;: &#034;yyyy-MM-dd&#034; },<br \/>\n        &#034;dayOfWeek&#034;: { &#034;type&#034;: &#034;keyword&#034; },<br \/>\n        &#034;deviceInfo&#034;: {<br \/>\n          &#034;properties&#034;: {<br \/>\n            &#034;hardware&#034;: { &#034;type&#034;: &#034;keyword&#034; },<br \/>\n            &#034;manufacturer&#034;: { &#034;type&#034;: &#034;keyword&#034; },<br \/>\n            &#034;model&#034;: { &#034;type&#034;: &#034;keyword&#034; },<br \/>\n            &#034;name&#034;: { &#034;type&#034;: &#034;keyword&#034; },<br \/>\n            &#034;software&#034;: { &#034;type&#034;: &#034;keyword&#034; }<br \/>\n          }<br \/>\n        },<br \/>\n        &#034;duration&#034;: { &#034;type&#034;: &#034;float&#034; },<br \/>\n        &#034;endDate&#034;: { &#034;type&#034;: &#034;date&#034;, &#034;format&#034;: &#034;yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis&#034; },<br \/>\n        &#034;hour&#034;: { &#034;type&#034;: &#034;integer&#034; },<br \/>\n        &#034;sourceName&#034;: { &#034;type&#034;: &#034;keyword&#034; },<br \/>\n        &#034;startDate&#034;: { &#034;type&#034;: &#034;date&#034;, &#034;format&#034;: &#034;yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis&#034; },<br \/>\n        &#034;type&#034;: { &#034;type&#034;: &#034;keyword&#034; },<br \/>\n        &#034;unit&#034;: { &#034;type&#034;: &#034;keyword&#034; },<br \/>\n        &#034;value&#034;: { &#034;type&#034;: &#034;float&#034; }<br \/>\n      }<br \/>\n    }<br \/>\n  }<br \/>\n} <\/p>\n<p>\u4ee5\u4e0b\u662f\u63d2\u5165\u7684\u6570\u636e\u793a\u4f8b&#xff1a;<\/p>\n<p>{<br \/>\n  &#034;type&#034;: &#034;HKQuantityTypeIdentifierStepCount&#034;,<br \/>\n  &#034;sourceName&#034;: &#034;Apple Watch&#034;,<br \/>\n  &#034;deviceInfo&#034;: {<br \/>\n    &#034;name&#034;: &#034;Apple Watch&#034;,<br \/>\n    &#034;manufacturer&#034;: &#034;Apple Inc.&#034;,<br \/>\n    &#034;model&#034;: &#034;Watch&#034;,<br \/>\n    &#034;hardware&#034;: &#034;Watch7,1&#034;,<br \/>\n    &#034;software&#034;: &#034;11.3.1&#034;<br \/>\n  },<br \/>\n  &#034;unit&#034;: &#034;count&#034;,<br \/>\n  &#034;creationDate&#034;: &#034;2025-06-01 08:11:04&#034;,<br \/>\n  &#034;startDate&#034;: &#034;2025-06-01 07:58:42&#034;,<br \/>\n  &#034;endDate&#034;: &#034;2025-06-01 07:59:10&#034;,<br \/>\n  &#034;value&#034;: 340,<br \/>\n  &#034;day&#034;: &#034;2025-06-01&#034;,<br \/>\n  &#034;dayOfWeek&#034;: &#034;Sunday&#034;,<br \/>\n  &#034;hour&#034;: 8,<br \/>\n  &#034;duration&#034;: 583<br \/>\n} <\/p>\n<p>\u6570\u636e\u5305\u542b\u6765\u81ea Apple Watch \u548c iPhone \u4e24\u4e2a\u6765\u6e90\u7684\u6b65\u6570\u8ba1\u6570&#xff0c;\u8bb0\u5f55\u4e86\u8be6\u7ec6\u7684\u65f6\u95f4\u6233\u548c\u8bbe\u5907\u4fe1\u606f\u3002<\/p>\n<p>\u6570\u636e\u5e93\u521b\u5efa\u5e76\u586b\u5145\u5b8c\u6210\u540e&#xff0c;\u6211\u4eec\u53ef\u4ee5\u5f00\u59cb\u6784\u5efa MCP \u670d\u52a1\u5668\u6765\u8bbf\u95ee\u8fd9\u4e9b\u6570\u636e\u3002<\/p>\n<\/p>\n<h2>\u6784\u5efa\u5065\u5eb7\u6570\u636e\u7684 MCP \u670d\u52a1\u5668<\/h2>\n<\/p>\n<h3>\u4f7f\u7528 FastMCP \u548c Pydantic \u8fdb\u884c\u521d\u59cb\u914d\u7f6e<\/h3>\n<p>\u8ba9\u6211\u4eec\u521b\u5efa\u4e00\u4e2a apple_watch_mcp.py \u6587\u4ef6&#xff0c;\u5305\u542b MCP \u670d\u52a1\u5668\u7684\u57fa\u672c\u7ed3\u6784&#xff1a;<\/p>\n<p># apple_watch_health_mcp.py<br \/>\nimport os<br \/>\nfrom typing import Any, Optional<br \/>\nimport json<br \/>\nfrom datetime import datetime<br \/>\nfrom pydantic import BaseModel, field_validator, ValidationError<br \/>\nfrom mcp.server.fastmcp import FastMCP<br \/>\nfrom elasticsearch import AsyncElasticsearch<br \/>\nfrom contextlib import asynccontextmanager<\/p>\n<p># Initialize FastMCP server<br \/>\nmcp &#061; FastMCP(&#034;apple-watch-steps&#034;)<\/p>\n<p># Constants<br \/>\nES_HOST &#061; &#034;http:\/\/localhost:9200&#034;<br \/>\nES_INDEX &#061; &#034;apple-health-steps&#034;<\/p>\n<p># API key from environment variable or fallback for development<br \/>\nES_API_KEY &#061; os.getenv(&#039;ES_API_KEY&#039;)<\/p>\n<p># Pydantic model for parameter validation<br \/>\nclass QueryStepDataParams(BaseModel):<br \/>\n    start_date: Optional[str] &#061; None<br \/>\n    end_date: Optional[str] &#061; None<br \/>\n    aggregation: Optional[str] &#061; None<br \/>\n    device: Optional[str] &#061; None<\/p>\n<p>    &#064;field_validator(&#039;start_date&#039;, &#039;end_date&#039;)<br \/>\n    def validate_date_format(cls, value):<br \/>\n        if value is None:<br \/>\n            return value<br \/>\n        try:<br \/>\n            datetime.strptime(value, &#034;%Y-%m-%d&#034;)<br \/>\n            return value<br \/>\n        except ValueError:<br \/>\n            raise ValueError(&#034;Invalid date format. Use YYYY-MM-DD&#034;)<\/p>\n<p>    &#064;field_validator(&#039;aggregation&#039;)<br \/>\n    def validate_aggregation(cls, value):<br \/>\n        valid_aggregations &#061; [&#034;hourly&#034;, &#034;daily&#034;, &#034;weekly&#034;, &#034;monthly&#034;, None]<br \/>\n        if value not in valid_aggregations:<br \/>\n            raise ValueError(f&#034;Invalid aggregation. Use one of: {valid_aggregations[:-1]}&#034;)<br \/>\n        return value<\/p>\n<p># Main function to run the server<br \/>\nif __name__ &#061;&#061; &#034;__main__&#034;:<br \/>\n    mcp.run() <\/p>\n<p>\u8fd9\u6bb5\u521d\u59cb\u4ee3\u7801\u8bbe\u7f6e\u4e86\u4e00\u4e2a\u540d\u4e3a \u201capple-watch-steps\u201d \u7684 MCP \u670d\u52a1\u5668&#xff0c;\u5e76\u5b9a\u4e49\u4e86\u4e00\u4e2a Pydantic \u6a21\u578b\u6765\u9a8c\u8bc1\u5de5\u5177\u4e2d\u4f7f\u7528\u7684\u53c2\u6570\u3002\u670d\u52a1\u5668\u5c06\u8fde\u63a5\u5230\u672c\u5730 Elasticsearch \u96c6\u7fa4&#xff0c;\u4f7f\u7528 \u201capple-health-steps\u201d \u7d22\u5f15\u3002<\/p>\n<\/p>\n<h3>\u8fde\u63a5 Elasticsearch&#xff1a;\u6211\u4eec\u7684\u6570\u636e\u6865\u6881<\/h3>\n<p>\u4e3a\u4e86\u4e0e Elasticsearch \u4ea4\u4e92&#xff0c;\u8ba9\u6211\u4eec\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u8f85\u52a9\u51fd\u6570&#xff1a;<\/p>\n<p>&#064;asynccontextmanager<br \/>\nasync def get_es_client():<br \/>\n    &#034;&#034;&#034;Context manager for Elasticsearch client.&#034;&#034;&#034;<br \/>\n    client &#061; AsyncElasticsearch([ES_HOST], api_key&#061;ES_API_KEY)<br \/>\n    try:<br \/>\n        yield client<br \/>\n    finally:<br \/>\n        await client.close()<\/p>\n<p># Elasticsearch helper function<br \/>\nasync def query_elasticsearch(query: dict) -&gt; dict[str, Any] | None:<br \/>\n    &#034;&#034;&#034;Makes a request to Elasticsearch with proper error handling.&#034;&#034;&#034;<br \/>\n    print(f&#034;Sending query to Elasticsearch: {json.dumps(query)}&#034;)<\/p>\n<p>    # Use context manager<br \/>\n    async with get_es_client() as client:<br \/>\n        try:<br \/>\n            response &#061; await client.search(<br \/>\n                index&#061;ES_INDEX,<br \/>\n                body&#061;query<br \/>\n            )<br \/>\n            return response<br \/>\n        except Exception as e:<br \/>\n            print(f&#034;Error querying Elasticsearch: {e}&#034;)<br \/>\n            return None <\/p>\n<p>\u8be5\u5b9e\u73b0\u4f7f\u7528\u5b98\u65b9 Elasticsearch Python \u5ba2\u6237\u7aef\u4e2d\u7684 AsyncElasticsearch \u7c7b&#xff0c;\u652f\u6301\u5b8c\u6574\u7684 async\/await \u5f02\u6b65\u64cd\u4f5c\u3002\u91c7\u7528\u5f02\u6b65\u65b9\u5f0f\u66ff\u4ee3\u4f20\u7edf\u540c\u6b65\u5ba2\u6237\u7aef\u64cd\u4f5c&#xff0c;\u53ef\u4ee5\u907f\u514d\u957f\u65f6\u95f4\u4efb\u52a1\u963b\u585e\u4e3b\u7ebf\u7a0b&#xff0c;\u4f7f\u670d\u52a1\u5668\u54cd\u5e94\u66f4\u5feb\u3002\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\u6a21\u5f0f&#xff08;context manager pattern&#xff09;\u786e\u4fdd\u6bcf\u6b21\u64cd\u4f5c\u65f6\u8fde\u63a5\u6b63\u786e\u6253\u5f00\u548c\u5173\u95ed&#xff0c;\u9632\u6b62\u8d44\u6e90\u6cc4\u6f0f\u548c\u8fde\u63a5\u8b66\u544a\u3002\u51fd\u6570\u63a5\u6536\u4e00\u4e2a\u67e5\u8be2\u5b57\u5178&#xff0c;\u53d1\u9001\u5230 Elasticsearch&#xff0c;\u5e76\u8fd4\u56de JSON \u683c\u5f0f\u7ed3\u679c&#xff1b;\u5982\u679c\u51fa\u9519\u5219\u8fd4\u56de None\u3002<\/p>\n<\/p>\n<h3>MCP \u7684\u4e09\u5927\u652f\u67f1&#xff1a;Resources\u3001Tools \u548c Prompts<\/h3>\n<p>\u73b0\u5728\u6211\u4eec\u6765\u5b9e\u73b0 MCP \u7684 Resources\u3001Tools \u548c Prompts&#xff0c;\u6bcf\u4e2a\u7ec4\u4ef6\u6709\u5176\u7279\u5b9a\u89d2\u8272\u3002<\/p>\n<p>\u793a\u4f8b Resource&#xff1a;<\/p>\n<p>&#064;mcp.resource(&#034;health:\/\/steps\/latest&#034;)<br \/>\nasync def get_latest_steps() -&gt; str:<br \/>\n    &#034;&#034;&#034;Gets the most recent step records&#034;&#034;&#034;<br \/>\n    query &#061; {<br \/>\n        &#034;query&#034;: {<br \/>\n            &#034;match_all&#034;: {}<br \/>\n        },<br \/>\n        &#034;sort&#034;: [<br \/>\n            {&#034;endDate&#034;: {&#034;order&#034;: &#034;desc&#034;}}<br \/>\n        ],<br \/>\n        &#034;size&#034;: 10<br \/>\n    }<\/p>\n<p>    data &#061; await query_elasticsearch(query)<br \/>\n    if not data:<br \/>\n        return json.dumps({&#034;error&#034;: &#034;Unable to query Elasticsearch&#034;}, indent&#061;2)<\/p>\n<p>    results &#061; []<br \/>\n    for hit in data[&#034;hits&#034;][&#034;hits&#034;]:<br \/>\n        source &#061; hit[&#034;_source&#034;]<br \/>\n        results.append({<br \/>\n            &#034;startDate&#034;: source.get(&#034;startDate&#034;),<br \/>\n            &#034;endDate&#034;: source.get(&#034;endDate&#034;),<br \/>\n            &#034;value&#034;: source.get(&#034;value&#034;),<br \/>\n            &#034;device&#034;: source.get(&#034;device&#034;),<br \/>\n            &#034;sourceName&#034;: source.get(&#034;sourceName&#034;),<br \/>\n            &#034;dayOfWeek&#034;: source.get(&#034;dayOfWeek&#034;),<br \/>\n            &#034;hour&#034;: source.get(&#034;hour&#034;)<br \/>\n        })<\/p>\n<p>    return json.dumps({<br \/>\n        &#034;latest_steps&#034;: results<br \/>\n    }, indent&#061;2) <\/p>\n<p>\u8be5 Resource \u4f1a\u67e5\u8be2 Elasticsearch&#xff0c;\u83b7\u53d6\u6309\u7ed3\u675f\u65f6\u95f4\u6392\u5e8f\u7684\u6700\u8fd1 10 \u6761\u6b65\u6570\u8bb0\u5f55\u3002\u672c\u6587\u540e\u9762\u4f1a\u901a\u8fc7\u5b9e\u9645 Claude Desktop \u4ea4\u4e92\u793a\u4f8b\u5c55\u793a\u8f93\u51fa\u683c\u5f0f\u548c\u6570\u636e\u6548\u679c\u3002<\/p>\n<\/p>\n<h3>\u5065\u5eb7\u6570\u636e\u667a\u80fd\u52a9\u624b<\/h3>\n<p>\u6211\u4eec\u7684\u7528\u4f8b\u662f\u521b\u5efa\u4e00\u4e2a\u77e5\u8bc6\u5e93\u52a9\u624b&#xff0c;\u4f7f LLM Agent \u80fd\u4e0e Apple HealthKit \u5065\u5eb7\u6570\u636e\u4ea4\u4e92\u3002\u91cd\u70b9\u662f\u6b65\u6570\u6570\u636e&#xff0c;\u4f46\u540c\u6837\u65b9\u6cd5\u53ef\u6269\u5c55\u5230\u5176\u4ed6\u5065\u5eb7\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<p>\u8be5\u52a9\u624b\u5141\u8bb8\u7528\u6237&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u7528\u5bf9\u8bdd\u65b9\u5f0f\u67e5\u8be2\u6b65\u6570\u6570\u636e<\/p>\n<\/li>\n<li>\n<p>\u83b7\u53d6\u4e2a\u6027\u5316\u5206\u6790\u548c\u53ef\u89c6\u5316<\/p>\n<\/li>\n<li>\n<p>\u6bd4\u8f83\u4e0d\u540c\u8bbe\u5907\u7684\u6570\u636e<\/p>\n<\/li>\n<li>\n<p>\u8bc6\u522b\u957f\u671f\u8d8b\u52bf\u548c\u6a21\u5f0f<\/p>\n<\/li>\n<\/ul>\n<h3>\u5b9e\u73b0 Resources&#xff1a;\u6b65\u6570\u6570\u636e\u7684\u8bfb\u53d6\u7aef\u70b9<\/h3>\n<p>\u6211\u4eec\u7684 MCP \u670d\u52a1\u5668\u5c06\u5b9e\u73b0\u4e09\u4e2a\u4e3b\u8981 Resource&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u6570\u636e\u7c7b\u578b\u5217\u8868&#xff1a;\u663e\u793a\u6570\u636e\u5e93\u4e2d\u53ef\u7528\u7684\u6570\u636e\u7c7b\u578b<\/p>\n<\/li>\n<li>\n<p>\u6700\u8fd1\u6570\u636e\u83b7\u53d6&#xff1a;\u83b7\u53d6\u6700\u65b0\u7684\u6b65\u6570\u8bb0\u5f55<\/p>\n<\/li>\n<li>\n<p>\u7edf\u8ba1\u6c47\u603b&#xff1a;\u63d0\u4f9b\u6570\u636e\u6982\u89c8<\/p>\n<\/li>\n<\/ul>\n<p>\u8ba9\u6211\u4eec\u5f00\u59cb\u5b9e\u73b0\u8fd9\u4e9b Resources&#xff1a;<\/p>\n<p># Resources<br \/>\n&#064;mcp.resource(&#034;health:\/\/steps\/types&#034;)<br \/>\nasync def list_step_types() -&gt; str:<br \/>\n    &#034;&#034;&#034;List all available step types in the database&#034;&#034;&#034;<br \/>\n    query &#061; {<br \/>\n        &#034;size&#034;: 0,<br \/>\n        &#034;aggs&#034;: {<br \/>\n            &#034;step_types&#034;: {<br \/>\n                &#034;terms&#034;: {<br \/>\n                    &#034;field&#034;: &#034;type&#034;,<br \/>\n                    &#034;size&#034;: 100<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n    }<\/p>\n<p>    data &#061; await query_elasticsearch(query)<br \/>\n    if not data:<br \/>\n        return json.dumps({&#034;error&#034;: &#034;Unable to query Elasticsearch&#034;}, indent&#061;2)<\/p>\n<p>    step_types &#061; [bucket[&#034;key&#034;] for bucket in<br \/>\n                  data[&#034;aggregations&#034;][&#034;step_types&#034;][&#034;buckets&#034;]]<\/p>\n<p>    return json.dumps({<br \/>\n        &#034;available_types&#034;: step_types,<br \/>\n        &#034;count&#034;: len(step_types)<br \/>\n    }, indent&#061;2)<\/p>\n<p>&#064;mcp.resource(&#034;health:\/\/steps\/summary&#034;)<br \/>\nasync def get_steps_summary() -&gt; str:<br \/>\n    &#034;&#034;&#034;Get summary statistics for step counts&#034;&#034;&#034;<br \/>\n    query &#061; {<br \/>\n        &#034;aggs&#034;: {<br \/>\n            &#034;all_time&#034;: {<br \/>\n                &#034;stats&#034;: {<br \/>\n                    &#034;field&#034;: &#034;value&#034;<br \/>\n                }<br \/>\n            }<br \/>\n        },<br \/>\n        &#034;size&#034;: 0<br \/>\n    }<\/p>\n<p>    data &#061; await query_elasticsearch(query)<br \/>\n    if not data:<br \/>\n        return json.dumps({&#034;error&#034;: &#034;Unable to query Elasticsearch&#034;}, indent&#061;2)<\/p>\n<p>    return json.dumps(data[&#034;aggregations&#034;], indent&#061;2) <\/p>\n<h2>\u4e0e\u667a\u80fd RAG \u5e94\u7528\u96c6\u6210<\/h2>\n<\/p>\n<h3>Tools&#xff1a;\u5c06 MCP \u8fde\u63a5\u5230 RAG \u5de5\u4f5c\u6d41\u7a0b<\/h3>\n<p>\u4e3a\u4e86\u5c06\u6211\u4eec\u7684 MCP \u670d\u52a1\u5668\u4e0e RAG&#xff08;\u68c0\u7d22\u589e\u5f3a\u751f\u6210&#xff09;\u5de5\u4f5c\u6d41\u7a0b\u96c6\u6210&#xff0c;\u6211\u4eec\u9700\u8981\u5b9e\u73b0\u652f\u6301\u81ea\u5b9a\u4e49\u590d\u6742\u67e5\u8be2\u7684\u5de5\u5177\u3002\u4e0b\u56fe\u5c55\u793a\u4e86 MCP \u5982\u4f55\u878d\u5165\u5b8c\u6574\u7684 RAG \u6d41\u7a0b&#xff1a;<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120305-688a09f985b60.webp\" \/><\/p>\n<p>\u8be5\u56fe\u5c55\u793a\u4e86\u6211\u4eec\u7684 MCP \u670d\u52a1\u5668\u5982\u4f55\u5b8c\u7f8e\u878d\u5165 RAG \u6d41\u7a0b&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u7528\u6237\u63d0\u51fa\u5173\u4e8e\u5065\u5eb7\u6570\u636e\u7684\u95ee\u9898<\/p>\n<\/li>\n<li>\n<p>\u67e5\u8be2\u88ab RAG \u7cfb\u7edf\u5904\u7406<\/p>\n<\/li>\n<li>\n<p>\u68c0\u7d22\u9636\u6bb5\u4f7f\u7528 MCP \u7684 query_step_data \u5de5\u5177\u5728 Elasticsearch \u4e2d\u641c\u7d22\u76f8\u5173\u6570\u636e<\/p>\n<\/li>\n<li>\n<p>\u68c0\u7d22\u5230\u7684\u6570\u636e\u7528\u4e8e\u6784\u5efa\u4e0a\u4e0b\u6587\u5e76\u4e30\u5bcc\u56de\u590d\u5185\u5bb9<\/p>\n<\/li>\n<li>\n<p>LLM \u6839\u636e\u6570\u636e\u548c\u4e0a\u4e0b\u6587\u751f\u6210\u6700\u7ec8\u56de\u590d<\/p>\n<\/li>\n<\/ul>\n<p>\u8ba9\u6211\u4eec\u5b9e\u73b0\u8fd9\u4e2a\u6d41\u7a0b\u6240\u9700\u7684\u5de5\u5177&#xff1a;<\/p>\n<p># Tools<br \/>\n&#064;mcp.tool()<br \/>\nasync def query_step_data(params: QueryStepDataParams) -&gt; str:<br \/>\n    &#034;&#034;&#034;<br \/>\n    Query step data with customizable parameters<\/p>\n<p>    Args:<br \/>\n        start_date: Start date in YYYY-MM-DD format<br \/>\n        end_date: End date in YYYY-MM-DD format<br \/>\n        aggregation: Aggregation interval (hourly, daily, weekly, monthly)<br \/>\n        device: Filter by specific device name<br \/>\n    &#034;&#034;&#034;<br \/>\n    # Extract parameters from model<br \/>\n    start_date &#061; params.start_date or &#034;&#034;<br \/>\n    end_date &#061; params.end_date or &#034;&#034;<br \/>\n    aggregation &#061; params.aggregation or &#034;&#034;<br \/>\n    device &#061; params.device or &#034;&#034;<\/p>\n<p>    query &#061; {&#034;query&#034;: {&#034;match_all&#034;: {}}}<br \/>\n    filters &#061; []<\/p>\n<p>    # Date filters<br \/>\n    date_ranges &#061; []<br \/>\n    if start_date:<br \/>\n        date_ranges.append({&#034;gte&#034;: start_date})<br \/>\n    if end_date:<br \/>\n        date_ranges.append({&#034;lte&#034;: end_date})<\/p>\n<p>    if date_ranges:<br \/>\n        filters.append({<br \/>\n            &#034;range&#034;: {<br \/>\n                &#034;day&#034;: {**{k: v for d in date_ranges for k, v in d.items()}}<br \/>\n            }<br \/>\n        })<\/p>\n<p>    # Device filter<br \/>\n    if device:<br \/>\n        filters.append({<br \/>\n            &#034;wildcard&#034;: {<br \/>\n                &#034;device&#034;: f&#034;*{device}*&#034;<br \/>\n            }<br \/>\n        })<\/p>\n<p>    if filters:<br \/>\n        query[&#034;query&#034;] &#061; {&#034;bool&#034;: {&#034;must&#034;: filters}}<\/p>\n<p>    # Aggregation handling<br \/>\n    if aggregation:<br \/>\n        interval_mapping &#061; {<br \/>\n            &#034;hourly&#034;: &#034;1h&#034;,<br \/>\n            &#034;daily&#034;: &#034;1d&#034;,<br \/>\n            &#034;weekly&#034;: &#034;1w&#034;,<br \/>\n            &#034;monthly&#034;: &#034;1M&#034;<br \/>\n        }<br \/>\n        interval &#061; interval_mapping.get(aggregation, &#034;1d&#034;)<br \/>\n        date_field &#061; &#034;startDate&#034; if aggregation &#061;&#061; &#034;hourly&#034; else &#034;day&#034;<\/p>\n<p>        query[&#034;aggs&#034;] &#061; {<br \/>\n            &#034;time_series&#034;: {<br \/>\n                &#034;date_histogram&#034;: {<br \/>\n                    &#034;field&#034;: date_field,<br \/>\n                    &#034;calendar_interval&#034;: interval,<br \/>\n                    &#034;min_doc_count&#034;: 0<br \/>\n                },<br \/>\n                &#034;aggs&#034;: {<br \/>\n                    &#034;total_steps&#034;: {&#034;sum&#034;: {&#034;field&#034;: &#034;value&#034;}},<br \/>\n                    &#034;avg_steps&#034;: {&#034;avg&#034;: {&#034;field&#034;: &#034;value&#034;}},<br \/>\n                    &#034;max_steps&#034;: {&#034;max&#034;: {&#034;field&#034;: &#034;value&#034;}},<br \/>\n                    &#034;min_steps&#034;: {&#034;min&#034;: {&#034;field&#034;: &#034;value&#034;}}<br \/>\n                }<br \/>\n            }<br \/>\n        }<br \/>\n        query[&#034;size&#034;] &#061; 0<br \/>\n    else:<br \/>\n        query.update({<br \/>\n            &#034;sort&#034;: [{&#034;startDate&#034;: &#034;desc&#034;}],<br \/>\n            &#034;size&#034;: 10<br \/>\n        })<\/p>\n<p>    data &#061; await query_elasticsearch(query)<br \/>\n    if not data:<br \/>\n        return json.dumps({<br \/>\n            &#034;error&#034;: &#034;Unable to query Elasticsearch&#034;,<br \/>\n            &#034;query&#034;: query<br \/>\n        }, indent&#061;2)<\/p>\n<p>    # Process results<br \/>\n    results &#061; []<br \/>\n    if aggregation and &#034;time_series&#034; in data.get(&#034;aggregations&#034;, {}):<br \/>\n        for bucket in data[&#034;aggregations&#034;][&#034;time_series&#034;][&#034;buckets&#034;]:<br \/>\n            results.append({<br \/>\n                &#034;date&#034;: bucket[&#034;key_as_string&#034;],<br \/>\n                &#034;total_steps&#034;: bucket[&#034;total_steps&#034;][&#034;value&#034;],<br \/>\n                &#034;average_steps&#034;: bucket[&#034;avg_steps&#034;][&#034;value&#034;],<br \/>\n                &#034;max_steps&#034;: bucket[&#034;max_steps&#034;][&#034;value&#034;],<br \/>\n                &#034;min_steps&#034;: bucket[&#034;min_steps&#034;][&#034;value&#034;],<br \/>\n                &#034;records&#034;: bucket[&#034;doc_count&#034;]<br \/>\n            })<br \/>\n    else:<br \/>\n        for hit in data[&#034;hits&#034;][&#034;hits&#034;]:<br \/>\n            source &#061; hit[&#034;_source&#034;]<br \/>\n            results.append({<br \/>\n                &#034;startDate&#034;: source.get(&#034;startDate&#034;),<br \/>\n                &#034;endDate&#034;: source.get(&#034;endDate&#034;),<br \/>\n                &#034;day&#034;: source.get(&#034;day&#034;),<br \/>\n                &#034;dayOfWeek&#034;: source.get(&#034;dayOfWeek&#034;),<br \/>\n                &#034;hour&#034;: source.get(&#034;hour&#034;),<br \/>\n                &#034;value&#034;: source.get(&#034;value&#034;),<br \/>\n                &#034;device&#034;: source.get(&#034;device&#034;),<br \/>\n                &#034;sourceName&#034;: source.get(&#034;sourceName&#034;)<br \/>\n            })<\/p>\n<p>    return json.dumps({<br \/>\n        &#034;aggregation&#034;: aggregation,<br \/>\n        &#034;total_records&#034;: data[&#034;hits&#034;][&#034;total&#034;][&#034;value&#034;],<br \/>\n        &#034;data&#034;: results,<br \/>\n        &#034;query&#034;: query<br \/>\n    }, indent&#061;2)<\/p>\n<p>&#064;mcp.tool()<br \/>\nasync def get_all_steps() -&gt; str:<br \/>\n    &#034;&#034;&#034;Get all steps without any filtering&#034;&#034;&#034;<br \/>\n    query &#061; {<br \/>\n        &#034;query&#034;: {<br \/>\n            &#034;match_all&#034;: {}<br \/>\n        },<br \/>\n        &#034;size&#034;: 10,<br \/>\n        &#034;sort&#034;: [{&#034;startDate&#034;: &#034;desc&#034;}]<br \/>\n    }<\/p>\n<p>    data &#061; await query_elasticsearch(query)<br \/>\n    if not data:<br \/>\n        return json.dumps({&#034;error&#034;: &#034;Unable to query Elasticsearch&#034;}, indent&#061;2)<\/p>\n<p>    results &#061; []<br \/>\n    for hit in data[&#034;hits&#034;][&#034;hits&#034;]:<br \/>\n        source &#061; hit[&#034;_source&#034;]<br \/>\n        results.append({<br \/>\n            &#034;startDate&#034;: source.get(&#034;startDate&#034;),<br \/>\n            &#034;value&#034;: source.get(&#034;value&#034;),<br \/>\n            &#034;device&#034;: source.get(&#034;device&#034;)<br \/>\n        })<\/p>\n<p>    return json.dumps({<br \/>\n        &#034;total_records&#034;: data[&#034;hits&#034;][&#034;total&#034;][&#034;value&#034;],<br \/>\n        &#034;data&#034;: results<br \/>\n    }, indent&#061;2) <\/p>\n<p>\u8fd9\u4e9b\u5de5\u5177\u652f\u6301&#xff1a;<\/p>\n<ul>\n<li>\n<p>\u5e26\u65e5\u671f\u3001\u8bbe\u5907\u548c\u805a\u5408\u8fc7\u6ee4\u7684\u81ea\u5b9a\u4e49\u67e5\u8be2<\/p>\n<\/li>\n<li>\n<p>\u65e0\u8fc7\u6ee4\u6761\u4ef6\u7684\u5feb\u901f\u6700\u8fd1\u6570\u636e\u68c0\u7d22<\/p>\n<\/li>\n<\/ul>\n<h2>Prompts&#xff1a;\u4e0d\u540c LLM \u670d\u52a1\u5546\u7684\u914d\u7f6e<\/h2>\n<p>\u6211\u4eec\u7684 MCP \u670d\u52a1\u5668\u53ef\u4e0e\u4e0d\u540c LLM \u670d\u52a1\u5546\u914d\u5408\u4f7f\u7528\u3002\u4e3a\u4e86\u65b9\u4fbf\u96c6\u6210&#xff0c;\u8ba9\u6211\u4eec\u5b9e\u73b0\u4e00\u4e9b prompts&#xff0c;\u5e2e\u52a9 LLM \u6709\u6548\u5229\u7528\u6211\u4eec\u7684\u8d44\u6e90\u548c\u5de5\u5177&#xff1a;<\/p>\n<p>&#064;mcp.prompt()<br \/>\ndef daily_report(date: str &#061; None) -&gt; str:<br \/>\n    &#034;&#034;&#034;Create a daily step report for a specific date&#034;&#034;&#034;<br \/>\n    if date:<br \/>\n        return f&#034;&#034;&#034;Please analyze the step data for {date}.<br \/>\nProvide:<br \/>\n1. Total steps<br \/>\n2. Average steps per active hour<br \/>\n3. Most active periods of the day<br \/>\n4. Comparison with weekly average<br \/>\n5. Graphical visualization of the data, if possible&#034;&#034;&#034;<br \/>\n    else:<br \/>\n        return &#034;&#034;&#034;Please analyze the step data for today.<br \/>\nProvide:<br \/>\n1. Total steps so far<br \/>\n2. Average steps per active hour<br \/>\n3. Most active periods of the day<br \/>\n4. Comparison with weekly average<br \/>\n5. Graphical visualization of the data, if possible&#034;&#034;&#034;<\/p>\n<p>&#064;mcp.prompt()<br \/>\ndef trend_analysis(start_date: str, end_date: str) -&gt; str:<br \/>\n    &#034;&#034;&#034;Analyze step trends over a specific period&#034;&#034;&#034;<br \/>\n    return f&#034;&#034;&#034;Analyze step trends between {start_date} and {end_date}.<br \/>\nPlease include:<br \/>\n1. Daily step trend graph<br \/>\n2. Identification of weekly patterns<br \/>\n3. Days with highest and lowest activity<br \/>\n4. Progression over time<br \/>\n5. Recommendations based on the data&#034;&#034;&#034;<\/p>\n<p>&#064;mcp.prompt()<br \/>\ndef device_comparison() -&gt; str:<br \/>\n    &#034;&#034;&#034;Compare step data recorded by different devices&#034;&#034;&#034;<br \/>\n    return &#034;&#034;&#034;Compare step data recorded by Apple Watch and iPhone:<br \/>\n1. Which device records more steps on average?<br \/>\n2. Are there notable differences in usage patterns?<br \/>\n3. Times when each device is used more<br \/>\n4. Apparent accuracy of each device<br \/>\n5. Recommendations on which device to prioritize for tracking&#034;&#034;&#034; <\/p>\n<h2>\u4f7f\u7528 MCP Inspector \u6d4b\u8bd5\u670d\u52a1\u5668<\/h2>\n<p>\u5728\u5c06\u670d\u52a1\u5668\u8fde\u63a5\u5230\u771f\u5b9e\u7684 LLM \u5ba2\u6237\u7aef&#xff08;\u6bd4\u5982 Claude&#xff09;\u4e4b\u524d&#xff0c;\u6700\u597d\u5148\u5728\u53d7\u63a7\u73af\u5883\u4e2d\u8fdb\u884c\u6d4b\u8bd5\u3002mcp \u5e93\u81ea\u5e26\u4e00\u4e2a\u5f3a\u5927\u7684\u57fa\u4e8e\u7f51\u9875\u7684\u8c03\u8bd5\u5de5\u5177&#xff0c;\u53eb\u505a MCP Inspector\u3002\u5b83\u5141\u8bb8\u6211\u4eec\u4ea4\u4e92\u5f0f\u6d4b\u8bd5\u670d\u52a1\u5668&#xff0c;\u5b9e\u65f6\u67e5\u770b\u8bf7\u6c42\u548c\u54cd\u5e94&#xff0c;\u9a8c\u8bc1\u903b\u8f91&#xff0c;\u786e\u4fdd\u90e8\u7f72\u524d\u65e0\u8bef\u3002<\/p>\n<\/p>\n<h3>\u5982\u4f55\u542f\u52a8 Inspector<\/h3>\n<p>\u5728\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u7684\u7ec8\u7aef\u4e2d&#xff0c;\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4&#xff0c;\u540e\u63a5\u4f60\u7684\u811a\u672c\u540d\u79f0&#xff1a;<\/p>\n<p>mcp dev apple_watch_mcp.py <\/p>\n<p>\u4f60\u7b2c\u4e00\u6b21\u8fd0\u884c\u65f6&#xff0c;mcp \u53ef\u80fd\u4f1a\u8bf7\u6c42\u5b89\u88c5 Inspector \u7684\u7f51\u9875\u7ec4\u4ef6\u3002\u8fd9\u662f\u4e00\u6b21\u6027\u8bbe\u7f6e\u3002\u53ea\u9700\u8f93\u5165 y \u7136\u540e\u6309\u56de\u8f66\u5373\u53ef\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120305-688a09f9ae895.webp\" \/><\/p>\n<p>\u786e\u8ba4\u540e&#xff0c;\u8be5\u5de5\u5177\u4f1a\u542f\u52a8\u672c\u5730\u4ee3\u7406\u670d\u52a1\u5668&#xff0c;\u5e76\u81ea\u52a8\u5728\u9ed8\u8ba4\u6d4f\u89c8\u5668\u6253\u5f00 MCP Inspector \u754c\u9762&#xff0c;\u901a\u5e38\u5730\u5740\u662f http:\/\/127.0.0.1:6274\u3002<\/p>\n<p>\u8ba4\u8bc1\u8bf4\u660e&#xff1a;\u65b0\u7248 MCP Inspector \u53ef\u80fd\u9700\u8981\u8ba4\u8bc1\u4ee5\u4fdd\u969c\u5b89\u5168\u3002\u5982\u679c\u754c\u9762\u672a\u81ea\u52a8\u6253\u5f00&#xff0c;\u8bf7\u67e5\u770b\u7ec8\u7aef\u4e2d\u7684\u63d0\u793a\u4fe1\u606f&#xff0c;\u5982&#xff1a;<\/p>\n<p>Session token: xxxxx&#8230;<br \/>\nOpen inspector with token pre-filled:<br \/>\n   http:\/\/localhost:6274\/?MCP_PROXY_AUTH_TOKEN&#061;xxxxx&#8230; <\/p>\n<p>\u4f7f\u7528\u5e26\u6709\u4ee4\u724c\u7684\u5b8c\u6574 URL \u8bbf\u95ee Inspector\u3002\u8be5\u4ee4\u724c\u786e\u4fdd\u6d4b\u8bd5\u671f\u95f4\u5bf9\u670d\u52a1\u5668\u7684\u5b89\u5168\u8bbf\u95ee\u3002<\/p>\n<\/p>\n<h3>\u754c\u9762\u4ecb\u7ecd<\/h3>\n<p>MCP Inspector \u63d0\u4f9b\u4e86\u7b80\u6d01\u7684\u754c\u9762&#xff0c;\u65b9\u4fbf\u4f60\u63a2\u7d22\u548c\u4ea4\u4e92\u670d\u52a1\u5668\u529f\u80fd\u3002<\/p>\n<\/p>\n<h4>1&#xff09;\u521d\u59cb\u8fde\u63a5<\/h4>\n<p>\u9875\u9762\u52a0\u8f7d\u65f6&#xff0c;\u4f1a\u81ea\u52a8\u8fde\u63a5\u5230\u4f60\u8fd0\u884c\u7684 apple_watch_mcp.py \u811a\u672c\u3002\u5de6\u4fa7\u72b6\u6001\u4f1a\u4ece\u672a\u8fde\u63a5\u53d8\u4e3a\u201cRestart | Disconnect\u201d&#xff0c;\u5e76\u4e14 \u201cHistory\u201d \u9762\u677f\u4f1a\u663e\u793a\u4e00\u4e2a initialize \u4e8b\u4ef6\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120305-688a09f9cbaa6.webp\" \/><\/p>\n<\/p>\n<h4>2&#xff09;\u53d1\u73b0\u4f60\u7684\u529f\u80fd<\/h4>\n<p>Inspector \u7684\u6838\u5fc3\u5728\u9876\u90e8\u7684\u6807\u7b7e\u9875&#xff1a;Resources\u3001Prompts \u548c Tools\u3002<\/p>\n<ul>\n<li>Resources&#xff1a;\u70b9\u51fb \u201cResources\u201d \u6807\u7b7e\u9875\u3002\u70b9\u51fb \u201cList Resources\u201d \u6309\u94ae&#xff0c;\u53ef\u4ee5\u67e5\u770b\u4f60\u521b\u5efa\u7684\u6240\u6709\u6570\u636e\u7aef\u70b9&#xff0c;\u5b83\u4eec\u4f1a\u663e\u793a\u5728\u4e0b\u65b9\u9762\u677f\u4e2d\u3002<\/li>\n<\/ul>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120305-688a09f9f228b.webp\" \/><\/p>\n<ul>\n<li>Tools \u548c Prompts&#xff1a;\u4f60\u4e5f\u53ef\u4ee5\u5bf9\u5176\u5b83\u6807\u7b7e\u9875\u6267\u884c\u540c\u6837\u64cd\u4f5c\u3002\u70b9\u51fb \u201cTools\u201d \u518d\u70b9\u51fb \u201cList Tools\u201d \u4f1a\u663e\u793a\u4f60\u7684 query_step_data \u548c get_all_steps \u51fd\u6570\u3002\u201cPrompts\u201d \u6807\u7b7e\u9875\u5219\u4f1a\u5217\u51fa\u4f60\u9884\u5b9a\u4e49\u7684\u63d0\u793a\u6a21\u677f\u3002<\/li>\n<\/ul>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120306-688a09fa22c8b.webp\" \/><\/p>\n<\/p>\n<h4>3&#xff09;\u8fd0\u884c\u6d4b\u8bd5<\/h4>\n<p>\u8ba9\u6211\u4eec\u6d4b\u8bd5\u4e00\u4e2a\u7b80\u5355\u7684\u5de5\u5177&#xff0c;\u770b\u770b\u5b83\u7684\u8fd0\u884c\u6548\u679c\u3002<\/p>\n<ul>\n<li>\n<p>\u8fdb\u5165 Tools \u6807\u7b7e\u9875<\/p>\n<\/li>\n<li>\n<p>\u4ece\u5217\u8868\u4e2d\u70b9\u51fb\u4e00\u4e2a\u5de5\u5177&#xff0c;\u6bd4\u5982 get_all_steps<\/p>\n<\/li>\n<li>\n<p>\u53f3\u4fa7\u9762\u677f\u4f1a\u663e\u793a\u8be5\u5de5\u5177\u7684\u8be6\u7ec6\u4fe1\u606f\u3002\u56e0\u4e3a get_all_steps \u4e0d\u9700\u8981\u53c2\u6570&#xff0c;\u4f60\u53ea\u9700\u70b9\u51fb \u201cRun Tool\u201d \u6309\u94ae\u5373\u53ef\u3002<\/p>\n<\/li>\n<\/ul>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120306-688a09fa3a038.webp\" \/><\/p>\n<p>\u70b9\u51fb\u201cRun Tool\u201d\u540e&#xff0c;\u4f60\u670d\u52a1\u5668\u8fd4\u56de\u7684 JSON \u54cd\u5e94\u4f1a\u663e\u793a\u5728\u53f3\u4fa7\u9762\u677f\u4e2d\u3002\u4f60\u53ef\u4ee5\u68c0\u67e5\u6570\u636e\u662f\u5426\u6b63\u786e\u3001\u683c\u5f0f\u662f\u5426\u7b26\u5408\u9884\u671f&#xff0c;\u5e76\u67e5\u770b\u662f\u5426\u6709\u9519\u8bef\u3002\u5bf9\u4e8e\u9700\u8981\u53c2\u6570\u7684\u5de5\u5177&#xff08;\u5982 query_step_data&#xff09;&#xff0c;\u586b\u5199\u53c2\u6570\u540e\u70b9\u51fb\u201cRun\u201d\u5373\u53ef\u540c\u6837\u6d4b\u8bd5\u3002<\/p>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4&#xff0c;\u4f60\u53ef\u4ee5\u6d4b\u8bd5 MCP \u670d\u52a1\u5668\u7684\u5404\u4e2a\u90e8\u5206&#xff0c;\u786e\u4fdd\u5176\u7a33\u5b9a\u5e76\u51c6\u5907\u597d\u4e0e Claude Desktop \u96c6\u6210\u3002<\/p>\n<\/p>\n<h3>\u505c\u6b62\u6d4b\u8bd5\u670d\u52a1\u5668<\/h3>\n<p>mcp dev \u547d\u4ee4\u542f\u52a8\u7684\u662f\u7528\u4e8e\u8c03\u8bd5\u7684\u672c\u5730\u5f00\u53d1\u670d\u52a1\u5668\u3002\u786e\u8ba4 Resources\u3001Tools \u548c Prompts \u529f\u80fd\u6b63\u5e38\u540e&#xff0c;\u53ef\u4ee5\u505c\u6b62\u6d4b\u8bd5\u670d\u52a1\u5668\u3002<\/p>\n<p>\u65b9\u6cd5\u662f\u56de\u5230\u8fd0\u884c\u8be5\u8fdb\u7a0b\u7684\u7ec8\u7aef\u7a97\u53e3&#xff0c;\u6309 Ctrl&#043;C\u3002<\/p>\n<p>&#8230;<br \/>\nConnected MCP client to backing server transport<br \/>\nCreated client\/server transports<br \/>\nSet up MCP proxy<br \/>\n^C <\/p>\n<p>\u670d\u52a1\u5668\u6d4b\u8bd5\u5b8c\u6210\u540e&#xff0c;\u4e0b\u4e00\u6b65\u662f\u5728 Claude Desktop \u4e2d\u5b89\u88c5\u5b83&#xff0c;\u7531 Claude Desktop \u7ba1\u7406\u670d\u52a1\u5668\u7684\u8fd0\u884c\u3002<\/p>\n<\/p>\n<h2>\u6dfb\u52a0\u5230 LLM \u5ba2\u6237\u7aef&#xff1a;\u6700\u540e\u4e00\u6b65<\/h2>\n<\/p>\n<h3>\u4ec0\u4e48\u662f Claude Desktop&#xff1f;<\/h3>\n<p>\u4e3a\u4e86\u66f4\u5b9e\u7528\u548c\u76f4\u89c2\u5730\u4e0e MCP \u670d\u52a1\u5668\u4ea4\u4e92&#xff0c;\u6211\u4eec\u5c06\u4f7f\u7528 Claude Desktop \u4f5c\u4e3a MCP \u5ba2\u6237\u7aef\u3002\u4e0e\u4f20\u7edf\u547d\u4ee4\u884c\u5de5\u5177\u4e0d\u540c&#xff0c;MCP \u670d\u52a1\u5668\u9700\u8981\u517c\u5bb9 Model Context Protocol \u7684\u5ba2\u6237\u7aef&#xff0c;\u4e0d\u80fd\u76f4\u63a5\u8fd0\u884c\u547d\u4ee4\u3002Claude Desktop \u63d0\u4f9b\u4e86\u8fd9\u6837\u7684\u5ba2\u6237\u7aef\u754c\u9762&#xff0c;\u4f7f\u6211\u4eec\u53ef\u4ee5\u53d1\u9001 MCP \u670d\u52a1\u5668\u53ef\u5904\u7406\u7684\u81ea\u7136\u8bed\u8a00\u67e5\u8be2\u3002<\/p>\n<p>\u5b89\u88c5&#xff1a;\u4f60\u53ef\u4ee5\u5728 Meet Claude \\\\ Anthropic \u514d\u8d39\u4e0b\u8f7d Claude Desktop\u3002\u514d\u8d39\u7248\u672c\u5b8c\u5168\u8db3\u591f\u672c\u6587\u6d4b\u8bd5\u4f7f\u7528\u3002<\/p>\n<\/p>\n<h3>\u5728 Claude \u4e2d\u5b89\u88c5\u670d\u52a1\u5668<\/h3>\n<p>\u5b89\u88c5 Claude Desktop \u540e&#xff0c;\u6211\u4eec\u6765\u6ce8\u518c MCP \u670d\u52a1\u5668&#xff1a;<\/p>\n<p># Install the server for Claude Desktop<br \/>\nmcp install apple_watch_mcp.py &#8211;name &#034;Apple Health Steps&#034; <\/p>\n<p>\u786e\u8ba4\u5b89\u88c5\u662f\u5426\u6210\u529f<\/p>\n<p>\u73b0\u5728&#xff0c;\u8ba9\u6211\u4eec\u786e\u8ba4\u547d\u4ee4\u662f\u5426\u6309\u9884\u671f\u6267\u884c\u3002mcp install \u547d\u4ee4\u4f1a\u5411\u4e00\u4e2a JSON \u914d\u7f6e\u6587\u4ef6\u6dfb\u52a0\u6761\u76ee\u3002\u5982\u679c\u4f60\u4f7f\u7528\u4e86 API \u5bc6\u94a5&#xff0c;\u914d\u7f6e\u4e2d\u4f1a\u5305\u542b\u76f8\u5e94\u7684\u73af\u5883\u53d8\u91cf\u3002\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u8be5\u6587\u4ef6\u5185\u5bb9\u3002<\/p>\n<p>cat ~\/Library\/Application\\\\ Support\/Claude\/claude_desktop_config.json <\/p>\n<p>\u4f60\u5e94\u8be5\u4f1a\u5728\u6587\u4ef6\u4e2d\u770b\u5230\u7c7b\u4f3c\u5982\u4e0b\u7ed3\u6784&#xff0c;\u4f4d\u4e8e &#034;mcpServers&#034; \u952e\u4e0b&#xff1a;<\/p>\n<p>{<br \/>\n  &#034;mcpServers&#034;: {<br \/>\n    &#034;Apple Health Steps&#034;: {<br \/>\n      &#034;command&#034;: &#034;\/full\/path\/to\/your\/uv&#034;,<br \/>\n      &#034;args&#034;: [<br \/>\n        &#034;&#8211;directory&#034;,<br \/>\n        &#034;\/path\/to\/repository\/apple-watch-health-mcp&#034;,<br \/>\n        &#034;run&#034;,<br \/>\n        &#034;apple_watch_mcp.py&#034;<br \/>\n        \/\/ Other arguments may appear depending on your setup<br \/>\n      ],<br \/>\n      &#034;env&#034;: {<br \/>\n        &#034;ES_API_KEY&#034;: &#034;YOUR_ES_API_KEY&#034;<br \/>\n      }<br \/>\n    }<br \/>\n    \/\/ &#8230; other servers might be listed here<br \/>\n  }<br \/>\n} <\/p>\n<p>\u5982\u679c\u4f60\u627e\u5230\u4e86 \u201cApple Health Steps\u201d \u8fd9\u4e00\u5757&#xff0c;\u606d\u559c&#xff01;\u4f60\u7684\u670d\u52a1\u5668\u5df2\u6210\u529f\u914d\u7f6e\u3002<\/p>\n<p>\u91cd\u542f\u63d0\u9192<\/p>\n<p>\u91cd\u8981&#xff1a;\u5b89\u88c5\u670d\u52a1\u5668\u540e&#xff0c;\u9700\u8981\u91cd\u542f Claude Desktop \u4ee5\u52a0\u8f7d\u65b0\u914d\u7f6e\u3002<\/p>\n<ul>\n<li>\n<p>\u53ea\u6709\u6253\u5f00 Claude \u65f6\u670d\u52a1\u5668\u624d\u4f1a\u542f\u52a8\u3002<\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u51fa\u73b0\u6267\u884c\u9519\u8bef&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u5728 Claude Desktop \u67e5\u770b\u65e5\u5fd7\u3002<\/p>\n<\/li>\n<\/ul>\n<h3>\u4e0e Claude \u7684\u4ea4\u4e92\u793a\u4f8b<\/h3>\n<p>\u914d\u7f6e\u5b8c\u6210\u540e&#xff0c;\u6700\u6709\u8da3\u7684\u90e8\u5206\u6765\u4e86&#xff1a;\u4f7f\u7528\u81ea\u7136\u8bed\u8a00\u4e0e\u4f60\u7684 MCP \u670d\u52a1\u5668\u5bf9\u8bdd\u3002<\/p>\n<\/p>\n<h4>\u5f00\u59cb\u4e4b\u524d&#xff1a;\u51c6\u5907\u597d\u4f60\u7684\u73af\u5883<\/h4>\n<p>\u8981\u4e0e\u65b0\u670d\u52a1\u5668\u4ea4\u4e92&#xff0c;\u9700\u8981\u8fdb\u5165\u5ba2\u6237\u7aef\u754c\u9762\u3002\u6253\u5f00 Claude Desktop \u5e94\u7528&#xff0c;\u786e\u4fdd\u4f60\u5904\u4e8e\u4e3b\u804a\u5929\u754c\u9762\u3002<\/p>\n<p>\u8fd9\u91cc\u662f\u4f60\u63d0\u95ee\u7684\u5730\u65b9\u3002\u5c4f\u5e55\u5e94\u5982\u4e0b\u56fe\u6240\u793a&#xff0c;\u6587\u672c\u6846\u5185\u5df2\u7ecf\u6709\u6211\u4eec\u7684\u7b2c\u4e00\u4e2a\u95ee\u9898\u51c6\u5907\u597d\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120306-688a09fa47f8d.webp\" \/><\/p>\n<p>\u4e00\u5207\u51c6\u5907\u5c31\u7eea&#xff0c;\u5f00\u59cb\u5427\u3002<\/p>\n<\/p>\n<h4>\u793a\u4f8b 1&#xff1a;\u57fa\u7840\u5bf9\u8bdd&#xff08;RAG \u5b9e\u8df5&#xff09;<\/h4>\n<p>\u73b0\u5728&#xff0c;\u53ea\u9700\u6309 \u201cEnter\u201d \u53d1\u9001\u4f60\u8f93\u5165\u7684\u95ee\u9898\u3002\u8fd9\u662f RAG \u7684\u4e00\u4e2a\u5f88\u597d\u793a\u4f8b&#xff0c;\u6a21\u578b\u4f1a\u68c0\u7d22\u7279\u5b9a\u6570\u636e\u8fdb\u884c\u56de\u7b54\u3002<\/p>\n<p>\u4f60\u8f93\u5165&#xff1a;<\/p>\n<p>How many steps did I take last Thursday? <\/p>\n<p>\u671f\u671b\u7ed3\u679c&#xff1a;<\/p>\n<p>Last Thursday (June 5th), you took 5,360 steps total. Your step count ranged from 450 to 2,340 steps across 4 different recordings throughout the day.<\/p>\n<h4 style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120306-688a09fa6adf3.webp\" \/><\/h4>\n<p>\u8fd9\u5f88\u6709\u7528&#xff0c;\u4f46 MCP \u7684\u771f\u6b63\u529b\u91cf\u5728\u4e8e\u5b83\u4e0d\u4ec5\u80fd\u8fd4\u56de\u6587\u672c\u3002<\/p>\n<\/p>\n<h3>\u4f8b\u5b50 2&#xff1a;\u53ef\u89c6\u5316\u4f60\u7684\u6d3b\u52a8&#xff08;MCP \u7684\u529b\u91cf&#xff09;<\/h3>\n<p>\u73b0\u5728&#xff0c;\u8ba9\u6211\u4eec\u8bf7\u6c42\u670d\u52a1\u5668\u5904\u7406\u6570\u636e\u5e76\u4ee5\u7ed3\u6784\u5316\u683c\u5f0f\u8fd4\u56de&#xff0c;\u6bd4\u5982\u67f1\u72b6\u56fe\u3002<\/p>\n<p>\u4f60\u8f93\u5165&#xff1a;<\/p>\n<p>Show me a summary of my step count from the last 7 days as a bar chart, including some insights on it. <\/p>\n<p>\u56e0\u4e3a\u4f60\u7684\u670d\u52a1\u5668\u7406\u89e3\u610f\u56fe\u5e76\u6709\u5de5\u5177\u6765\u805a\u5408\u6570\u636e&#xff0c;\u5b83\u4e0d\u4ec5\u8fd4\u56de\u4e00\u53e5\u8bdd\u3002\u5b83\u751f\u6210\u7ed3\u6784\u5316\u6570\u636e&#xff0c;\u4ee5\u4fbf\u5ba2\u6237\u7aef&#xff08; Claude &#xff09;\u53ef\u4ee5\u6e32\u67d3\u53ef\u89c6\u5316\u3002<\/p>\n<p style=\"text-align:center\"><img decoding=\"async\" alt=\"\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120306-688a09fa95ef8.webp\" \/><\/p>\n<p>\u606d\u559c&#xff01;<\/p>\n<p>\u4f60\u5df2\u6210\u529f\u521b\u5efa\u4e00\u4e2a\u529f\u80fd\u6027\u7684 MCP \u670d\u52a1\u5668&#xff0c;\u5c06 Claude \u8fde\u63a5\u5230\u4f60\u7684\u5065\u5eb7\u6570\u636e&#xff0c;\u4f7f\u7528 Elasticsearch \u4f5c\u4e3a\u540e\u7aef&#xff0c;\u5e76\u652f\u6301\u81ea\u7136\u8bed\u8a00\u4ea4\u4e92\u3002<\/p>\n<\/p>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u5728\u8fd9\u7bc7\u535a\u5ba2\u4e2d&#xff0c;\u6211\u4eec\u63a2\u8ba8\u4e86\u5982\u4f55\u521b\u5efa\u4e00\u4e2a\u5c06 Apple HealthKit \u6570\u636e\u4e0e LLM \u4ee3\u7406\u96c6\u6210\u7684 MCP \u670d\u52a1\u5668&#xff0c;\u4f7f\u7528 FastMCP \u548c Elasticsearch\u3002\u6211\u4eec\u8fd8\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528 MCP Inspector \u548c Claude Desktop \u672c\u5730\u6d4b\u8bd5\u670d\u52a1\u5668\u3002\u4ee3\u7801\u5728\u8fd9\u91cc\u53ef\u7528\u3002<\/p>\n<p>\u8fd9\u79cd\u65b9\u6cd5\u5141\u8bb8 AI \u52a9\u624b\u4ee5\u4e0a\u4e0b\u6587\u76f8\u5173\u3001\u5b89\u5168\u4e14\u76f4\u89c2\u7684\u65b9\u5f0f\u8bbf\u95ee\u548c\u5206\u6790\u5065\u5eb7\u6570\u636e\u3002<\/p>\n<\/p>\n<p>\u9644\u52a0\u8d44\u6e90&#xff1a;<\/p>\n<ul>\n<li>MCP Python SDK \u6587\u6863<\/li>\n<li>MCP \u89c4\u8303<\/li>\n<li>Elasticsearch \u6587\u6863<\/li>\n<li>Apple HealthKit \u6587\u6863<\/li>\n<li>\u5b98\u65b9 Elasticsearch MCP \u670d\u52a1\u5668<\/li>\n<li>FastMCP \u6587\u6863<\/li>\n<li>\u4f7f\u7528 asyncio<\/li>\n<\/ul>\n<p>\u539f\u6587&#xff1a;Building an MCP server with Elasticsearch for real health data &#8211; Elasticsearch Labs<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u6458\u8981\uff1a\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528FastMCP\u6846\u67b6\u548cElasticsearch\u6784\u5efa\u4e00\u4e2aMCP\uff08Model Context Protocol\uff09\u670d\u52a1\u5668\u6765\u7ba1\u7406\u548c\u5206\u6790Apple Health\u5065\u5eb7\u6570\u636e\u3002\u6587\u7ae0\u8be6\u7ec6\u8bb2\u89e3\u4e86MCP\u7684\u4e09\u4e2a\u6838\u5fc3\u7ec4\u4ef6\uff08Resources\u3001Tools\u548cPrompts\uff09\u7684\u5b9e\u73b0\u65b9\u6cd5\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5c06Elasticsearch\u4f5c\u4e3a\u6570\u636e\u5b58\u50a8\u540e\u7aef\uff0c\u5e76\u901a\u8fc7Claude Desktop\u5b9e\u73b0\u81ea\u7136\u8bed\u8a00\u4ea4\u4e92\u67e5\u8be2\u3002\u8be5\u89e3\u51b3\u65b9\u6848\u652f\u6301\u52a8\u6001\u6570\u636e\u67e5\u8be2\u3001\u8d8b\u52bf\u5206\u6790\u548c\u53ef\u89c6\u5316\u5c55\u793a\uff0c\u4e3aLLM\u4ee3\u7406\u63d0\u4f9b\u4e86\u5b9e\u65f6\u5065\u5eb7\u6570\u636e\u8bbf\u95ee\u80fd\u529b\u3002\u6587\u4e2d\u5305\u542b\u5b8c\u6574\u7684\u4ee3\u7801\u5b9e\u73b0\u3001\u6d4b\u8bd5\u65b9_elasticsearch mcp<\/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":[66,4416,1299,73,50,3368,323,2215],"topic":[],"class_list":["post-49832","post","type-post","status-publish","format-standard","hentry","category-server","tag-ai","tag-elastic","tag-elasticsearch","tag-mcp","tag-50","tag-3368","tag-323","tag-2215"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528 Elasticsearch \u6784\u5efa\u4e00\u4e2a\u7528\u4e8e\u771f\u5b9e\u5065\u5eb7\u6570\u636e\u7684 MCP \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\/49832.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528 Elasticsearch \u6784\u5efa\u4e00\u4e2a\u7528\u4e8e\u771f\u5b9e\u5065\u5eb7\u6570\u636e\u7684 MCP \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u6458\u8981\uff1a\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528FastMCP\u6846\u67b6\u548cElasticsearch\u6784\u5efa\u4e00\u4e2aMCP\uff08Model Context Protocol\uff09\u670d\u52a1\u5668\u6765\u7ba1\u7406\u548c\u5206\u6790Apple Health\u5065\u5eb7\u6570\u636e\u3002\u6587\u7ae0\u8be6\u7ec6\u8bb2\u89e3\u4e86MCP\u7684\u4e09\u4e2a\u6838\u5fc3\u7ec4\u4ef6\uff08Resources\u3001Tools\u548cPrompts\uff09\u7684\u5b9e\u73b0\u65b9\u6cd5\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5c06Elasticsearch\u4f5c\u4e3a\u6570\u636e\u5b58\u50a8\u540e\u7aef\uff0c\u5e76\u901a\u8fc7Claude Desktop\u5b9e\u73b0\u81ea\u7136\u8bed\u8a00\u4ea4\u4e92\u67e5\u8be2\u3002\u8be5\u89e3\u51b3\u65b9\u6848\u652f\u6301\u52a8\u6001\u6570\u636e\u67e5\u8be2\u3001\u8d8b\u52bf\u5206\u6790\u548c\u53ef\u89c6\u5316\u5c55\u793a\uff0c\u4e3aLLM\u4ee3\u7406\u63d0\u4f9b\u4e86\u5b9e\u65f6\u5065\u5eb7\u6570\u636e\u8bbf\u95ee\u80fd\u529b\u3002\u6587\u4e2d\u5305\u542b\u5b8c\u6574\u7684\u4ee3\u7801\u5b9e\u73b0\u3001\u6d4b\u8bd5\u65b9_elasticsearch mcp\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/49832.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-07-30T12:03:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120304-688a09f859b06.webp\" \/>\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=\"12 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/49832.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/49832.html\",\"name\":\"\u4f7f\u7528 Elasticsearch \u6784\u5efa\u4e00\u4e2a\u7528\u4e8e\u771f\u5b9e\u5065\u5eb7\u6570\u636e\u7684 MCP \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-07-30T12:03:07+00:00\",\"dateModified\":\"2025-07-30T12:03:07+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/49832.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/49832.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/49832.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528 Elasticsearch \u6784\u5efa\u4e00\u4e2a\u7528\u4e8e\u771f\u5b9e\u5065\u5eb7\u6570\u636e\u7684 MCP \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":"\u4f7f\u7528 Elasticsearch \u6784\u5efa\u4e00\u4e2a\u7528\u4e8e\u771f\u5b9e\u5065\u5eb7\u6570\u636e\u7684 MCP \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\/49832.html","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528 Elasticsearch \u6784\u5efa\u4e00\u4e2a\u7528\u4e8e\u771f\u5b9e\u5065\u5eb7\u6570\u636e\u7684 MCP \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.1k\u6b21\uff0c\u70b9\u8d5e12\u6b21\uff0c\u6536\u85cf8\u6b21\u3002\u6458\u8981\uff1a\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528FastMCP\u6846\u67b6\u548cElasticsearch\u6784\u5efa\u4e00\u4e2aMCP\uff08Model Context Protocol\uff09\u670d\u52a1\u5668\u6765\u7ba1\u7406\u548c\u5206\u6790Apple Health\u5065\u5eb7\u6570\u636e\u3002\u6587\u7ae0\u8be6\u7ec6\u8bb2\u89e3\u4e86MCP\u7684\u4e09\u4e2a\u6838\u5fc3\u7ec4\u4ef6\uff08Resources\u3001Tools\u548cPrompts\uff09\u7684\u5b9e\u73b0\u65b9\u6cd5\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5c06Elasticsearch\u4f5c\u4e3a\u6570\u636e\u5b58\u50a8\u540e\u7aef\uff0c\u5e76\u901a\u8fc7Claude Desktop\u5b9e\u73b0\u81ea\u7136\u8bed\u8a00\u4ea4\u4e92\u67e5\u8be2\u3002\u8be5\u89e3\u51b3\u65b9\u6848\u652f\u6301\u52a8\u6001\u6570\u636e\u67e5\u8be2\u3001\u8d8b\u52bf\u5206\u6790\u548c\u53ef\u89c6\u5316\u5c55\u793a\uff0c\u4e3aLLM\u4ee3\u7406\u63d0\u4f9b\u4e86\u5b9e\u65f6\u5065\u5eb7\u6570\u636e\u8bbf\u95ee\u80fd\u529b\u3002\u6587\u4e2d\u5305\u542b\u5b8c\u6574\u7684\u4ee3\u7801\u5b9e\u73b0\u3001\u6d4b\u8bd5\u65b9_elasticsearch mcp","og_url":"https:\/\/www.wsisp.com\/helps\/49832.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-07-30T12:03:07+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/07\/20250730120304-688a09f859b06.webp"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"12 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/49832.html","url":"https:\/\/www.wsisp.com\/helps\/49832.html","name":"\u4f7f\u7528 Elasticsearch \u6784\u5efa\u4e00\u4e2a\u7528\u4e8e\u771f\u5b9e\u5065\u5eb7\u6570\u636e\u7684 MCP \u670d\u52a1\u5668 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-07-30T12:03:07+00:00","dateModified":"2025-07-30T12:03:07+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/49832.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/49832.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/49832.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528 Elasticsearch \u6784\u5efa\u4e00\u4e2a\u7528\u4e8e\u771f\u5b9e\u5065\u5eb7\u6570\u636e\u7684 MCP \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\/49832","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=49832"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/49832\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=49832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=49832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=49832"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=49832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}