@weapp-vite/mcp 0.0.5 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/package.json +8 -6
- package/dist/index.cjs +0 -39
- package/dist/index.d.cts +0 -2
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @weapp-vite/mcp
|
|
2
|
+
|
|
3
|
+
## 简介
|
|
4
|
+
|
|
5
|
+
`@weapp-vite/mcp` 是一个基于 Model Context Protocol (MCP) SDK 的示例服务包,展示如何通过 stdio 传输方式注册工具并响应调用。
|
|
6
|
+
|
|
7
|
+
> 该包目前以示例为主,适合用于学习/验证 MCP 工具服务的基本结构。
|
|
8
|
+
|
|
9
|
+
## 特性
|
|
10
|
+
|
|
11
|
+
- 使用 MCP SDK 创建服务
|
|
12
|
+
- 基于 zod 的入参校验
|
|
13
|
+
- 内置示例工具(`calculate-bmi`、`fetch-weather`)
|
|
14
|
+
- stdio 传输,方便被 MCP Client 集成
|
|
15
|
+
|
|
16
|
+
## 安装
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pnpm add @weapp-vite/mcp
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## 使用
|
|
23
|
+
|
|
24
|
+
在仓库内启动示例服务:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm --filter @weapp-vite/mcp start
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
然后由 MCP Client 通过 stdio 连接并调用工具。
|
|
31
|
+
|
|
32
|
+
## 配置
|
|
33
|
+
|
|
34
|
+
目前没有独立配置文件。请直接修改 `src/index.ts` 来:
|
|
35
|
+
|
|
36
|
+
- 添加/移除工具
|
|
37
|
+
- 调整工具参数与逻辑
|
|
38
|
+
- 修改服务名称与版本
|
|
39
|
+
|
|
40
|
+
## 相关链接
|
|
41
|
+
|
|
42
|
+
- MCP SDK:https://github.com/modelcontextprotocol/sdk
|
|
43
|
+
- 仓库:https://github.com/weapp-vite/weapp-vite
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-vite/mcp",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.0.1",
|
|
5
5
|
"description": "mcp",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "ISC",
|
|
@@ -18,19 +18,21 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": {
|
|
20
20
|
"types": "./dist/index.d.ts",
|
|
21
|
-
"import": "./dist/index.mjs"
|
|
22
|
-
"require": "./dist/index.cjs"
|
|
21
|
+
"import": "./dist/index.mjs"
|
|
23
22
|
}
|
|
24
23
|
},
|
|
25
|
-
"main": "./dist/index.
|
|
24
|
+
"main": "./dist/index.mjs",
|
|
26
25
|
"module": "./dist/index.mjs",
|
|
27
26
|
"types": "./dist/index.d.ts",
|
|
28
27
|
"files": [
|
|
29
28
|
"dist"
|
|
30
29
|
],
|
|
30
|
+
"engines": {
|
|
31
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
32
|
+
},
|
|
31
33
|
"dependencies": {
|
|
32
|
-
"@modelcontextprotocol/sdk": "^1.25.
|
|
33
|
-
"zod": "^4.
|
|
34
|
+
"@modelcontextprotocol/sdk": "^1.25.3",
|
|
35
|
+
"zod": "^4.3.6"
|
|
34
36
|
},
|
|
35
37
|
"scripts": {
|
|
36
38
|
"dev": "unbuild --stub",
|
package/dist/index.cjs
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const mcp_js = require('@modelcontextprotocol/sdk/server/mcp.js');
|
|
4
|
-
const stdio_js = require('@modelcontextprotocol/sdk/server/stdio.js');
|
|
5
|
-
const zod = require('zod');
|
|
6
|
-
|
|
7
|
-
const server = new mcp_js.McpServer({
|
|
8
|
-
name: "Demo",
|
|
9
|
-
version: "1.0.0"
|
|
10
|
-
});
|
|
11
|
-
server.tool(
|
|
12
|
-
"calculate-bmi",
|
|
13
|
-
{
|
|
14
|
-
weightKg: zod.z.number(),
|
|
15
|
-
heightM: zod.z.number()
|
|
16
|
-
},
|
|
17
|
-
async ({ weightKg, heightM }) => ({
|
|
18
|
-
content: [{
|
|
19
|
-
type: "text",
|
|
20
|
-
text: String(weightKg / (heightM * heightM))
|
|
21
|
-
}]
|
|
22
|
-
})
|
|
23
|
-
);
|
|
24
|
-
server.tool(
|
|
25
|
-
"fetch-weather",
|
|
26
|
-
{ city: zod.z.string() },
|
|
27
|
-
async ({ city }) => {
|
|
28
|
-
const response = await fetch(`https://api.weather.com/${city}`);
|
|
29
|
-
const data = await response.text();
|
|
30
|
-
return {
|
|
31
|
-
content: [{ type: "text", text: data }]
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
const transport = new stdio_js.StdioServerTransport();
|
|
36
|
-
async function main() {
|
|
37
|
-
await server.connect(transport);
|
|
38
|
-
}
|
|
39
|
-
main();
|
package/dist/index.d.cts
DELETED