{"_id":"@baixiaogou/mcp-server-demo","_rev":"2-363a29ae22c2698d07bab6eceec90773","name":"@baixiaogou/mcp-server-demo","dist-tags":{"latest":"1.0.1"},"versions":{"1.0.0":{"name":"@baixiaogou/mcp-server-demo","version":"1.0.0","keywords":["mcp","server","demo"],"author":{"name":"你的名字","email":"你的邮箱"},"license":"ISC","_id":"@baixiaogou/mcp-server-demo@1.0.0","maintainers":[{"name":"baiyoubai","email":"530765937@qq.com"}],"homepage":"https://github.com/你的用户名/mcp-server-demo#readme","bugs":{"url":"https://github.com/你的用户名/mcp-server-demo/issues"},"dist":{"shasum":"af0cac7a37c6db5a3a8eb474843804691b0df830","tarball":"https://registry.npmjs.org/@baixiaogou/mcp-server-demo/-/mcp-server-demo-1.0.0.tgz","fileCount":3,"integrity":"sha512-09KNYYn3k56vguU6zeEKCblxNkS2zGCcVvP9gigOzETyRzq38UVbuq6mUh39IVIWrvnvcAGKyhO3PvUt/bkx/A==","signatures":[{"sig":"MEQCICeXzA4VyhlQdjTsn8d6QmXdSwndsuv/7VpbCTpAbNVVAiB0lBU1bQYQe7j3DFFNlYWXp8gFhIqyL0WtvBdiIav85Q==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":5075},"main":"server.js","type":"module","gitHead":"e06a926664e778460731bd2bae6e13aae4f9d721","scripts":{"test":"echo \"Error: no test specified\" && exit 1","start":"node server.js"},"_npmUser":{"name":"baiyoubai","email":"530765937@qq.com"},"repository":{"url":"git+https://github.com/你的用户名/mcp-server-demo.git","type":"git"},"_npmVersion":"10.2.3","description":"一个示例的MCP服务端包","directories":{},"_nodeVersion":"18.19.0","dependencies":{"zod":"^3.25.76","@modelcontextprotocol/sdk":"^1.15.1"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/mcp-server-demo_1.0.0_1752833170281_0.5591693165685598","host":"s3://npm-registry-packages-npm-production"}},"1.0.1":{"name":"@baixiaogou/mcp-server-demo","bin":{"mcp-server-demo":"server.js"},"type":"module","version":"1.0.1","description":"一个示例的MCP服务端包","main":"server.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1","start":"node server.js"},"keywords":["mcp","server","demo"],"author":{"name":"你的名字","email":"你的邮箱"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/你的用户名/mcp-server-demo.git"},"bugs":{"url":"https://github.com/你的用户名/mcp-server-demo/issues"},"homepage":"https://github.com/你的用户名/mcp-server-demo#readme","dependencies":{"@baixiaogou/mcp-server-demo":"^1.0.0","@modelcontextprotocol/sdk":"^1.15.1","global":"^4.4.0","zod":"^3.25.76"},"publishConfig":{"access":"public"},"_id":"@baixiaogou/mcp-server-demo@1.0.1","gitHead":"ce5ddcdd8cb2eb531e69a5da5c4781e64c05a687","_nodeVersion":"20.19.4","_npmVersion":"10.8.2","dist":{"integrity":"sha512-XZ4A5+9Qu8xhSwl0kHls7qU6Z8C9KrCp+6WuG3+sAuyzpn7ZyE7RvyTGNUB9d5GxP5R2lAPK3caDxO0BkwQBYg==","shasum":"98c6afb21fdf9bcea67debe314ace88a43ea3a75","tarball":"https://registry.npmjs.org/@baixiaogou/mcp-server-demo/-/mcp-server-demo-1.0.1.tgz","fileCount":3,"unpackedSize":5243,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDS4rLyM40DbhwC+TwAKU7Fzq/dJGnw0EAYfudaOEZehwIgbdEmOO9RABmKOocatPYBQAdkF7DXRKMuNEQN3YYJeO4="}]},"_npmUser":{"name":"baiyoubai","email":"530765937@qq.com"},"directories":{},"maintainers":[{"name":"baiyoubai","email":"530765937@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/mcp-server-demo_1.0.1_1752833764303_0.44499610027248604"},"_hasShrinkwrap":false}},"time":{"created":"2025-07-18T10:06:10.185Z","modified":"2025-07-18T10:16:04.647Z","1.0.0":"2025-07-18T10:06:10.452Z","1.0.1":"2025-07-18T10:16:04.478Z"},"bugs":{"url":"https://github.com/你的用户名/mcp-server-demo/issues"},"author":{"name":"你的名字","email":"你的邮箱"},"license":"ISC","homepage":"https://github.com/你的用户名/mcp-server-demo#readme","keywords":["mcp","server","demo"],"repository":{"type":"git","url":"git+https://github.com/你的用户名/mcp-server-demo.git"},"description":"一个示例的MCP服务端包","maintainers":[{"name":"baiyoubai","email":"530765937@qq.com"}],"readme":"# mcp-server-demo\n\n## 项目简介\n\n本项目基于 [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) 协议，演示如何通过 MCP Server 向大语言模型（LLM）或客户端暴露自定义工具（Tool）和资源（Resource），并通过标准输入输出（stdio）作为通信通道进行集成。\n\n## 主要功能\n- 注册自定义工具（registerTool）\n- 注册自定义资源（registerResource）\n- 通过 StdioServerTransport 启动服务，适合本地开发和集成到 LLM 工具链\n\n---\n\n## registerTool API\n\n### 作用\n注册一个“工具”（Tool），即带参数的接口，供 LLM 或客户端调用，实现自定义功能。\n\n### 用法\n```js\nserver.registerTool(\n  \"hello\", // 工具名称\n  {\n    title: \"Hello Tool\", // 工具标题\n    description: \"返回 hello, {name}\", // 工具描述\n    inputSchema: { name: z.string() }, // 输入参数校验（zod schema）\n  },\n  async ({ name }) => ({\n    content: [{ type: \"text\", text: `hello, ${name}` }], // 返回内容\n  })\n);\n```\n\n### 返回内容格式\n返回值需为对象，通常包含 `content` 字段，内容为数组，每项为：\n- `type`: 内容类型（如 \"text\"）\n- `text`: 文本内容\n\n**示例返回：**\n```json\n{\n  \"content\": [\n    { \"type\": \"text\", \"text\": \"hello, 张三\" }\n  ]\n}\n```\n\n---\n\n## registerResource API\n\n### 作用\n注册一个“资源”（Resource），即只读数据接口，供 LLM 加载到上下文，实现动态数据获取。\n\n### 用法\n```js\nserver.registerResource(\n  \"hello\", // 资源名称\n  new ResourceTemplate(\"hello://{name}\", { list: undefined }), // 资源模板\n  {\n    title: \"Hello Resource\", // 资源标题\n    description: \"动态 hello 资源\", // 资源描述\n  },\n  async (uri, { name }) => ({\n    contents: [\n      {\n        uri: uri.href,\n        text: `hello, ${name}`,\n      },\n    ],\n  })\n);\n```\n\n### 返回内容格式\n返回值需为对象，通常包含 `contents` 字段，内容为数组，每项为：\n- `uri`: 资源唯一标识\n- `text`: 文本内容\n\n**示例返回：**\n```json\n{\n  \"contents\": [\n    {\n      \"uri\": \"hello://张三\",\n      \"text\": \"hello, 张三\"\n    }\n  ]\n}\n```\n\n---\n\n## 什么是 StdioServerTransport\n\n`StdioServerTransport` 是 MCP 协议中用于通信的标准输入输出（stdio）传输方式。其特点如下：\n- 通过进程的标准输入（stdin）和标准输出（stdout）进行 JSON-RPC 消息的收发\n- 适合本地开发、调试和集成到 LLM 工具链\n- 启动后，客户端可作为子进程启动本服务，通过 stdio 通道与其通信\n- 保证所有消息为 UTF-8 编码的 JSON-RPC 格式\n\n**示例代码：**\n```js\nconst transport = new StdioServerTransport();\nawait server.connect(transport);\n```\n\n---\n\n## 参考资料\n- [Model Context Protocol 官方文档](https://modelcontextprotocol.io/specification/)\n- [MCP TypeScript SDK](https://github.com/modelcontextprotocol/modelcontextprotocol) ","readmeFilename":"README.md"}