{"id":412,"date":"2026-03-29T14:43:00","date_gmt":"2026-03-29T06:43:00","guid":{"rendered":"https:\/\/mitongxue.cn\/?p=412"},"modified":"2026-06-14T14:48:55","modified_gmt":"2026-06-14T06:48:55","slug":"mcp-server","status":"publish","type":"post","link":"https:\/\/mitongxue.cn\/index.php\/2026\/03\/29\/mcp-server\/","title":{"rendered":"MCP Server"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">MCP\u662f\u4e00\u5957 <strong>\u6807\u51c6\u534f\u8bae<\/strong>\uff0c \u5b83\u89c4\u5b9a\u4e86 <strong>\u5e94\u7528\u7a0b\u5e8f<\/strong> \u4e4b\u95f4 <strong>\u5982\u4f55\u901a\u4fe1<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u4f55\u901a\u4fe1\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u901a\u4fe1\u65b9\u5f0f\n<ul class=\"wp-block-list\">\n<li>stdio\uff1a \u63a8\u8350\uff0c\u9ad8\u6548\u3001\u7b80\u6d01\u3001\u672c\u5730<\/li>\n\n\n\n<li>http\uff1a \u53ef\u8fdc\u7a0b\n<ul class=\"wp-block-list\">\n<li>StreamHTTP<\/li>\n\n\n\n<li>SSE<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u901a\u4fe1\u683c\u5f0f\uff1a \u57fa\u4e8eJSON-RPC\u7684\u8fdb\u4e00\u6b65\u89c4\u8303<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\u57fa\u672c\u89c4\u8303<\/h3>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1. \u521d\u59cb\u5316 initialize<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e24\u4e2a\u5e94\u7528\u7a0b\u5e8f\u8981\u5f00\u59cb\u901a\u4fe1\uff0c\u9996\u5148\u9700\u8981\u521d\u59cb\u5316<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">request<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>{<br> &nbsp;\"jsonrpc\": \"2.0\",<br> &nbsp;\"id\": 1,<br> &nbsp;\"method\": \"initialize\", \/\/ \u56fa\u5b9a\u4e3a initialize<br> &nbsp;\"params\": {<br> &nbsp; &nbsp;\"protocolVersion\": \"2024-11-05\",<br> &nbsp; &nbsp;\"capabilities\": {<br> &nbsp; &nbsp; &nbsp;\"roots\": {<br> &nbsp; &nbsp; &nbsp; &nbsp;\"listChanged\": true<br> &nbsp; &nbsp;  },<br> &nbsp; &nbsp; &nbsp;\"sampling\": {},<br> &nbsp; &nbsp; &nbsp;\"elicitation\": {}<br> &nbsp;  },<br> &nbsp; &nbsp;\"clientInfo\": { \/\/ \u544a\u77e5\u670d\u52a1\u5668\u5ba2\u6237\u7aef\u7684\u4fe1\u606f<br> &nbsp; &nbsp; &nbsp;\"name\": \"ExampleClient\",<br> &nbsp; &nbsp; &nbsp;\"title\": \"Example Client Display Name\",<br> &nbsp; &nbsp; &nbsp;\"version\": \"1.0.0\"<br> &nbsp;  }<br>  }<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">response<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>{<br> &nbsp;\"jsonrpc\": \"2.0\",<br> &nbsp;\"id\": 1, <br> &nbsp;\"result\": {<br> &nbsp; &nbsp;\"protocolVersion\": \"2024-11-05\",<br> &nbsp; &nbsp;\"capabilities\": {<br> &nbsp; &nbsp; &nbsp;\"logging\": {},<br> &nbsp; &nbsp; &nbsp;\"prompts\": {<br> &nbsp; &nbsp; &nbsp; &nbsp;\"listChanged\": true<br> &nbsp; &nbsp;  },<br> &nbsp; &nbsp; &nbsp;\"resources\": {<br> &nbsp; &nbsp; &nbsp; &nbsp;\"subscribe\": true,<br> &nbsp; &nbsp; &nbsp; &nbsp;\"listChanged\": true<br> &nbsp; &nbsp;  },<br> &nbsp; &nbsp; &nbsp;\"tools\": {<br> &nbsp; &nbsp; &nbsp; &nbsp;\"listChanged\": true<br> &nbsp; &nbsp;  }<br> &nbsp;  },<br> &nbsp; &nbsp;\"serverInfo\": { \/\/ \u670d\u52a1\u7aef\u4fe1\u606f<br> &nbsp; &nbsp; &nbsp;\"name\": \"ExampleServer\",<br> &nbsp; &nbsp; &nbsp;\"title\": \"Example Server Display Name\",<br> &nbsp; &nbsp; &nbsp;\"version\": \"1.0.0\"<br> &nbsp;  },<br> &nbsp; &nbsp;\"instructions\": \"Optional instructions for the client\"<br>  }<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2. \u53d1\u73b0\u5de5\u5177 <code>tools\/list<\/code><\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u670d\u52a1\u5668\u6709\u54ea\u4e9b\u5de5\u5177\u51fd\u6570\u53ef\u4ee5\u4f9b\u5ba2\u6237\u7aef\u8c03\u7528<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">request<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{<br> &nbsp;\"jsonrpc\": \"2.0\",<br> &nbsp;\"id\": 1,<br> &nbsp;\"method\": \"tools\/list\",<br>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">response<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{<br> &nbsp;\"jsonrpc\": \"2.0\",<br> &nbsp;\"id\": 1,<br> &nbsp;\"result\": {<br> &nbsp; &nbsp;\"tools\": &#91;<br> &nbsp; &nbsp;  {<br> &nbsp; &nbsp; &nbsp; &nbsp;\"name\": \"get_weather\",<br> &nbsp; &nbsp; &nbsp; &nbsp;\"title\": \"Weather Information Provider\",<br> &nbsp; &nbsp; &nbsp; &nbsp;\"description\": \"Get current weather information for a location\",<br> &nbsp; &nbsp; &nbsp; &nbsp;\"inputSchema\": {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"type\": \"object\",<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"properties\": {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"location\": {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"type\": \"string\",<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"description\": \"City name or zip code\"<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  },<br> &nbsp; &nbsp; &nbsp; &nbsp;  },<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"required\": &#91;\"location\"]<br> &nbsp; &nbsp; &nbsp;  }<br> &nbsp; &nbsp;  }<br> &nbsp;  ]<br>  }<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3. \u5de5\u5177\u8c03\u7528 <code>tools\/call<\/code><\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">request<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{<br> &nbsp;\"jsonrpc\": \"2.0\",<br> &nbsp;\"id\": 2,<br> &nbsp;\"method\": \"tools\/call\", \/\/ \u8c03\u7528\u5de5\u5177<br> &nbsp;\"params\": {<br> &nbsp; &nbsp;\"name\": \"get_weather\", \/\/ \u5de5\u5177\u540d\uff0c\u5bf9\u5e94\u5de5\u5177\u53d1\u73b0\u4e2d\u7684name<br> &nbsp; &nbsp;\"arguments\": { \/\/ \u5de5\u5177\u53c2\u6570\uff0c\u9700\u8981\u548c\u5de5\u5177\u53d1\u73b0\u4e2d\u7684\u7ed3\u6784\u4e00\u81f4<br> &nbsp; &nbsp; &nbsp;\"location\": \"New York\" <br> &nbsp;  }<br>  }<br>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">response<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{<br> &nbsp;\"jsonrpc\": \"2.0\",<br> &nbsp;\"id\": 2,<br> &nbsp;\"result\": {<br> &nbsp; &nbsp;\"content\": &#91;{ \/\/ \u51fd\u6570\u7ed3\u679c\u9700\u8981\u653e\u5230content\u5b57\u6bb5\u4e2d\uff0c\u5982\u679c\u6709\u591a\u4e2a\uff0c\u4f7f\u7528\u6570\u7ec4<br> &nbsp; &nbsp; &nbsp;\/\/ \u51fd\u6570\u7ed3\u679c\u7684\u7c7b\u578b<br> &nbsp; &nbsp; &nbsp;\/\/ \u652f\u6301\u7684\u7c7b\u578b\uff1a https:\/\/modelcontextprotocol.io\/specification\/2025-06-18\/server\/tools#tool-result<br> &nbsp; &nbsp; &nbsp;\"type\": \"text\", <br> &nbsp; &nbsp; &nbsp;\"text\": \"72\u00b0F\" <br> &nbsp;  }]<br>  }<br>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6587\u6863<\/strong>\uff1a<a href=\"https:\/\/modelcontextprotocol.io\/specification\/2025-06-18\/server\/tools#listing-tools\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/modelcontextprotocol.io\/specification\/2025-06-18\/server\/tools#listing-tools<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>MCP\u662f\u4e00\u5957 \u6807\u51c6\u534f\u8bae\uff0c \u5b83\u89c4\u5b9a\u4e86 \u5e94\u7528\u7a0b\u5e8f \u4e4b\u95f4..<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27],"tags":[33],"class_list":["post-412","post","type-post","status-publish","format-standard","hentry","category-ai","tag-mcp"],"featured_image_urls":{"full":"","thumbnail":"","medium":"","medium_large":"","large":"","1536x1536":"","2048x2048":""},"author_info":{"info":["\u9648 \u67d0\u4eba"]},"category_info":"<a href=\"https:\/\/mitongxue.cn\/index.php\/category\/ai\/\" rel=\"category tag\">AI<\/a>","tag_info":"AI","comment_count":"0","_links":{"self":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/412","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/comments?post=412"}],"version-history":[{"count":2,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/412\/revisions"}],"predecessor-version":[{"id":414,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/posts\/412\/revisions\/414"}],"wp:attachment":[{"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/media?parent=412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/categories?post=412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mitongxue.cn\/index.php\/wp-json\/wp\/v2\/tags?post=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}