首页
学习
活动
专区
圈层
工具
发布
清单首页AI文章详情

一文掌握 MCP 上下文协议:从理论到实践

{"type":"doc","content":[{"type":"image","attrs":{"id":"1ab72fbd-2eb3-4be8-a8dc-ba0abed3eed4","src":"https://developer.qcloudimg.com/editor/image/7707913/20250402-26fc53e6.png","extension":"png","align":"center","alt":"","showAlt":false,"href":"","boxShadow":"","width":1000,"aspectRatio":"2.500000","status":"success","showText":true,"isPercentage":false,"percentage":0,"isHoverDragHandle":false}},{"type":"blockquote","attrs":{"id":"277e90d7-7790-4eb0-a814-a4ad6587e7fb","textAlign":"inherit","isHoverDragHandle":false},"content":[{"type":"paragraph","attrs":{"id":"0a63a886-2686-4486-8334-668b505dcc66","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"该文章已被 "},{"type":"text","marks":[{"type":"bold"}],"text":"MCP 中文教程讲解"},{"type":"text","text":" https://github.com/chenmingyong0423/mcp-tutorials 收录,欢迎 star 收藏。"}]}]},{"type":"heading","attrs":{"id":"6bd5038b-abcc-464d-9df4-20dd17d2ce46","textAlign":"inherit","indent":0,"level":1,"isHoverDragHandle":false},"content":[{"type":"text","text":"MCP"}]},{"type":"paragraph","attrs":{"id":"4a7897ec-c948-45fa-b443-0ba119bfb230","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"​模型上下文协议("},{"type":"text","marks":[{"type":"code"}],"text":"Model Context Protocol"},{"type":"text","text":",简称 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":")是一种开放标准,旨在标准化大型语言模型("},{"type":"text","marks":[{"type":"code"}],"text":"LLM"},{"type":"text","text":")与外部数据源和工具之间的交互方式。​由 "},{"type":"text","marks":[{"type":"code"}],"text":"Anthropic"},{"type":"text","text":" 于 "},{"type":"text","marks":[{"type":"bold"}],"text":"2024"},{"type":"text","text":" 年 "},{"type":"text","marks":[{"type":"bold"}],"text":"11"},{"type":"text","text":" 月推出,"},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 通过定义统一的接口,使 "},{"type":"text","marks":[{"type":"code"}],"text":"AI"},{"type":"text","text":" 应用能够安全、灵活地访问和操作本地及远程数据资源,提升模型的功能性和可扩展性。 ​"}]},{"type":"image","attrs":{"id":"2be8f221-377d-4838-93e3-ca04d5196a57","src":"https://developer.qcloudimg.com/editor/image/7707913/20250402-eb0a6c72.png","extension":"png","align":"center","alt":"","showAlt":false,"href":"","boxShadow":"","width":858,"aspectRatio":"1.469178","status":"success","showText":true,"isPercentage":false,"percentage":0,"isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"182d7f6a-493a-4653-ba6e-53a9038689d4","textAlign":"inherit","indent":0,"level":1,"isHoverDragHandle":false},"content":[{"type":"text","text":"Transports(传输层)"}]},{"type":"paragraph","attrs":{"id":"c02dc575-5fad-462d-841d-cd51a09fb250","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"在 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 协议中,传输层提供了客户端与服务器之间通信的基础,其负责处理消息的发送与接收的底层机制。"}]},{"type":"heading","attrs":{"id":"ca075576-f5f8-4a54-acd0-30b2adf40608","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"消息格式"}]},{"type":"paragraph","attrs":{"id":"57d465a8-e743-4904-a8d3-1ca765a5fc6b","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 协议使用 "},{"type":"text","marks":[{"type":"code"}],"text":"JSON-RPC 2.0"},{"type":"text","text":" 作为消息传输格式,包含以下三种类型的 "},{"type":"text","marks":[{"type":"code"}],"text":"JSON-RPC"},{"type":"text","text":" 消息:"}]},{"type":"bulletList","attrs":{"id":"7ff35db2-d397-4780-958b-92fede16453a","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"5c2b050e-082a-49ff-ab52-50b41789a67d"},"content":[{"type":"paragraph","attrs":{"id":"8cd60dab-e7c6-4780-a2ec-b15b8233eaa9","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"Request"},{"type":"text","text":" 请求:"}]}]}]},{"type":"codeBlock","attrs":{"id":"1cdfe43a-26c9-4157-83b8-db90c7c447b4","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"jsonrpc\": \"2.0\",\n \"id\": 1, // 请求 ID(数字或字符串)\n\n \"method\": \"string\", // 方法名\n \"params\": {} // 可选,参数对象\n}"}]},{"type":"bulletList","attrs":{"id":"377161f0-ce09-4c6d-bfd9-0be0b203195a","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"a5b3be23-9980-4896-b0d5-aa5e2c08e4bc"},"content":[{"type":"paragraph","attrs":{"id":"efac357b-5c8b-4806-992f-ca616019893c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"Response"},{"type":"text","text":" 响应:"}]}]}]},{"type":"codeBlock","attrs":{"id":"5545197e-d0df-4aa5-8e59-899a95abd04c","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"jsonrpc\": \"2.0\",\n \"id\": 1, // 对应请求的 ID\n\n \"result\": {}, // 可选,成功结果\n \"error\": { // 可选,错误信息\n\n \"code\": 123,\n \"message\": \"错误描述\",\n \"data\": {} // 可选,附加数据\n }\n}"}]},{"type":"bulletList","attrs":{"id":"51cda6c4-3f37-4e8c-8f83-290e602123c5","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"5644a409-fb00-4362-b995-cd8c38f7a2b3"},"content":[{"type":"paragraph","attrs":{"id":"282a2ed1-e7bf-4551-ba3b-62a9dda13844","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"Notification"},{"type":"text","text":"通知:"}]}]}]},{"type":"codeBlock","attrs":{"id":"91cf5d1b-efa7-47bc-8fba-4655392bcea1","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"jsonrpc\": \"2.0\",\n \"method\": \"string\", // 通知方法名\n\n \"params\": {} // 可选,参数对象\n}"}]},{"type":"heading","attrs":{"id":"7a34c55e-68d7-459d-b9cb-7b483bc84c63","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"内置传输类型"}]},{"type":"paragraph","attrs":{"id":"3958583f-5e97-4a1e-9a02-f17e5fe282f6","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 协议内置了两种标准传输方式:"},{"type":"text","marks":[{"type":"bold"}],"text":"标准输入/输出(stdio)"},{"type":"text","text":"和 "},{"type":"text","marks":[{"type":"bold"}],"text":"Server-Sent Events (SSE)"},{"type":"text","text":"。"}]},{"type":"heading","attrs":{"id":"ddcf4ced-adab-45ce-8a83-d9a4667bffe3","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"标准输入/输出(stdio)"}]},{"type":"paragraph","attrs":{"id":"31baeca9-f1ef-4da8-9080-e972634c62b8","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"stdio"},{"type":"text","text":" 传输通过 "},{"type":"text","marks":[{"type":"bold"}],"text":"标准输入输出流"},{"type":"text","text":" 实现客户端与服务器之间的通信,适用于本地集成与命令行工具。"}]},{"type":"paragraph","attrs":{"id":"5ec7a7a2-c42b-42e1-95fb-61114106eba8","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"推荐在以下场景使用 "},{"type":"text","marks":[{"type":"code"}],"text":"stdio"},{"type":"text","text":":"}]},{"type":"bulletList","attrs":{"id":"b6736c2b-039a-40a0-b245-8c36cc15e0ea","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"c9f5e5b1-4995-4a13-87db-189cc8865671"},"content":[{"type":"paragraph","attrs":{"id":"5d72946d-a144-4234-9573-05b259704847","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"构建命令行工具"}]}]},{"type":"listItem","attrs":{"id":"39b72893-fc4f-469d-bf6d-92ed3d238457"},"content":[{"type":"paragraph","attrs":{"id":"44cc2e91-3693-49f1-80ce-3e0a2a1b133c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"本地系统集成"}]}]},{"type":"listItem","attrs":{"id":"9158e152-7964-49e1-81a2-c9f4fc5322e1"},"content":[{"type":"paragraph","attrs":{"id":"09422e72-5905-4b63-9091-7da9bd2f222f","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"简单进程间通信"}]}]},{"type":"listItem","attrs":{"id":"78be2b5f-d9b0-4506-b2c9-da916043ccc2"},"content":[{"type":"paragraph","attrs":{"id":"047b7fc5-3451-41d0-aece-9a3d70ae7d41","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"与 "},{"type":"text","marks":[{"type":"code"}],"text":"shell"},{"type":"text","text":" 脚本协作"}]}]}]},{"type":"paragraph","attrs":{"id":"d8a142c3-bdbf-4cfa-99ad-3078fc347014","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"Go server"},{"type":"text","text":" 示例:"}]},{"type":"codeBlock","attrs":{"id":"276b234f-93dd-45d6-93df-535e9e634b05","language":"go","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"s := server.NewMCPServer(\n\t\"My Server\", // Server name\n\t\"1.0.0\", // Version\n)\n\nif err := server.ServeStdio(s); err != nil {\n\tlog.Fatalf(\"Server error: %v\", err)\n}"}]},{"type":"heading","attrs":{"id":"80de82ff-24e5-4f94-aea1-829a8803ef7d","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"Server-Sent Events (SSE)"}]},{"type":"paragraph","attrs":{"id":"27456ecd-074d-44a8-af78-0d1c4ca233c4","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"SSE"},{"type":"text","marks":[{"type":"bold"}],"text":" 传输"},{"type":"text","text":" 通过 "},{"type":"text","marks":[{"type":"code"}],"text":"HTTP POST"},{"type":"text","text":" 请求实现 "},{"type":"text","marks":[{"type":"bold"}],"text":"客户端到服务器通信"},{"type":"text","text":",同时支持 "},{"type":"text","marks":[{"type":"bold"}],"text":"服务器到客户端流式传输"},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"id":"0e8c8293-fd87-4e7d-8b6f-84cbea84bc4b","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"推荐在以下场景使用 "},{"type":"text","marks":[{"type":"code"}],"text":"SSE"},{"type":"text","text":":"}]},{"type":"bulletList","attrs":{"id":"824bdbdd-0921-440c-a123-bc3468648213","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"2d87ba24-0cd2-428a-adc9-487bdd0f3940"},"content":[{"type":"paragraph","attrs":{"id":"8b440010-a443-494d-a824-f2c0714826c3","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"仅需要服务器到客户端的流式通信"}]}]},{"type":"listItem","attrs":{"id":"a5a34b6f-bee5-4aeb-9656-f6e053c3e7ee"},"content":[{"type":"paragraph","attrs":{"id":"7be76b42-53b7-458b-9068-1ea3e40af40f","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"运行在受限网络环境"}]}]},{"type":"listItem","attrs":{"id":"080f04b8-4872-4429-8f42-c34d556f9e15"},"content":[{"type":"paragraph","attrs":{"id":"37478b0b-5dd3-4860-91db-e0e282dca396","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"实现简单的推送更新"}]}]}]},{"type":"paragraph","attrs":{"id":"88d0e428-ae08-46ca-9804-1c11b4af4cb5","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"Go server"},{"type":"text","text":" 示例:"}]},{"type":"codeBlock","attrs":{"id":"9dc085f3-9c8c-4b5e-9c7a-cae00f2dfb3c","language":"go","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"s := server.NewMCPServer(\n\t\"My Server\", // Server name\n\t\"1.0.0\", // Version\n)\n\nsseServer := server.NewSSEServer(s)\nerr := sseServer.Start(\":8080\")\nif err != nil {\n\tpanic(err)\n}"}]},{"type":"heading","attrs":{"id":"7d41bf79-8d5a-45e1-b1df-fbac64262359","textAlign":"inherit","indent":0,"level":1,"isHoverDragHandle":false},"content":[{"type":"text","text":"MCP 的通用架构"}]},{"type":"paragraph","attrs":{"id":"a8748cb5-50fc-4d27-9ec7-9c872a6420ee","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 遵循 "},{"type":"text","marks":[{"type":"code"}],"text":"CS"},{"type":"text","text":" 架构("},{"type":"text","marks":[{"type":"code"}],"text":"client-server"},{"type":"text","text":"),具体包含的组件如下:"}]},{"type":"bulletList","attrs":{"id":"c1d6fdcb-8dea-492c-bdad-a983678f06f4","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"872db1ae-79f8-4bac-9e2b-27e7a3bdbd4d"},"content":[{"type":"paragraph","attrs":{"id":"86b93486-437c-429f-8f0a-13f86fe3407e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"Host"},{"type":"text","text":" 主机:发起连接 "},{"type":"text","marks":[{"type":"code"}],"text":"LLM"},{"type":"text","text":" 的应用程序,例如 "},{"type":"text","marks":[{"type":"code"}],"text":"Claude for Desktop"},{"type":"text","text":" 或其他的 "},{"type":"text","marks":[{"type":"code"}],"text":"AI"},{"type":"text","text":" 应用。"}]}]},{"type":"listItem","attrs":{"id":"21717f49-e054-4ef8-9453-1bf5bc5efd97"},"content":[{"type":"paragraph","attrs":{"id":"a25afe3a-0cd7-4dd4-922c-6c247e76475b","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"MCP Client"},{"type":"text","text":" 客户端:运行在主机里的客户端,与 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP Server"},{"type":"text","text":" 服务器保持 "},{"type":"text","marks":[{"type":"bold"}],"text":"1:1"},{"type":"text","text":" 连接,负责协议通信。"}]}]},{"type":"listItem","attrs":{"id":"efa61184-4da8-47d0-8dbf-dedc29eb21bb"},"content":[{"type":"paragraph","attrs":{"id":"7ceb713e-c14e-470f-ab7f-16cb2001eb5e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"MCP Server"},{"type":"text","text":" 服务器:负责向客户端提供 "},{"type":"text","marks":[{"type":"bold"}],"text":"资源"},{"type":"text","text":"、"},{"type":"text","marks":[{"type":"bold"}],"text":"提示"},{"type":"text","text":" 和 "},{"type":"text","marks":[{"type":"bold"}],"text":"工具 "},{"type":"text","text":"的服务器。"}]}]}]},{"type":"image","attrs":{"id":"ee9d3dd4-8d51-46c6-879a-810f4a18a919","src":"https://developer.qcloudimg.com/editor/image/7707913/20250402-7d3d9c40.png","extension":"png","align":"center","alt":"","showAlt":false,"href":"","boxShadow":"","width":721,"aspectRatio":"1.839286","status":"success","showText":true,"isPercentage":false,"percentage":0,"isHoverDragHandle":false}},{"type":"paragraph","attrs":{"id":"fa2ad04c-10ed-4645-9f97-6b9fa56471fe","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"9c692626-9bae-46f0-b1a6-a94b73bf8f95","textAlign":"inherit","indent":0,"level":1,"isHoverDragHandle":false},"content":[{"type":"text","text":" MCP 客户端"}]},{"type":"paragraph","attrs":{"id":"01b34d6a-e48c-4b0c-bf30-5edcb490a17e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"客户端可以实现额外的功能来与 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 服务器进行交互。"}]},{"type":"heading","attrs":{"id":"df8ac846-e6d3-41c2-99b0-e9bae7d5745f","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"Roots 根"}]},{"type":"paragraph","attrs":{"id":"8f2a1e25-174d-4590-914f-a613d333bfd1","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"Roots"},{"type":"text","text":" 是"},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 协议中的一个概念,用于界定服务器可操作的边界。客户端可以定义 "},{"type":"text","marks":[{"type":"code"}],"text":"Roots"},{"type":"text","text":",以告知服务器相关的资源信息及其位置。"}]},{"type":"paragraph","attrs":{"id":"60be6bab-0675-4d25-b270-bfb7845bef1f","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"root"},{"type":"text","text":" 是客户端建议服务器应关注的 "},{"type":"text","marks":[{"type":"code"}],"text":"URI"},{"type":"text","text":"。当 "},{"type":"text","marks":[{"type":"bold"}],"text":"客户端 "},{"type":"text","text":"连接到服务器时,它会声明"},{"type":"text","marks":[{"type":"bold"}],"text":" 服务器 "},{"type":"text","text":"应处理哪些 "},{"type":"text","marks":[{"type":"code"}],"text":"root"},{"type":"text","text":"。虽然这些 "},{"type":"text","marks":[{"type":"code"}],"text":"root"},{"type":"text","text":" 主要是文件系统路径,但 "},{"type":"text","marks":[{"type":"code"}],"text":"root"},{"type":"text","text":" 也可以是 "},{"type":"text","marks":[{"type":"code"}],"text":"HTTP URL"},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"id":"8d5b3fd0-5378-41b1-b97d-1d201a03a4f8","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"例如:"}]},{"type":"codeBlock","attrs":{"id":"b96ad5cb-1e28-4472-8801-f41db6c2bcb9","language":"bash","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"# 文件系统路径\nfile:///home/chenmingyong/workspace\n# HTTP URL\nhttps://chenmingyong.cn/"}]},{"type":"heading","attrs":{"id":"b3a2c73e-7f58-492a-957a-82e539c0b3c8","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"功能"}]},{"type":"paragraph","attrs":{"id":"1c080ab3-db5a-46db-8653-0b17c49fe619","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"Roots"},{"type":"text","text":" 有以下几个功能:"}]},{"type":"bulletList","attrs":{"id":"7939830b-13d9-427d-8d0e-8c1b6cf8b518","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"504bc0e3-dd72-4bca-8655-488ffea05ac9"},"content":[{"type":"paragraph","attrs":{"id":"c2d7e897-4918-4fb5-aba7-391612377594","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"引导:指示服务器相关资源及其位置。"}]}]},{"type":"listItem","attrs":{"id":"28079bae-feaf-46c1-9398-513b99b99133"},"content":[{"type":"paragraph","attrs":{"id":"d4147854-6751-462f-b23d-8d0125557287","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"明确归属:清楚标识哪些资源属于当前工作区。"}]}]},{"type":"listItem","attrs":{"id":"1598d169-295f-4f40-9170-e1b2d496266f"},"content":[{"type":"paragraph","attrs":{"id":"65f6dfb4-ee67-440a-b5d2-75329ea906a8","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"便于管理:支持同时处理多个不同的资源。"}]}]}]},{"type":"heading","attrs":{"id":"57368626-a848-4409-9193-ec1a244e0ac4","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"工作机制"}]},{"type":"paragraph","attrs":{"id":"210bd678-7962-4489-b54c-577ac88604a5","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"当客户端具备 "},{"type":"text","marks":[{"type":"code"}],"text":"Roots"},{"type":"text","text":" 功能时,通常会:"}]},{"type":"bulletList","attrs":{"id":"fa6a5c51-f682-464a-9c17-8a680b0445d4","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"5292d09c-c7c6-4ad7-b4a5-d621d6f7f160"},"content":[{"type":"paragraph","attrs":{"id":"739f0458-2eea-4ae9-964c-ede9cedf503a","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"在连接服务器时声明自身的 "},{"type":"text","marks":[{"type":"code"}],"text":"Roots"},{"type":"text","text":" 支持能力"}]}]},{"type":"listItem","attrs":{"id":"815c8f44-b05a-43f7-bc21-1b5e7413e103"},"content":[{"type":"paragraph","attrs":{"id":"cad9461b-62a7-40fe-a71e-5f1433f6bac7","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"向服务器发送建议的 "},{"type":"text","marks":[{"type":"code"}],"text":"Roots"},{"type":"text","text":" 列表"}]}]},{"type":"listItem","attrs":{"id":"ec242f14-f149-4dc3-9e73-22e292c49aba"},"content":[{"type":"paragraph","attrs":{"id":"fcdf550d-902f-43bd-accc-92324884c83e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"在 "},{"type":"text","marks":[{"type":"code"}],"text":"Roots"},{"type":"text","text":" 发生变更时(若协议支持)主动通知服务器"}]}]}]},{"type":"heading","attrs":{"id":"75416cc2-00b4-4603-b015-95b497035c55","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"示例"}]},{"type":"codeBlock","attrs":{"id":"b35a3641-27c7-4489-91a1-e01d774c1d34","language":"bash","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"roots\": [\n {\n \"uri\": \"file:///home/chenmingyong/workspace/frontend\",\n \"name\": \"Frontend Repository\"\n },\n {\n \"uri\": \"https://chenmingyong.cn/\",\n \"name\": \"API Endpoint\"\n }\n ]\n}"}]},{"type":"heading","attrs":{"id":"9f83a515-7bd8-4ba3-aac6-9b7987c8850f","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"Sampling 采样"}]},{"type":"paragraph","attrs":{"id":"7c7963f2-44ed-4d24-a072-8c4435896dc3","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"采样是 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 协议中一项强大的功能,允许服务器通过客户端向 "},{"type":"text","marks":[{"type":"code"}],"text":"LLM"},{"type":"text","text":" 大模型请求补全结果,从而实现更复杂的代理行为,同时确保安全性与隐私性。"}]},{"type":"heading","attrs":{"id":"96132b84-d286-46c2-b0a0-2f7a3f5a5c52","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"工作原理"}]},{"type":"paragraph","attrs":{"id":"8cc4e335-7f03-497a-b50b-0274963f66c9","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"采样流程遵循以下步骤:"}]},{"type":"bulletList","attrs":{"id":"194c38b9-d707-4b9f-9329-4b2c43bdd780","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"cb09fd46-386e-4702-a3ab-ba5baf007cce"},"content":[{"type":"paragraph","attrs":{"id":"e8fce2ab-c94c-4408-9135-749c0a92aa0c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"服务器发送请求"},{"type":"text","text":":服务器向客户端发送 "},{"type":"text","marks":[{"type":"code"}],"text":"sampling/createMessage"},{"type":"text","text":" 请求。"}]}]},{"type":"listItem","attrs":{"id":"ceb40a8c-5735-4af8-a896-709c72be2a50"},"content":[{"type":"paragraph","attrs":{"id":"6341ff5e-71bf-4e76-aff9-b887cabd7d7d","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"客户端审核请求"},{"type":"text","text":":客户端收到请求后可以对其审查和修改。"}]}]},{"type":"listItem","attrs":{"id":"f7a44d1f-c117-415e-ac4b-37ba01e50c30"},"content":[{"type":"paragraph","attrs":{"id":"94d762fb-299a-46f7-99b3-a98b828ff32e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"客户端发起采样"},{"type":"text","text":":客户端向 "},{"type":"text","marks":[{"type":"code"}],"text":"LLM"},{"type":"text","text":" 发送采样请求。"}]}]},{"type":"listItem","attrs":{"id":"46c329c6-dfaa-4fba-9cd3-954acc6b9944"},"content":[{"type":"paragraph","attrs":{"id":"c647a77c-e1e1-4dc6-a238-00916c66cc88","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"客户端审核结果"},{"type":"text","text":":客户端审核 "},{"type":"text","marks":[{"type":"code"}],"text":"LLM"},{"type":"text","text":" 返回的补全内容。"}]}]},{"type":"listItem","attrs":{"id":"5c04eecc-fad4-41d0-ad50-38110ae7f70b"},"content":[{"type":"paragraph","attrs":{"id":"78890477-fd61-4f58-850f-b4eb4901808b","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"客户端返回结果"},{"type":"text","text":":客户端将最终结果发送回服务器。"}]}]}]},{"type":"image","attrs":{"id":"b21f50cd-651c-4630-841d-f78c2350418d","src":"https://developer.qcloudimg.com/editor/image/7707913/20250403-4156175b.png","extension":"png","align":"center","alt":"","showAlt":false,"href":"","boxShadow":"","width":759,"aspectRatio":"1.485323","status":"success","showText":true,"isPercentage":false,"percentage":0,"isHoverDragHandle":false}},{"type":"paragraph","attrs":{"id":"9ba43b28-995a-4086-92c0-6fcea6d7ffa1","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false}},{"type":"paragraph","attrs":{"id":"59a7ceb3-9570-4b5d-8a7e-0af76854e3b4","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"这种 "},{"type":"text","marks":[{"type":"bold"}],"text":"人机协作(Human-in-the-loop)"},{"type":"text","text":" 设计,确保用户能控制 "},{"type":"text","marks":[{"type":"code"}],"text":"LLM"},{"type":"text","text":" 看到的内容以及生成的结果,兼顾自动化与安全性。"}]},{"type":"heading","attrs":{"id":"1704d8c0-7e41-42cf-875b-377eea3b94fd","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"消息格式"}]},{"type":"paragraph","attrs":{"id":"646fc1ef-5ed4-4175-9b33-60331f65890e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"采样请求使用同一的消息结构,示例如下:"}]},{"type":"codeBlock","attrs":{"id":"d6a982e9-eb0c-4053-bdf4-de1d77511787","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"messages\": [\n {\n \"role\": \"user\" | \"assistant\", // 消息角色\n \"content\": {\n \"type\": \"text\" | \"image\", // 内容类型\n\n // 文本内容\n \"text\": \"string\",\n\n // 图片内容\n \"data\": \"string\", // Base64 编码\n \"mimeType\": \"string\" // MIME 类型\n\n }\n\n }\n ],\n \"modelPreferences\": { // 可选,模型偏好设置\n \"hints\": [ // 模型提示\n {\n \"name\": \"string\" // 建议的模型名称\n\n }\n ],\n \"costPriority\": 0.0, // 降低成本的优先级 (0-1)\n \"speedPriority\": 0.0, // 低延迟的优先级 (0-1)\n \"intelligencePriority\": 0.0 // 模型能力的优先级 (0-1)\n },\n \"systemPrompt\": \"string\", // 可选,系统提示词\n\n \"includeContext\": \"none\" | \"thisServer\" | \"allServers\", // 上下文包含范围\n \"temperature\": 0.0, // 随机性控制\n \"maxTokens\": 100, // 最大生成 Token 数\n\n \"stopSequences\": [\"string\"], // 停止序列\n \"metadata\": {} // 其他元数据\n}"}]},{"type":"heading","attrs":{"id":"06e7b08f-3883-4ec0-9163-55c6ecd45d9e","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"响应格式"}]},{"type":"paragraph","attrs":{"id":"a1d31319-890b-4bc7-b603-bc6e1d2e8672","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"客户端返回采样结果的结构如下:"}]},{"type":"codeBlock","attrs":{"id":"c59c1f70-b363-4fa4-a74c-52032be44a27","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"model\": \"string\", // 使用的模型名称\n \"stopReason\": \"endTurn\" | \"stopSequence\" | \"maxTokens\" | \"string\", // 停止原因\n\n \"role\": \"user\" | \"assistant\", // 消息角色\n \"content\": {\n\n \"type\": \"text\" | \"image\", // 内容类型\n \"text\": \"string\", // 文本内容\n \"data\": \"string\", // 图片内容 (Base64)\n \"mimeType\": \"string\" // MIME 类型\n }\n}"}]},{"type":"heading","attrs":{"id":"129de4b1-5b91-4f05-b18f-7ce750d398c7","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"示例请求"}]},{"type":"paragraph","attrs":{"id":"ce83410a-faad-4312-adba-23ab2a8bd354","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"以下是一个示例采样请求:"}]},{"type":"codeBlock","attrs":{"id":"67ec02f6-89e9-43e6-a650-a1bc3a4f22e3","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"method\": \"sampling/createMessage\",\n \"params\": {\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": {\n \"type\": \"text\",\n \"text\": \"当前目录下有哪些文件?\"\n\n }\n }\n ],\n \"systemPrompt\": \"你是一名文件系统助手。\",\n \"includeContext\": \"thisServer\",\n \"maxTokens\": 100\n }\n}"}]},{"type":"heading","attrs":{"id":"63b4f3d0-fd32-4fd1-93ba-623c59c80b3e","textAlign":"inherit","indent":0,"level":1,"isHoverDragHandle":false},"content":[{"type":"text","text":"MCP 服务器"}]},{"type":"paragraph","attrs":{"id":"1465bf8a-867f-44e5-9503-45fb7a69d75f","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"在 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 协议中,服务器提供了为 "},{"type":"text","marks":[{"type":"code"}],"text":"LLM"},{"type":"text","text":" 大模型添加上下文的基础构件。通过 "},{"type":"text","marks":[{"type":"code"}],"text":"Propmts"},{"type":"text","text":"(提示词)、"},{"type":"text","marks":[{"type":"code"}],"text":"Resources"},{"type":"text","text":"(资源)和 "},{"type":"text","marks":[{"type":"code"}],"text":"Tools"},{"type":"text","text":"(工具)这三种 "},{"type":"text","marks":[{"type":"bold"}],"text":"原语(Primitives)"},{"type":"text","text":", "},{"type":"text","marks":[{"type":"textStyle","attrs":{"color":"rgb(24, 24, 24)","background":""}}],"text":"客户端、服务器与语言模型之间能够实现"},{"type":"text","marks":[{"type":"textStyle","attrs":{"color":"rgb(24, 24, 24)","background":""}},{"type":"bold"}],"text":"高效且灵活的交互。"}]},{"type":"heading","attrs":{"id":"436ef560-0343-4872-b47b-019ff2d1c111","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"Prompts 提示词"}]},{"type":"paragraph","attrs":{"id":"2f5bb0dc-696f-4870-b659-d24e100e925e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"提示词 "},{"type":"text","text":"允许服务器定义可复用的提示词模板和工作流,客户端可以轻松将这些模板呈现给用户或 "},{"type":"text","marks":[{"type":"code"}],"text":"LLM"},{"type":"text","text":"。"}]},{"type":"heading","attrs":{"id":"790c2bb2-e853-4596-9d6f-90c2634a6ad9","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"提示词结构"}]},{"type":"paragraph","attrs":{"id":"f883fbf0-6fa7-49b4-9f1e-a232152f082a","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"一个提示词的结构定义如下所示:"}]},{"type":"codeBlock","attrs":{"id":"9e5710e9-8593-4d43-afa0-a72c7a02a513","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"name\": \"string\", // 提示词唯一标识符\n \"description\": \"string\", // 可选,人类可读的描述\n \"arguments\": [ // 可选参数列表\n {\n \"name\": \"string\", // 参数标识符\n \"description\": \"string\", // 可选,参数描述\n\n \"required\": \"boolean\" // 是否为必填参数\n }\n ]\n}\n"}]},{"type":"heading","attrs":{"id":"2137cbac-3daf-4f10-812d-1bf5074d7cdd","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"获取提示词"}]},{"type":"paragraph","attrs":{"id":"85ffd9ed-4cb3-40cf-8205-2ff9ff409b1b","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"客户端可以通过调用 "},{"type":"text","marks":[{"type":"code"}],"text":"prompts/list"},{"type":"text","text":" 获取可用的提示词列表:"}]},{"type":"paragraph","attrs":{"id":"d3482d5f-761c-4312-887e-b64cd92b37a3","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"请求示例:"}]},{"type":"codeBlock","attrs":{"id":"b1cfb4c7-7596-451b-88a1-ed09b48a00fb","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n method: \"prompts/list\"\n}"}]},{"type":"paragraph","attrs":{"id":"268af277-5ba9-40c6-8d46-33ee385609ee","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"响应示例:"}]},{"type":"codeBlock","attrs":{"id":"b7f862cc-4b75-4e04-9172-694a0a3f76aa","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"prompts\": [\n {\n \"name\": \"analyze-code\", // 提示词唯一标识符\n \"description\": \"分析代码以发现潜在改进点\", // 提示词描述\n \"arguments\": [\n {\n \"name\": \"language\", // 参数名称\n \"description\": \"编程语言\", // 参数描述\n \"required\": true // 是否必填\n }\n ]\n }\n ]\n}"}]},{"type":"heading","attrs":{"id":"7d84b780-87ac-460d-861b-a4560862e775","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"获取 prompt 详情"}]},{"type":"paragraph","attrs":{"id":"d25540fd-1644-42f5-b80b-e34902540128","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"如果客户端要使用提示词,需要通过 "},{"type":"text","marks":[{"type":"code"}],"text":"prompts/get"},{"type":"text","text":" 接口获取提示词详情。"}]},{"type":"paragraph","attrs":{"id":"6c5059a3-4dce-42af-a6e2-c1ab061521f9","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"请求示例:"}]},{"type":"codeBlock","attrs":{"id":"96c0a8bd-0b4a-483c-ba3a-c8cea2e7b3a1","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"method\": \"prompts/get\",\n \"params\": {\n \"name\": \"analyze-code\", // 要使用的提示词名称\n \"arguments\": {\n \"language\": \"go\" // 动态参数\n }\n }\n}"}]},{"type":"paragraph","attrs":{"id":"9735702d-480c-4881-b1ae-4ae4f9114202","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"响应示例:"}]},{"type":"codeBlock","attrs":{"id":"cb103e03-76c0-42f0-84b7-31f75ac98b68","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"description\": \"分析 Go 代码以发现潜在改进点\", // 提示词描述\n \"messages\": [\n {\n \"role\": \"user\", // 消息发送方\n \"content\": {\n \"type\": \"text\", // 内容类型\n \"text\": \"请分析以下 Go 代码,找出可能的改进空间:\\n\\n```go\\npackage main\\n\\nimport \"fmt\"\\n\\nfunc main() {\\n\\n\tfmt.Println(\"Hello, World!\")\\n}\\n```\"\n }\n }\n ]\n}"}]},{"type":"heading","attrs":{"id":"ecfd97dc-2539-4f4a-9157-966d2631f69b","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"动态提示词"}]},{"type":"paragraph","attrs":{"id":"fbf195f7-0090-439c-bcb3-5f31a884cb91","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"提示词不仅可以是静态模板,也支持根据参数动态生成内容,甚至可以嵌入 "},{"type":"text","marks":[{"type":"bold"}],"text":"资源上下文"},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"id":"f0dce82e-8f0d-48e4-a08b-f558d361479c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"提示词定义示例:"}]},{"type":"codeBlock","attrs":{"id":"fbd358bb-2f81-4196-9e91-717493ab1ff8","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"name\": \"analyze-project\", // 提示词名称\n \"description\": \"分析项目日志与代码\", // 描述\n \"arguments\": [\n {\n \"name\": \"timeframe\", // 参数名称\n \"description\": \"要分析的日志时间范围\", // 参数描述\n \"required\": true // 是否必填\n },\n {\n \"name\": \"fileUri\", // 参数名称\n \"description\": \"待审查的代码文件 URI\", // 参数描述\n \"required\": true // 是否必填\n }\n ]\n}\n"}]},{"type":"paragraph","attrs":{"id":"bd634a78-0083-40ad-9768-0d478e188f6e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"prompts/get 请求返回示例:"}]},{"type":"codeBlock","attrs":{"id":"75a51169-8a86-44af-a8da-fcbd3029b625","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"messages\": [\n {\n \"role\": \"user\",\n \"content\": {\n \"type\": \"text\",\n \"text\": \"请分析以下系统日志和代码文件,找出潜在问题:\"\n }\n },\n {\n \"role\": \"user\",\n \"content\": {\n \"type\": \"resource\",\n \"resource\": {\n \"uri\": \"logs://recent?timeframe=1h\", // 资源 URI\n \"text\": \"[2024-03-14 15:32:11] ERROR: network.py:127 连接超时\\n[2024-03-14 15:32:15] WARN: 正在重试连接 (第 2/3 次)\\n[2024-03-14 15:32:20] ERROR: 达到最大重试次数\", \n \"mimeType\": \"text/plain\" // 资源类型\n }\n }\n },\n {\n \"role\": \"user\",\n \"content\": {\n \"type\": \"resource\",\n \"resource\": {\n \"uri\": \"file:///path/to/code.py\", // 代码文件 URI\n \"text\": \"def connect_to_service(timeout=30):\\n retries = 3\\n for attempt in range(retries):\\n try:\\n return establish_connection(timeout)\\n except TimeoutError:\\n if attempt == retries - 1:\\n raise\\n time.sleep(5)\\n\\ndef establish_connection(timeout):\\n # 连接实现\\n pass\",\n \"mimeType\": \"text/x-python\"\n }\n }\n }\n ]\n}\n"}]},{"type":"heading","attrs":{"id":"34b2591d-a4c8-4a15-a2ec-271e8c38a427","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"多轮提示工作流"}]},{"type":"paragraph","attrs":{"id":"4fbff8ef-7e2a-436f-ada2-f3a24d10f3c2","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"提示词还支持定义多轮对话流程,通过预设的多步提示,引导用户完成复杂任务。"}]},{"type":"codeBlock","attrs":{"id":"c8c3220a-fa7a-46a4-a22a-7fca591ee610","language":"typescript","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"const debugWorkflow = {\n name: \"debug-error\",\n async getMessages(error: string) {\n return [\n {\n role: \"user\",\n content: {\n type: \"text\",\n text: `我遇到了一个错误:${error}`\n }\n },\n {\n role: \"assistant\",\n content: {\n type: \"text\",\n text: \"我来帮你分析这个错误。你之前尝试过哪些操作?\"\n }\n },\n {\n role: \"user\",\n content: {\n type: \"text\",\n text: \"我尝试重启服务,但错误依然存在。\"\n }\n }\n ];\n }\n};"}]},{"type":"heading","attrs":{"id":"9144c257-1c09-4afc-82e8-533a2daf1dab","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"Resources 资源"}]},{"type":"paragraph","attrs":{"id":"be84ec61-e034-4c59-bceb-9b3e9c91f8d1","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"Resources "},{"type":"text","text":"(资源)是 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 协议中的核心原语之一,服务器通过它可以向客户端提供可读的数据或内容,用作 "},{"type":"text","marks":[{"type":"code"}],"text":"LLM"},{"type":"text","text":" 交互的上下文信息。"}]},{"type":"heading","attrs":{"id":"c33821a5-4e1e-438d-bc73-9958bb1945e6","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"资源 URI"}]},{"type":"paragraph","attrs":{"id":"d9d60058-a427-454b-99ea-c5d3eb2629d0","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"每个资源通过 "},{"type":"text","marks":[{"type":"code"}],"text":"URI"},{"type":"text","text":" 进行标识,格式如下:"}]},{"type":"codeBlock","attrs":{"id":"a85db1d5-ea45-47ee-b959-d51731b6e487","language":"markdown","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"[协议]://[主机]/[路径]"}]},{"type":"paragraph","attrs":{"id":"f548c486-198f-43fe-a946-68300df44677","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"示例:"}]},{"type":"codeBlock","attrs":{"id":"c739b994-9886-4240-a0d1-1c1d6d8297bb","language":"markdown","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"file:///home/chenmingyong/documents/go.pdf\npostgres://database/customers/schema\nscreen://localhost/display1"}]},{"type":"paragraph","attrs":{"id":"2e4a6906-7267-4f4e-9985-f9c9c5f30027","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"具体的协议("},{"type":"text","marks":[{"type":"code"}],"text":"protocol"},{"type":"text","text":")与路径结构由 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 服务器自行定义,服务器也可以设计自定义的 "},{"type":"text","marks":[{"type":"code"}],"text":"URI"},{"type":"text","text":" 格式。"}]},{"type":"heading","attrs":{"id":"e9cf1003-d43b-4b95-9fea-a31525d02b0d","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"资源类型"}]},{"type":"paragraph","attrs":{"id":"9c3b4b8d-c574-4dad-9a6d-f41e73d6d3f8","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"资源内容分为两种类型:"}]},{"type":"heading","attrs":{"id":"76ba0cab-89dc-45df-91a6-5978e3a01084","textAlign":"inherit","indent":0,"level":4,"isHoverDragHandle":false},"content":[{"type":"text","text":"文本类型"}]},{"type":"paragraph","attrs":{"id":"5607d288-41b8-4be8-8965-956c70b225ee","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"包含 "},{"type":"text","marks":[{"type":"code"}],"text":"UTF_8"},{"type":"text","text":" 编码的文本数据,例如:"}]},{"type":"bulletList","attrs":{"id":"1f6a51ab-c565-4873-8b67-6985df06068c","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"2846407b-c528-4281-8b30-e0deaa68b31c"},"content":[{"type":"paragraph","attrs":{"id":"e294896f-c1b3-44c3-852d-3eb6e3cb1f47","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"源代码"}]}]},{"type":"listItem","attrs":{"id":"c7ba8f03-a656-4a12-91e0-8a627af1d218"},"content":[{"type":"paragraph","attrs":{"id":"b0c42117-e9b9-466a-a4c5-7f7d346282cb","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"配置文件"}]}]},{"type":"listItem","attrs":{"id":"0f5a06ee-54cf-404e-9b07-e6b5a05f888c"},"content":[{"type":"paragraph","attrs":{"id":"e23e944f-ff18-4191-9856-e4ff022ae760","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"日志文件"}]}]},{"type":"listItem","attrs":{"id":"bfa83d41-a154-4a8b-82a8-3d3761cd9dd5"},"content":[{"type":"paragraph","attrs":{"id":"60dbf8fd-3200-4702-9338-6c152449770e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"JSON / XML"},{"type":"text","text":" 数据"}]}]},{"type":"listItem","attrs":{"id":"b246106e-94a2-43e2-bbbc-d060d4fade86"},"content":[{"type":"paragraph","attrs":{"id":"aa5e32d5-d3f7-464a-b5d2-0a80d26ba8b5","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"普通文本"}]}]}]},{"type":"heading","attrs":{"id":"6ac2f5e4-b42d-4f9d-ab7c-49f8ed76286b","textAlign":"inherit","indent":0,"level":4,"isHoverDragHandle":false},"content":[{"type":"text","text":"二进制资源"}]},{"type":"paragraph","attrs":{"id":"09005f4b-8e89-42b7-bd38-2ebdb87f6457","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"包含 "},{"type":"text","marks":[{"type":"code"}],"text":"Base64"},{"type":"text","text":" 编码的原始二进制数据,例如:"}]},{"type":"bulletList","attrs":{"id":"fb79d80e-2b13-4f4f-92ff-a43d84510089","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"ca7fe7f7-a542-4db4-9479-fa04efcb4b4b"},"content":[{"type":"paragraph","attrs":{"id":"9d56eb18-8151-4705-9dd7-972d67e079c1","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"图片"}]}]},{"type":"listItem","attrs":{"id":"207777e5-49ec-4cd4-ba6b-1ac6468376af"},"content":[{"type":"paragraph","attrs":{"id":"6ba88fea-8513-419f-a3a4-ed72518f8fc5","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"PDF"},{"type":"text","text":" 文件"}]}]},{"type":"listItem","attrs":{"id":"97ed5e95-95d3-4b0b-aa30-32a5e53a757b"},"content":[{"type":"paragraph","attrs":{"id":"e667de89-ec78-474a-94ff-33b91b04428a","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"音频 / 视频文件"}]}]},{"type":"listItem","attrs":{"id":"b1f83b71-7287-4851-9fd8-afc0e1f06e9b"},"content":[{"type":"paragraph","attrs":{"id":"01ab7aa4-238a-4118-94e2-06b6620ef15d","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"其他非文本格式"}]}]}]},{"type":"heading","attrs":{"id":"02fc44f7-c1a7-4a62-934e-68fb504551b9","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"获取资源列表"}]},{"type":"paragraph","attrs":{"id":"73f9ca81-d125-45e0-923c-4dbd5c6e17d4","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"客户端可以通过调用服务器的 "},{"type":"text","marks":[{"type":"code"}],"text":"resources/list"},{"type":"text","text":" 获取资源列表,每个资源包含以下信息:"}]},{"type":"codeBlock","attrs":{"id":"c952c593-16a4-4ef1-8d41-d6dd45c8efb5","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"uri\": \"string\", // 资源唯一标识符\n \"name\": \"string\", // 资源名称(人类可读)\n\n \"description\": \"string\", // 可选,资源描述\n \"mimeType\": \"string\" // 可选,资源 MIME 类型\n}"}]},{"type":"paragraph","attrs":{"id":"24f5f517-1702-4b26-9dd8-d423e67adf8d","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"对于动态资源,服务器可以通过 "},{"type":"text","marks":[{"type":"code"}],"text":"URI"},{"type":"text","text":" 模板方式暴露资源,客户端可根据模板构建有效的资源 "},{"type":"text","marks":[{"type":"code"}],"text":"URI"},{"type":"text","text":":"}]},{"type":"codeBlock","attrs":{"id":"3efacdb2-d289-4433-a83f-62ac0794cef2","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"uriTemplate\": \"string\", // 符合 RFC 6570 的 URI 模板\n \"name\": \"string\", // 模板名称(人类可读)\n\n \"description\": \"string\", // 可选,模板描述\n \"mimeType\": \"string\" // 可选,匹配资源的 MIME 类型\n}"}]},{"type":"heading","attrs":{"id":"caf3fde4-e212-42dd-bcf3-875098a4a1a6","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"获取资源详情"}]},{"type":"paragraph","attrs":{"id":"68e2afaf-0fd4-4ba9-9a2c-d1df26780b4a","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"客户端可以通过 "},{"type":"text","marks":[{"type":"code"}],"text":"resources/read"},{"type":"text","text":" 接口读取资源内容,只需传入资源的 "},{"type":"text","marks":[{"type":"code"}],"text":"URI"},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"id":"540ee86c-b251-49a8-b8d4-06ed39e22fe8","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"服务器会返回资源内容列表:"}]},{"type":"codeBlock","attrs":{"id":"b7ed9289-88e9-4f54-96e3-282ceae8e583","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n contents: [\n {\n uri: string; // 资源唯一标识符\n mimeType?: string; // 可选,资源 MIME 类型\n\n // 以下二选一\n text?: string; // 文本资源\n blob?: string; // 二进制资源\n }\n ]\n}"}]},{"type":"heading","attrs":{"id":"ad3a7855-2991-48c2-aa7f-db47aae1b172","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"资源更新"}]},{"type":"paragraph","attrs":{"id":"660900b1-905e-43a2-8c8e-5ef4516dbe42","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 支持通过两种方式通知资源变更。"}]},{"type":"heading","attrs":{"id":"f90c348a-d44a-4f9c-b88a-919b87014cb5","textAlign":"inherit","indent":0,"level":4,"isHoverDragHandle":false},"content":[{"type":"text","text":"列表变更"}]},{"type":"paragraph","attrs":{"id":"fbf901fd-07b7-4394-b55f-7d14d559cbae","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"当可用资源列表发生变更时,服务器会通过 "},{"type":"text","marks":[{"type":"code"}],"text":"notifications/resources/list_changed"},{"type":"text","text":" 通知客户端。"}]},{"type":"heading","attrs":{"id":"0c2c68f6-eb72-44b0-a4a6-62a088d677cb","textAlign":"inherit","indent":0,"level":4,"isHoverDragHandle":false},"content":[{"type":"text","text":"内容变更"}]},{"type":"paragraph","attrs":{"id":"7e462c62-526c-45b2-87f4-ec3beb0f8d84","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"客户端可以订阅特定资源的更新流程如下:"}]},{"type":"bulletList","attrs":{"id":"6a738de9-8885-405c-b963-5e9561f3ebe5","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"0401380e-4bab-4417-8394-0009edc60ce1"},"content":[{"type":"paragraph","attrs":{"id":"7743963f-5b14-4572-b30a-05ba708d30af","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"客户端发送 "},{"type":"text","marks":[{"type":"code"}],"text":"resources/subscribe"},{"type":"text","text":" 请求,指定资源 "},{"type":"text","marks":[{"type":"code"}],"text":"URI"}]}]},{"type":"listItem","attrs":{"id":"7a9f63c4-d835-4708-a366-0a805678b8e3"},"content":[{"type":"paragraph","attrs":{"id":"7856d778-e342-4b65-beed-2211410bfe8e","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"资源发生变更时,服务器通过 "},{"type":"text","marks":[{"type":"code"}],"text":"notifications/resources/updated"},{"type":"text","text":" 通知客户端"}]}]},{"type":"listItem","attrs":{"id":"0b5c01dd-0928-4062-9dfa-3e86bffed6bf"},"content":[{"type":"paragraph","attrs":{"id":"f63c7376-f133-43dc-8809-509403cab96d","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"客户端可通过 "},{"type":"text","marks":[{"type":"code"}],"text":"resources/read"},{"type":"text","text":" 获取最新内容"}]}]},{"type":"listItem","attrs":{"id":"f4ed8f43-ba32-4d87-840c-9045c64f9caf"},"content":[{"type":"paragraph","attrs":{"id":"3a82a503-50e4-4d88-861f-e9225fe52e33","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"客户端可通过 "},{"type":"text","marks":[{"type":"code"}],"text":"resources/unsubscribe"},{"type":"text","text":" 取消订阅"}]}]}]},{"type":"heading","attrs":{"id":"b51ad4c8-4b16-42ee-aef7-fb3ae32147f7","textAlign":"inherit","indent":0,"level":2,"isHoverDragHandle":false},"content":[{"type":"text","text":"Tools 工具"}]},{"type":"paragraph","attrs":{"id":"d4b08a1d-c847-4bbe-bef4-f16851d6f003","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"Tools"},{"type":"text","text":"(工具) 是 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 协议中的一项关键原语,服务器可通过它向客户端暴露可执行功能,供 "},{"type":"text","marks":[{"type":"code"}],"text":"LLM"},{"type":"text","text":" 使用(通常需要用户批准,确保人类参与决策)。"},{"type":"text","marks":[{"type":"code"}],"text":"Tools"},{"type":"text","text":" 的核心概念包括:"}]},{"type":"bulletList","attrs":{"id":"f882f6ef-62e6-4462-a366-11435eb90698","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"d823a6f0-4ebf-49e1-bf49-55df2dbe6054"},"content":[{"type":"paragraph","attrs":{"id":"c4efb065-e70f-4379-acf4-a5188f5f40cc","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"发现("},{"type":"text","marks":[{"type":"bold"}],"text":"Discovery"},{"type":"text","text":"):客户端可通过 "},{"type":"text","marks":[{"type":"code"}],"text":"tools/list"},{"type":"text","text":" 接口获取可用工具列表。"}]}]},{"type":"listItem","attrs":{"id":"7d66c8c1-69ff-4a50-9218-478f8748b507"},"content":[{"type":"paragraph","attrs":{"id":"d77cb0dd-cf62-4f55-9b2d-b469c1c5e17a","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"调用("},{"type":"text","marks":[{"type":"bold"}],"text":"Invocation"},{"type":"text","text":"):客户端可通过 "},{"type":"text","marks":[{"type":"code"}],"text":"tools/call"},{"type":"text","text":"接口发起工具调用请求,由服务器执行具体操作并返回结果。"}]}]},{"type":"listItem","attrs":{"id":"16a527bd-25bc-41a4-832c-abf707ba2cc0"},"content":[{"type":"paragraph","attrs":{"id":"a6eea383-f343-4300-b8b9-b1872625478a","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"灵活性("},{"type":"text","marks":[{"type":"bold"}],"text":"Flexibility"},{"type":"text","text":"):工具既可以是简单的计算函数,也可以是复杂的 "},{"type":"text","marks":[{"type":"code"}],"text":"API"},{"type":"text","text":" 集成。"}]}]}]},{"type":"heading","attrs":{"id":"cdece19f-3943-4ba9-bab6-728871af810b","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"工具结构定义"}]},{"type":"paragraph","attrs":{"id":"ada81688-40c1-46d2-8a85-828e7f9bbfc1","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"每个工具的结构定义如下所示:"}]},{"type":"codeBlock","attrs":{"id":"d1b2db2d-2326-4881-b01a-340653000e62","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"name\": \"string\", // 工具唯一标识符\n \"description\": \"string\", // 可选,工具描述\n\n \"inputSchema\": { // 工具参数的 JSON Schema\n \"type\": \"object\",\n\n \"properties\": { ... } // 工具参数定义\n }\n}"}]},{"type":"heading","attrs":{"id":"db67f025-b814-4f0c-bb06-ee27012ed773","textAlign":"inherit","indent":0,"level":3,"isHoverDragHandle":false},"content":[{"type":"text","text":"工具实现示例"}]},{"type":"bulletList","attrs":{"id":"a0bee169-e5e8-4528-8208-3519e2529908","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"84ea320e-2bb6-4303-98ce-8cf3a3bf91f7"},"content":[{"type":"paragraph","attrs":{"id":"f7642d80-08ac-412f-a1ab-9f99df219148","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"与本地系统交互的工具"}]}]}]},{"type":"codeBlock","attrs":{"id":"179a6cc6-afa9-4155-ad03-f88c5400960e","language":"javascript","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"name\": \"execute_command\", // 工具名称\n \"description\": \"执行 shell 命令\", // 描述\n\n \"inputSchema\": {\n \"type\": \"object\",\n\n \"properties\": {\n \"command\": { \"type\": \"string\" }, // 命令名称\n\n \"args\": { \n \"type\": \"array\", \n\n \"items\": { \"type\": \"string\" } // 命令参数\n }\n }\n }\n}\n"}]},{"type":"bulletList","attrs":{"id":"e5167af6-7ff6-47cd-8489-c8032965d429","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"82235f74-bb0c-48de-956f-fc81d926fbdb"},"content":[{"type":"paragraph","attrs":{"id":"38b752ec-80f4-4549-8072-54030f08d56a","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"外部 "},{"type":"text","marks":[{"type":"code"}],"text":"API"},{"type":"text","text":" 集成类工具"}]}]}]},{"type":"codeBlock","attrs":{"id":"c8a6b809-f840-4afc-b5f9-b9379f19d274","language":"json","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"{\n \"name\": \"github_create_issue\", // 工具名称\n \"description\": \"在 GitHub 创建 Issue\", // 描述\n\n \"inputSchema\": {\n \"type\": \"object\",\n\n \"properties\": {\n \"title\": { \"type\": \"string\" }, // Issue 标题\n\n \"body\": { \"type\": \"string\" }, // Issue 内容\n \"labels\": { \n\n \"type\": \"array\", \n \"items\": { \"type\": \"string\" } // Issue 标签\n }\n\n }\n }\n}\n"}]},{"type":"paragraph","attrs":{"id":"26c236ff-a02c-412f-b45b-fb4f147ec3e1","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false}},{"type":"heading","attrs":{"id":"78636bd8-2cef-46ea-a863-ff18d856a7ee","textAlign":"inherit","indent":0,"level":1,"isHoverDragHandle":false},"content":[{"type":"text","text":"MCP Server 原语控制层级"}]},{"type":"paragraph","attrs":{"id":"2358cdb7-5c3f-4300-88d8-5f3d80b66f6c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"每个原语的 "},{"type":"text","marks":[{"type":"bold"}],"text":"控制层级 "},{"type":"text","text":"可总结如下:"}]},{"type":"table","attrs":{"id":"b7e29f4d-5a31-4c30-9dd4-c737ff7c9d0b","isHoverDragHandle":false},"content":[{"type":"tableRow","content":[{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"style":"border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem; font-weight: 600;"},"content":[{"type":"paragraph","attrs":{"id":"aeebcdee-44bb-4b5e-acbe-51fc2e0b1ad4","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"原语"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"style":"border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem; font-weight: 600;"},"content":[{"type":"paragraph","attrs":{"id":"90ef9cab-4c61-4116-9001-2699a12ff30c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"控制方"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"style":"border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem; font-weight: 600;"},"content":[{"type":"paragraph","attrs":{"id":"98002028-960b-4adb-8a2f-099363b11840","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"Description  描述"}]}]},{"type":"tableHeader","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"style":"border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem; font-weight: 600;"},"content":[{"type":"paragraph","attrs":{"id":"7bebab4c-a304-4959-9fae-456decba1e76","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"Example  示例"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"background":null,"color":null,"textAlign":null,"style":"background: null; color: null; text-align: null; border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem"},"content":[{"type":"paragraph","attrs":{"id":"431523c7-425c-4bb0-a355-c8072f81cc19","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"Prompts"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"background":null,"color":null,"textAlign":null,"style":"background: null; color: null; text-align: null; border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem"},"content":[{"type":"paragraph","attrs":{"id":"bf8b595d-7b3b-4882-9dde-eef525378f62","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"用户控制"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"background":null,"color":null,"textAlign":null,"style":"background: null; color: null; text-align: null; border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem"},"content":[{"type":"paragraph","attrs":{"id":"59a7c158-54ea-4e95-a507-1b3a8ffe1530","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"由用户选择调用的交互式模板"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"background":null,"color":null,"textAlign":null,"style":"background: null; color: null; text-align: null; border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem"},"content":[{"type":"paragraph","attrs":{"id":"76794694-1df0-4f5d-848a-3bd7a95db4d2","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"斜杠命令(/command)、菜单选项"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"background":null,"color":null,"textAlign":null,"style":"background: null; color: null; text-align: null; border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem"},"content":[{"type":"paragraph","attrs":{"id":"e702a95d-73cf-4e0c-a405-5cb9701affa6","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"Resources"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"background":null,"color":null,"textAlign":null,"style":"background: null; color: null; text-align: null; border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem"},"content":[{"type":"paragraph","attrs":{"id":"30d83471-fba0-4fd6-a9e3-e3481444805b","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"应用控制"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"background":null,"color":null,"textAlign":null,"style":"background: null; color: null; text-align: null; border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem"},"content":[{"type":"paragraph","attrs":{"id":"2a704839-8343-4955-90e3-c1148f9d144c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"由客户端附加并管理的上下文数据"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"background":null,"color":null,"textAlign":null,"style":"background: null; color: null; text-align: null; border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem"},"content":[{"type":"paragraph","attrs":{"id":"0a6d2b7d-cd81-4fd5-bf21-efa6aed5cfd5","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"文件内容,git 历史记录"}]}]}]},{"type":"tableRow","content":[{"type":"tableCell","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"background":null,"color":null,"textAlign":null,"style":"background: null; color: null; text-align: null; border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem"},"content":[{"type":"paragraph","attrs":{"id":"5ea77756-8f7c-4d50-aba4-5daaed8d9eb8","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"Tools"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"background":null,"color":null,"textAlign":null,"style":"background: null; color: null; text-align: null; border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem"},"content":[{"type":"paragraph","attrs":{"id":"6d8c6205-6651-45de-9aae-4b6c58856ea8","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"模型控制"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"background":null,"color":null,"textAlign":null,"style":"background: null; color: null; text-align: null; border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem"},"content":[{"type":"paragraph","attrs":{"id":"bcad4dd8-eb4d-4967-a0d2-e3f33dedf877","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"暴露给 LLM 以便其执行操作的功能接口"}]}]},{"type":"tableCell","attrs":{"colspan":1,"rowspan":1,"colwidth":null,"background":null,"color":null,"textAlign":null,"style":"background: null; color: null; text-align: null; border-color: rgb(209 213 219/var(--tw-border-opacity)); --tw-border-spacing-x: 0; --tw-border-spacing-y: 0; --tw-translate-x: 0; --tw-translate-y: 0; --tw-rotate: 0; --tw-skew-x: 0; --tw-skew-y: 0; --tw-scale-x: 1; --tw-scale-y: 1; --tw-pan-x: ; --tw-pan-y: ; --tw-pinch-zoom: ; --tw-scroll-snap-strictness: proximity; --tw-gradient-from-position: ; --tw-gradient-via-position: ; --tw-gradient-to-position: ; --tw-ordinal: ; --tw-slashed-zero: ; --tw-numeric-figure: ; --tw-numeric-spacing: ; --tw-numeric-fraction: ; --tw-ring-inset: ; --tw-ring-offset-width: 0px; --tw-ring-offset-color: #fff; --tw-ring-color: rgb(59 130 246 / 0.5); --tw-ring-offset-shadow: 0 0 #0000; --tw-ring-shadow: 0 0 #0000; --tw-shadow: 0 0 #0000; --tw-shadow-colored: 0 0 #0000; --tw-blur: ; --tw-brightness: ; --tw-contrast: ; --tw-grayscale: ; --tw-hue-rotate: ; --tw-invert: ; --tw-saturate: ; --tw-sepia: ; --tw-drop-shadow: ; --tw-backdrop-blur: ; --tw-backdrop-brightness: ; --tw-backdrop-contrast: ; --tw-backdrop-grayscale: ; --tw-backdrop-hue-rotate: ; --tw-backdrop-invert: ; --tw-backdrop-opacity: ; --tw-backdrop-saturate: ; --tw-backdrop-sepia: ; --tw-contain-size: ; --tw-contain-layout: ; --tw-contain-paint: ; --tw-contain-style: ; --tw-border-opacity: 1; padding: 0.5rem 1rem"},"content":[{"type":"paragraph","attrs":{"id":"0ab5dc6e-a1be-4818-8c76-de95279cef74","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"API POST 请求、文件写入 "}]}]}]}]},{"type":"heading","attrs":{"id":"c6facb67-5b06-428b-af9e-0bcdd34df39a","textAlign":"inherit","indent":0,"level":1,"isHoverDragHandle":false},"content":[{"type":"text","text":"服务器实现"}]},{"type":"paragraph","attrs":{"id":"492280e9-9eca-431f-9de1-64325de96308","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"以下是基于 "},{"type":"text","marks":[{"type":"code"}],"text":"Go"},{"type":"text","text":" 语言实现的 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 服务器代码示例:"}]},{"type":"codeBlock","attrs":{"id":"0f7511f8-4b07-4ba2-ae40-362af8d42372","language":"go","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"package main\n\nimport (\n\t\"context\"\n\t\"errors\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/mark3labs/mcp-go/mcp\"\n\t\"github.com/mark3labs/mcp-go/server\"\n)\n\nfunc main() {\n\ts := server.NewMCPServer(\n\t\t\"Server Demo\",\n\t\t\"1.0.0\",\n\t)\n\n\t// 添加工具\n\t{\n\t\tcalculatorTool := mcp.NewTool(\"calculate\",\n\t\t\tmcp.WithDescription(\"执行基本的算术运算\"),\n\t\t\tmcp.WithString(\"operation\",\n\t\t\t\tmcp.Required(),\n\t\t\t\tmcp.Description(\"要执行的算术运算类型\"),\n\t\t\t\tmcp.Enum(\"add\", \"subtract\", \"multiply\", \"divide\"), // 保持英文\n\t\t\t),\n\t\t\tmcp.WithNumber(\"x\",\n\t\t\t\tmcp.Required(),\n\t\t\t\tmcp.Description(\"第一个数字\"),\n\t\t\t),\n\t\t\tmcp.WithNumber(\"y\",\n\t\t\t\tmcp.Required(),\n\t\t\t\tmcp.Description(\"第二个数字\"),\n\t\t\t),\n\t\t)\n\n\t\ts.AddTool(calculatorTool, func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {\n\t\t\top := request.Params.Arguments[\"operation\"].(string)\n\t\t\tx := request.Params.Arguments[\"x\"].(float64)\n\t\t\ty := request.Params.Arguments[\"y\"].(float64)\n\n\t\t\tvar result float64\n\t\t\tswitch op {\n\t\t\tcase \"add\":\n\t\t\t\tresult = x + y\n\t\t\tcase \"subtract\":\n\t\t\t\tresult = x - y\n\t\t\tcase \"multiply\":\n\t\t\t\tresult = x * y\n\t\t\tcase \"divide\":\n\t\t\t\tif y == 0 {\n\t\t\t\t\treturn nil, errors.New(\"不允许除以零\")\n\t\t\t\t}\n\t\t\t\tresult = x / y\n\t\t\t}\n\n\t\t\treturn mcp.FormatNumberResult(result), nil\n\t\t})\n\t}\n\n\t// 添加资源\n\t{\n\t\t// 静态资源示例 - 暴露一个 README 文件\n\t\tresource := mcp.NewResource(\n\t\t\t\"docs://readme\",\n\t\t\t\"项目说明文档\",\n\t\t\tmcp.WithResourceDescription(\"项目的 README 文件\"),\n\t\t\tmcp.WithMIMEType(\"text/markdown\"),\n\t\t)\n\n\t\t// 添加资源及其处理函数\n\t\ts.AddResource(resource, func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {\n\t\t\tcontent, err := os.ReadFile(\"README.md\")\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\t\treturn []mcp.ResourceContents{\n\t\t\t\tmcp.TextResourceContents{\n\t\t\t\t\tURI: \"docs://readme\",\n\t\t\t\t\tMIMEType: \"text/markdown\",\n\t\t\t\t\tText: string(content),\n\t\t\t\t},\n\t\t\t}, nil\n\t\t})\n\t}\n\n\t// 添加提示词\n\t{\n\t\t// 简单问候提示\n\t\ts.AddPrompt(mcp.NewPrompt(\"greeting\",\n\t\t\tmcp.WithPromptDescription(\"一个友好的问候提示\"),\n\t\t\tmcp.WithArgument(\"name\",\n\t\t\t\tmcp.ArgumentDescription(\"要问候的人的名字\"),\n\t\t\t),\n\t\t), func(ctx context.Context, request mcp.GetPromptRequest) (*mcp.GetPromptResult, error) {\n\t\t\tname := request.Params.Arguments[\"name\"]\n\t\t\tif name == \"\" {\n\t\t\t\tname = \"朋友\"\n\t\t\t}\n\n\t\t\treturn mcp.NewGetPromptResult(\n\t\t\t\t\"友好的问候\",\n\t\t\t\t[]mcp.PromptMessage{\n\t\t\t\t\tmcp.NewPromptMessage(\n\t\t\t\t\t\tmcp.RoleAssistant,\n\t\t\t\t\t\tmcp.NewTextContent(fmt.Sprintf(\"你好,%s!今天有什么可以帮您的吗?\", name)),\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t), nil\n\t\t})\n\t}\n\n\t// 启动基于 stdio 传输类型的服务\n\tif err := server.ServeStdio(s); err != nil {\n\t\tfmt.Printf(\"Server error: %v\\n\", err)\n\t}\n}\n"}]},{"type":"paragraph","attrs":{"id":"b19a4327-6509-4485-86d9-e22493248970","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"上述代码示例演示了如何创建一个 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP Server"},{"type":"text","text":",并展示了添加工具、资源和提示词的方法。"}]},{"type":"paragraph","attrs":{"id":"396d3a52-bcfd-43b7-a3f0-a1cd45472b46","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"需要注意的是,由于 "},{"type":"text","marks":[{"type":"code"}],"text":"mcp-go"},{"type":"text","text":" 库当前尚未支持 "},{"type":"text","marks":[{"type":"code"}],"text":"Sampling"},{"type":"text","text":"(采样)功能,示例中未包含该功能的相关用法。"}]},{"type":"heading","attrs":{"id":"8b5b4840-bd95-483f-9ec4-ae7576073939","textAlign":"inherit","indent":0,"level":1,"isHoverDragHandle":false},"content":[{"type":"text","text":"客户端实现"}]},{"type":"paragraph","attrs":{"id":"a9fedf57-9465-44e0-b8cd-16d571fc5c76","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"基于上面定义的服务器,以下是基于 "},{"type":"text","marks":[{"type":"code"}],"text":"Go"},{"type":"text","text":" 语言实现的 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 客户端代码示例:"}]},{"type":"codeBlock","attrs":{"id":"1cd8f736-9060-4620-9858-295e6e1d51a5","language":"go","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/mark3labs/mcp-go/client\"\n\t\"github.com/mark3labs/mcp-go/mcp\"\n)\n\nfunc main() {\n\n\t// 创建一个基于 stdio 的MCP客户端\n\tmcpClient, err := client.NewStdioMCPClient(\n\t\t\"./client/server\",\n\t\t[]string{},\n\t)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tdefer mcpClient.Close()\n\n\tctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)\n\tdefer cancel()\n\n\tfmt.Println(\"初始化 mcp 客户端...\")\n\tinitRequest := mcp.InitializeRequest{}\n\tinitRequest.Params.ProtocolVersion = mcp.LATEST_PROTOCOL_VERSION\n\tinitRequest.Params.ClientInfo = mcp.Implementation{\n\t\tName: \"Client Demo\",\n\t\tVersion: \"1.0.0\",\n\t}\n\n\t// 初始化MCP客户端并连接到服务器\n\tinitResult, err := mcpClient.Initialize(ctx, initRequest)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\n\t\t\"\\n初始化成功,服务器信息: %s %s\\n\\n\",\n\t\tinitResult.ServerInfo.Name,\n\t\tinitResult.ServerInfo.Version,\n\t)\n\n\t// 从服务器获取提示词列表\n\tfmt.Println(\"提示词列表:\")\n\tpromptsRequest := mcp.ListPromptsRequest{}\n\tprompts, err := mcpClient.ListPrompts(ctx, promptsRequest)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfor _, prompt := range prompts.Prompts {\n\t\tfmt.Printf(\"- %s: %s\\n\", prompt.Name, prompt.Description)\n\t\tfmt.Println(\"参数:\", prompt.Arguments)\n\t}\n\n\t// 从服务器获取资源列表\n\tfmt.Println()\n\tfmt.Println(\"资源列表:\")\n\tresourcesRequest := mcp.ListResourcesRequest{}\n\tresources, err := mcpClient.ListResources(ctx, resourcesRequest)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfor _, resource := range resources.Resources {\n\t\tfmt.Printf(\"- uri: %s, name: %s, description: %s, MIME类型: %s\\n\", resource.URI, resource.Name, resource.Description, resource.MIMEType)\n\t}\n\n\t// 从服务器获取工具列表\n\tfmt.Println()\n\tfmt.Println(\"可用工具列表:\")\n\ttoolsRequest := mcp.ListToolsRequest{}\n\ttools, err := mcpClient.ListTools(ctx, toolsRequest)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfor _, tool := range tools.Tools {\n\t\tfmt.Printf(\"- %s: %s\\n\", tool.Name, tool.Description)\n\t\tfmt.Println(\"参数:\", tool.InputSchema.Properties)\n\t}\n\tfmt.Println()\n\n\t// 调用工具\n\tfmt.Println(\"调用工具: calculate\")\n\ttoolRequest := mcp.CallToolRequest{\n\t\tRequest: mcp.Request{\n\t\t\tMethod: \"tools/call\",\n\t\t},\n\t}\n\ttoolRequest.Params.Name = \"calculate\"\n\ttoolRequest.Params.Arguments = map[string]any{\n\t\t\"operation\": \"add\",\n\t\t\"x\": 1,\n\t\t\"y\": 1,\n\t}\n\t// Call the tool\n\tresult, err := mcpClient.CallTool(ctx, toolRequest)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Println(\"调用工具结果:\", result.Content[0].(mcp.TextContent).Text)\n}\n"}]},{"type":"paragraph","attrs":{"id":"d99afaf3-fb02-421a-b217-f9455958f6ef","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"运行上述代码的结果如下所示:"}]},{"type":"codeBlock","attrs":{"id":"b57b1ed7-715a-4faf-9e1d-7ab2b27e37db","language":"plaintext","theme":"atom-one-dark","runtimes":0,"isHoverDragHandle":false,"key":""},"content":[{"type":"text","text":"初始化 mcp 客户端...\n\n初始化成功,服务器信息: Server Demo 1.0.0\n\n提示词列表:\n- greeting: 一个友好的问候提示\n参数: [{name 要问候的人的名字 false}]\n\n资源列表:\n- uri: docs://readme, name: 项目说明文档, description: 项目的 README 文件, MIME类型: text/markdown\n\n可用工具列表:\n- calculate: 执行基本的算术运算\n参数: map[operation:map[description:要执行的算术运算类型 enum:[add subtract multiply divide] type:string] x:map[description:第一个数字 type:number] y:map[description:第二个数字 type:number]]\n\n调用工具: calculate\n调用工具结果: 2.00\n"}]},{"type":"paragraph","attrs":{"id":"7c48f039-ccdf-482b-b01a-d1ff5037ab2c","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"提示词、资源以及工具列表和之前定义 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP Server"},{"type":"text","text":" 时所设置的数据一致。"}]},{"type":"heading","attrs":{"id":"a9c1cb87-3fca-40f4-886d-12983f04d584","textAlign":"inherit","indent":0,"level":1,"isHoverDragHandle":false},"content":[{"type":"text","text":"小结"}]},{"type":"paragraph","attrs":{"id":"eddaf4dd-356b-4209-b8c9-bc86aff34d9a","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"本文介绍了 "},{"type":"text","marks":[{"type":"bold"}],"text":"模型上下文协议(Model Context Protocol,MCP)"},{"type":"text","text":",一种用于规范大型语言模型("},{"type":"text","marks":[{"type":"code"}],"text":"LLM"},{"type":"text","text":")与外部数据源及工具之间交互的开放标准。内容涵盖了 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 协议的整体架构("},{"type":"text","marks":[{"type":"textStyle","attrs":{"color":"","background":""}}],"text":"客户端与服务器的一对一连接模式)、消息传输机制(采用 "},{"type":"text","marks":[{"type":"code"}],"text":"JSON-RPC 2.0"},{"type":"text","marks":[{"type":"textStyle","attrs":{"color":"","background":""}}],"text":" 格式)、以及客户端与服务器支持的核心原语,包括:"}]},{"type":"bulletList","attrs":{"id":"192c71d5-15b2-4ba7-ae84-42a479e5d15e","isHoverDragHandle":false},"content":[{"type":"listItem","attrs":{"id":"a700d35c-beb9-4116-b43f-b78af3c1fb03"},"content":[{"type":"paragraph","attrs":{"id":"7b42ac1a-d008-44c0-8840-987ec00b6d73","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"客户端原语:"},{"type":"text","marks":[{"type":"bold"}],"text":"roots(根路径)"},{"type":"text","text":"、"},{"type":"text","marks":[{"type":"bold"}],"text":"sampling(采样)"}]}]},{"type":"listItem","attrs":{"id":"8d48b696-6b3d-4709-ad7b-d77f25d6cda8"},"content":[{"type":"paragraph","attrs":{"id":"e497b223-f3bf-4047-a3de-67944f2d0d06","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"服务器原语:"},{"type":"text","marks":[{"type":"bold"}],"text":"prompts(提示词)"},{"type":"text","text":"、"},{"type":"text","marks":[{"type":"bold"}],"text":"resources(资源)"},{"type":"text","text":"、"},{"type":"text","marks":[{"type":"bold"}],"text":"tools(工具)"}]}]},{"type":"listItem","attrs":{"id":"9932d97e-8746-4f14-b096-9a35f038d68f"},"content":[{"type":"paragraph","attrs":{"id":"f4621e9e-570f-4f99-9203-87d10b6d4834","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"code"}],"text":"Server"},{"type":"text","text":"原语的控制层级分类"}]}]}]},{"type":"paragraph","attrs":{"id":"3382afeb-458f-4a63-8003-2e6438516aac","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"最后,本文提供了基于 "},{"type":"text","marks":[{"type":"bold"}],"text":"Go 语言"},{"type":"text","text":" 的 "},{"type":"text","marks":[{"type":"code"}],"text":"MCP"},{"type":"text","text":" 客户端与服务器的示例实现,帮助开发者快速理解和应用该协议。"}]},{"type":"blockquote","attrs":{"id":"a5662506-8858-468c-a08d-12338815b9c5","textAlign":"inherit","isHoverDragHandle":false},"content":[{"type":"paragraph","attrs":{"id":"85298a3b-1926-4e8c-b0c3-3b9949219659","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","text":"该文章已被 "},{"type":"text","marks":[{"type":"bold"}],"text":"MCP 中文教程讲解"},{"type":"text","text":" https://github.com/chenmingyong0423/mcp-tutorials 收录,欢迎 star 收藏。"}]}]},{"type":"horizontalRule","attrs":{"id":"6b338b33-157a-4763-9142-a8086d86619c","isHoverDragHandle":false}},{"type":"paragraph","attrs":{"id":"369e691c-7a93-4e2b-a1ad-02f1e9766604","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"你好,我是陈明勇,一名热爱技术、乐于分享的开发者,同时也是开源爱好者。"}]},{"type":"paragraph","attrs":{"id":"faf71c2a-5f04-4cf4-8411-5d2e6b1d4412","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"我专注于分享 Go 语言相关的技术知识,同时也会深入探讨 AI 领域的前沿技术。"}]},{"type":"paragraph","attrs":{"id":"82a7ed16-b387-410d-aa85-074d5ef7981f","textAlign":"inherit","indent":0,"color":null,"background":null,"isHoverDragHandle":false},"content":[{"type":"text","marks":[{"type":"bold"}],"text":"成功的路上并不拥挤,有没有兴趣结个伴?"}]}]}

下一篇
举报
领券