mcpluoqifang 1.1.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.
Files changed (3) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +33 -0
  3. package/server.js +81 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 luoqifang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "mcpluoqifang",
3
+ "version": "1.1.1",
4
+ "description": "An MCP (Model Context Protocol) server implementation over stdio transport.",
5
+ "type": "module",
6
+ "main": "server.js",
7
+ "bin": {
8
+ "mcpabc": "./server.js"
9
+ },
10
+ "files": [
11
+ "server.js",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "scripts": {
16
+ "start": "node server.js"
17
+ },
18
+ "keywords": [
19
+ "mcp",
20
+ "model-context-protocol",
21
+ "stdio",
22
+ "mcp-server"
23
+ ],
24
+ "author": "luoqifang",
25
+ "license": "MIT",
26
+ "dependencies": {
27
+ "@modelcontextprotocol/sdk": "^0.6.0",
28
+ "zod": "^3.23.8"
29
+ },
30
+ "engines": {
31
+ "node": ">=18"
32
+ }
33
+ }
package/server.js ADDED
@@ -0,0 +1,81 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { z } from "zod";
5
+ import fs from "fs/promises";
6
+ import path from "path";
7
+
8
+ // 1. 创建标准MCP服务实例
9
+ const mcpServer = new McpServer({
10
+ name: "demo-mcp-server",
11
+ version: "1.0.0"
12
+ });
13
+
14
+ // 工具1:sum 数字求和
15
+ mcpServer.tool(
16
+ "sum",
17
+ "计算两个数字的总和",
18
+ {
19
+ a: z.number().describe("第一个数字"),
20
+ b: z.number().describe("第二个数字")
21
+ },
22
+ async ({ a, b }) => {
23
+ const total = a + b;
24
+ return {
25
+ content: [
26
+ {
27
+ type: "text",
28
+ text: `计算结果:${a} + ${b} = ${total}`
29
+ }
30
+ ]
31
+ };
32
+ }
33
+ );
34
+
35
+ // 工具2:create_file 创建本地文件并写入内容
36
+ mcpServer.tool(
37
+ "create_file",
38
+ "在本地创建文件并写入文本内容",
39
+ {
40
+ filePath: z.string().describe("文件保存路径,例如 ./test.txt"),
41
+ content: z.string().describe("要写入文件的文本内容")
42
+ },
43
+ async ({ filePath, content }) => {
44
+ try {
45
+ // 自动创建父文件夹
46
+ const dir = path.dirname(filePath);
47
+ await fs.mkdir(dir, { recursive: true });
48
+ // 写入文件
49
+ await fs.writeFile(filePath, content, "utf8");
50
+ return {
51
+ content: [
52
+ {
53
+ type: "text",
54
+ text: `文件创建成功!路径:${path.resolve(filePath)},内容长度:${content.length}字符`
55
+ }
56
+ ]
57
+ };
58
+ } catch (err) {
59
+ return {
60
+ content: [
61
+ {
62
+ type: "text",
63
+ text: `文件创建失败:${err.message}`
64
+ }
65
+ ]
66
+ };
67
+ }
68
+ }
69
+ );
70
+
71
+ // 2. 绑定STDIO传输(完全匹配你MCP Inspector的STDIO模式)
72
+ async function run() {
73
+ const transport = new StdioServerTransport();
74
+ await mcpServer.connect(transport);
75
+ console.error("MCP STDIO Server 已启动,等待Inspector连接...");
76
+ }
77
+
78
+ run().catch(err => {
79
+ console.error("服务启动异常:", err);
80
+ process.exit(1);
81
+ });