amcjt-mcp-server 0.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 ADDED
@@ -0,0 +1,91 @@
1
+ # MCP Demo Server
2
+
3
+ A demo MCP (Model Context Protocol) server with stdio transport that provides basic arithmetic calculation tools.
4
+
5
+ ## Features
6
+
7
+ - **Calculator Tool**: Perform basic arithmetic operations (add, subtract, multiply, divide)
8
+ - **stdio Transport**: Communicate via standard input/output
9
+ - **TypeScript**: Written in TypeScript for better type safety
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install -g mcp-demo-server
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ### Direct execution
20
+ ```bash
21
+ npx mcp-demo-server
22
+ ```
23
+
24
+ ### As MCP server in Claude Desktop
25
+ Add to your Claude Desktop configuration:
26
+
27
+ ```json
28
+ {
29
+ "mcpServers": {
30
+ "demo-calculator": {
31
+ "command": "npx",
32
+ "args": ["mcp-demo-server"]
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ ## Available Tools
39
+
40
+ ### calculator
41
+ Perform basic arithmetic operations.
42
+
43
+ **Parameters:**
44
+ - `operation` (string, required): The arithmetic operation - one of: "add", "subtract", "multiply", "divide"
45
+ - `a` (number, required): First number
46
+ - `b` (number, required): Second number
47
+
48
+ **Example:**
49
+ ```json
50
+ {
51
+ "operation": "add",
52
+ "a": 5,
53
+ "b": 3
54
+ }
55
+ ```
56
+
57
+ **Returns:** The calculation result as text (e.g., "5 + 3 = 8")
58
+
59
+ ## Development
60
+
61
+ ```bash
62
+ # Install dependencies
63
+ npm install
64
+
65
+ # Build the project
66
+ npm run build
67
+
68
+ # Run in development mode
69
+ npm run dev
70
+
71
+ # Run the built server
72
+ npm start
73
+
74
+ ### 测试 Groovy MCP 服务器
75
+
76
+ npx @modelcontextprotocol/inspector npm run dev
77
+ ```
78
+
79
+ ## Publishing to NPM
80
+
81
+ ```bash
82
+ # Build the project
83
+ npm run build
84
+
85
+ # Publish to NPM
86
+ npm publish
87
+ ```
88
+
89
+ ## License
90
+
91
+ MIT
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import 'dotenv/config';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAGA,OAAO,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ // 加载 .env 文件中的环境变量
5
+ require("dotenv/config");
6
+ const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
7
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
8
+ const tools_1 = require("./tools");
9
+ const server = new mcp_js_1.McpServer({
10
+ name: 'amcjt-mcp-server',
11
+ version: '1.0.0',
12
+ });
13
+ // 注册所有工具
14
+ (0, tools_1.registerCalculatorTool)(server);
15
+ (0, tools_1.registerMoonshotBalanceTool)(server);
16
+ (0, tools_1.registerWeChatWorkTool)(server);
17
+ async function main() {
18
+ const transport = new stdio_js_1.StdioServerTransport();
19
+ console.error('amcjt-mcp-server starting...');
20
+ await server.connect(transport);
21
+ console.error('amcjt-mcp-server running on stdio');
22
+ }
23
+ main().catch((error) => {
24
+ console.error('Failed to start server:', error);
25
+ process.exit(1);
26
+ });
27
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,mBAAmB;AACnB,yBAAuB;AAEvB,oEAAoE;AACpE,wEAAiF;AACjF,mCAAsG;AAEtG,MAAM,MAAM,GAAG,IAAI,kBAAS,CAAC;IAC3B,IAAI,EAAE,kBAAkB;IACxB,OAAO,EAAE,OAAO;CACjB,CAAC,CAAC;AAEH,SAAS;AACT,IAAA,8BAAsB,EAAC,MAAM,CAAC,CAAC;AAC/B,IAAA,mCAA2B,EAAC,MAAM,CAAC,CAAC;AACpC,IAAA,8BAAsB,EAAC,MAAM,CAAC,CAAC;AAE/B,KAAK,UAAU,IAAI;IACjB,MAAM,SAAS,GAAG,IAAI,+BAAoB,EAAE,CAAC;IAE7C,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC9C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;AACrD,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;IAChD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ /**
3
+ * 注册一个计算器工具到MCP服务器
4
+ * @param server - MCP服务器实例,用于注册工具
5
+ */
6
+ export declare function registerCalculatorTool(server: McpServer): void;
7
+ //# sourceMappingURL=calculator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculator.d.ts","sourceRoot":"","sources":["../../src/tools/calculator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAC;AAGlE;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,QAqHvD"}
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerCalculatorTool = registerCalculatorTool;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * 注册一个计算器工具到MCP服务器
7
+ * @param server - MCP服务器实例,用于注册工具
8
+ */
9
+ function registerCalculatorTool(server) {
10
+ // 注册名为calculator的工具
11
+ server.registerTool('calculator', {
12
+ // 工具标题
13
+ title: '计算器',
14
+ // 工具描述,说明其功能
15
+ description: '执行基本的算术运算(加法、减法、乘法、除法)',
16
+ // 输入参数的Schema定义
17
+ inputSchema: zod_1.z.object({
18
+ // 运算类型,只能是四种基本运算之一
19
+ operation: zod_1.z.enum(['add', 'subtract', 'multiply', 'divide']),
20
+ // 第一个操作数
21
+ a: zod_1.z.number().describe('第一个操作数'),
22
+ // 第二个操作数
23
+ b: zod_1.z.number().describe('第二个操作数')
24
+ })
25
+ },
26
+ // 异步处理函数,接收输入参数并返回计算结果
27
+ async (args) => {
28
+ try {
29
+ // 从参数中解构出运算类型和两个操作数
30
+ const { operation, a, b } = args;
31
+ // 参数验证
32
+ if (!operation || !['add', 'subtract', 'multiply', 'divide'].includes(operation)) {
33
+ return {
34
+ content: [
35
+ {
36
+ type: 'text',
37
+ text: '错误:无效的运算类型。必须是以下之一:add(加法)、subtract(减法)、multiply(乘法)、divide(除法)',
38
+ },
39
+ ],
40
+ isError: true,
41
+ };
42
+ }
43
+ if (typeof a !== 'number' || typeof b !== 'number') {
44
+ return {
45
+ content: [
46
+ {
47
+ type: 'text',
48
+ text: '错误:参数 a 和 b 必须是数字',
49
+ },
50
+ ],
51
+ isError: true,
52
+ };
53
+ }
54
+ let result;
55
+ let operationSymbol;
56
+ switch (operation) {
57
+ case 'add':
58
+ result = a + b;
59
+ operationSymbol = '+';
60
+ break;
61
+ case 'subtract':
62
+ result = a - b;
63
+ operationSymbol = '-';
64
+ break;
65
+ case 'multiply':
66
+ result = a * b;
67
+ operationSymbol = '*';
68
+ break;
69
+ case 'divide':
70
+ if (b === 0) {
71
+ return {
72
+ content: [
73
+ {
74
+ type: 'text',
75
+ text: '错误:不允许除以零',
76
+ },
77
+ ],
78
+ isError: true,
79
+ };
80
+ }
81
+ result = a / b;
82
+ operationSymbol = '/';
83
+ break;
84
+ default:
85
+ return {
86
+ content: [
87
+ {
88
+ type: 'text',
89
+ text: `错误:未知的运算类型 '${operation}'`,
90
+ },
91
+ ],
92
+ isError: true,
93
+ };
94
+ }
95
+ const calculation = `${a} ${operationSymbol} ${b} = ${result}`;
96
+ return {
97
+ content: [
98
+ {
99
+ type: 'text',
100
+ text: calculation,
101
+ },
102
+ ],
103
+ };
104
+ }
105
+ catch (error) {
106
+ const errorMessage = error instanceof Error ? error.message : '发生未知错误';
107
+ return {
108
+ content: [
109
+ {
110
+ type: 'text',
111
+ text: `错误: ${errorMessage}`,
112
+ },
113
+ ],
114
+ isError: true,
115
+ };
116
+ }
117
+ });
118
+ }
119
+ //# sourceMappingURL=calculator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"calculator.js","sourceRoot":"","sources":["../../src/tools/calculator.ts"],"names":[],"mappings":";;AAOA,wDAqHC;AA3HD,6BAAsB;AAEtB;;;GAGG;AACH,SAAgB,sBAAsB,CAAC,MAAiB;IACpD,oBAAoB;IACpB,MAAM,CAAC,YAAY,CACf,YAAY,EACZ;QACI,OAAO;QACP,KAAK,EAAE,KAAK;QACZ,aAAa;QACb,WAAW,EAAE,wBAAwB;QACrC,gBAAgB;QAChB,WAAW,EAAE,OAAC,CAAC,MAAM,CAAC;YAClB,mBAAmB;YACnB,SAAS,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;YAC5D,SAAS;YACT,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAChC,SAAS;YACT,CAAC,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;SACnC,CAAC;KACL;IACD,uBAAuB;IACvB,KAAK,EAAE,IAAS,EAAE,EAAE;QAChB,IAAI,CAAC;YACD,oBAAoB;YACpB,MAAM,EAAC,SAAS,EAAE,CAAC,EAAE,CAAC,EAAC,GAAG,IAAI,CAAC;YAE/B,OAAO;YACP,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC,KAAK,EAA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AAI,EAAE,eAAe,SAAS,GAAG;6BACpC;yBACJ;wBACD,OAAO,EAAE,IAAI;qBAChB,CAAC;YACV,CAAC;YAED,MAAM,WAAW,GAAG,GAAG,CAAC,IAAI,eAAe,IAAI,CAAC,MAAM,MAAM,EAAE,CAAC;YAE/D,OAAO;gBACH,OAAO,EAAE;oBACL;wBACI,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,WAAW;qBACpB;iBACJ;aACJ,CAAC;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;YACvE,OAAO;gBACH,OAAO,EAAE;oBACL;wBACI,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,OAAO,YAAY,EAAE;qBAC9B;iBACJ;gBACD,OAAO,EAAE,IAAI;aAChB,CAAC;QACN,CAAC;IACL,CAAC,CACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { registerCalculatorTool } from './calculator';
2
+ export { registerMoonshotBalanceTool } from './moonshot-balance';
3
+ export { registerWeChatWorkTool } from './wechat-work';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,2BAA2B,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerWeChatWorkTool = exports.registerMoonshotBalanceTool = exports.registerCalculatorTool = void 0;
4
+ var calculator_1 = require("./calculator");
5
+ Object.defineProperty(exports, "registerCalculatorTool", { enumerable: true, get: function () { return calculator_1.registerCalculatorTool; } });
6
+ var moonshot_balance_1 = require("./moonshot-balance");
7
+ Object.defineProperty(exports, "registerMoonshotBalanceTool", { enumerable: true, get: function () { return moonshot_balance_1.registerMoonshotBalanceTool; } });
8
+ var wechat_work_1 = require("./wechat-work");
9
+ Object.defineProperty(exports, "registerWeChatWorkTool", { enumerable: true, get: function () { return wechat_work_1.registerWeChatWorkTool; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AAA7C,oHAAA,sBAAsB,OAAA;AAC/B,uDAAiE;AAAxD,+HAAA,2BAA2B,OAAA;AACpC,6CAAuD;AAA9C,qHAAA,sBAAsB,OAAA"}
@@ -0,0 +1,7 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ /**
3
+ * 注册Moonshot余额查询工具到MCP服务器
4
+ * @param server - MCP服务器实例,用于注册工具
5
+ */
6
+ export declare function registerMoonshotBalanceTool(server: McpServer): void;
7
+ //# sourceMappingURL=moonshot-balance.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moonshot-balance.d.ts","sourceRoot":"","sources":["../../src/tools/moonshot-balance.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAC;AAGlE;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,SAAS,QAsG5D"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerMoonshotBalanceTool = registerMoonshotBalanceTool;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * 注册Moonshot余额查询工具到MCP服务器
7
+ * @param server - MCP服务器实例,用于注册工具
8
+ */
9
+ function registerMoonshotBalanceTool(server) {
10
+ // 注册名为query_moonshot_balance的工具
11
+ server.registerTool('query_moonshot_balance', {
12
+ // 工具标题
13
+ title: 'Moonshot余额查询|Kimi余额查询',
14
+ // 工具描述,说明其功能
15
+ description: '查询 Moonshot AI(Kimi) 账户余额',
16
+ // 输入参数的Schema定义
17
+ inputSchema: zod_1.z.object({})
18
+ },
19
+ // 异步处理函数,接收输入参数并返回查询结果
20
+ async (args) => {
21
+ try {
22
+ const API_KEY = process.env.MOONSHOT_API_KEY;
23
+ const API_HOST = "api.moonshot.cn";
24
+ const API_PATH = "/v1/users/me/balance";
25
+ const url = `https://${API_HOST}${API_PATH}`;
26
+ const response = await fetch(url, {
27
+ method: 'GET',
28
+ headers: {
29
+ 'Authorization': `Bearer ${API_KEY}`,
30
+ 'Content-Type': 'application/json'
31
+ }
32
+ });
33
+ if (!response.ok) {
34
+ const errorData = await response.json();
35
+ throw new Error(`API错误: ${errorData.message || '未知错误'}`);
36
+ }
37
+ const data = await response.json();
38
+ if (data.code !== 0) {
39
+ throw new Error(`API错误: ${data.message || '未知错误'}`);
40
+ }
41
+ const formatMoney = (value) => {
42
+ if (value == null)
43
+ return "0.00元";
44
+ try {
45
+ const num = parseFloat(value.toString());
46
+ return `${num.toFixed(2)}元`;
47
+ }
48
+ catch (e) {
49
+ const str = value.toString();
50
+ if (str.includes('.')) {
51
+ const parts = str.split('.');
52
+ return `${parts[0]}.${(parts[1] + '00').slice(0, 2)}元`;
53
+ }
54
+ return `${str}.00元`;
55
+ }
56
+ };
57
+ const now = new Date();
58
+ const queryTime = now.toLocaleString('zh-CN', {
59
+ year: 'numeric',
60
+ month: '2-digit',
61
+ day: '2-digit',
62
+ hour: '2-digit',
63
+ minute: '2-digit',
64
+ second: '2-digit'
65
+ });
66
+ const result = {
67
+ available_balance: formatMoney(data.data.available_balance),
68
+ voucher_balance: formatMoney(data.data.voucher_balance),
69
+ cash_balance: formatMoney(data.data.cash_balance),
70
+ query_time: queryTime
71
+ };
72
+ return {
73
+ content: [
74
+ {
75
+ type: 'text',
76
+ text: JSON.stringify(result, null, 2)
77
+ }
78
+ ]
79
+ };
80
+ }
81
+ catch (error) {
82
+ const errorMessage = error instanceof Error ? error.message : '发生未知错误';
83
+ return {
84
+ content: [
85
+ {
86
+ type: 'text',
87
+ text: `错误: ${errorMessage}`
88
+ }
89
+ ],
90
+ isError: true
91
+ };
92
+ }
93
+ });
94
+ }
95
+ //# sourceMappingURL=moonshot-balance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"moonshot-balance.js","sourceRoot":"","sources":["../../src/tools/moonshot-balance.ts"],"names":[],"mappings":";;AAOA,kEAsGC;AA5GD,6BAAsB;AAEtB;;;GAGG;AACH,SAAgB,2BAA2B,CAAC,MAAiB;IACzD,gCAAgC;IAChC,MAAM,CAAC,YAAY,CACf,wBAAwB,EACxB;QACI,OAAO;QACP,KAAK,EAAE,uBAAuB;QAC9B,aAAa;QACb,WAAW,EAAE,2BAA2B;QACxC,gBAAgB;QAChB,WAAW,EAAE,OAAC,CAAC,MAAM,CAAC,EAAE,CAAC;KAC5B;IACD,uBAAuB;IACvB,KAAK,EAAE,IAAS,EAAE,EAAE;QAChB,IAAI,CAAC;YACD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC;YAC7C,MAAM,QAAQ,GAAG,iBAAiB,CAAC;YACnC,MAAM,QAAQ,GAAG,sBAAsB,CAAC;YAExC,MAAM,GAAG,GAAG,WAAW,QAAQ,GAAG,QAAQ,EAAE,CAAC;YAE7C,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE;gBAC9B,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE;oBACL,eAAe,EAAE,UAAU,OAAO,EAAE;oBACpC,cAAc,EAAE,kBAAkB;iBACrC;aACJ,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBACf,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC,IAAI,EAA0B,CAAC;gBAChE,MAAM,IAAI,KAAK,CAAC,UAAU,SAAS,CAAC,OAAO,IAAI,M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AS;aACpB,CAAC,CAAC;YAEH,MAAM,MAAM,GAAG;gBACX,iBAAiB,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC;gBAC3D,eAAe,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;gBACvD,YAAY,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC;gBACjD,UAAU,EAAE,SAAS;aACxB,CAAC;YAEF,OAAO;gBACH,OAAO,EAAE;oBACL;wBACI,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;qBACxC;iBACJ;aACJ,CAAC;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,CAAC;YACvE,OAAO;gBACH,OAAO,EAAE;oBACL;wBACI,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,OAAO,YAAY,EAAE;qBAC9B;iBACJ;gBACD,OAAO,EAAE,IAAI;aAChB,CAAC;QACN,CAAC;IACL,CAAC,CACJ,CAAC;AACN,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ /**
3
+ * 注册企业微信消息发送工具到MCP服务器
4
+ * @param server - MCP服务器实例,用于注册工具
5
+ */
6
+ export declare function registerWeChatWorkTool(server: McpServer): void;
7
+ //# sourceMappingURL=wechat-work.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wechat-work.d.ts","sourceRoot":"","sources":["../../src/tools/wechat-work.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,yCAAyC,CAAC;AAGlE;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,QAoHvD"}
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.registerWeChatWorkTool = registerWeChatWorkTool;
4
+ const zod_1 = require("zod");
5
+ /**
6
+ * 注册企业微信消息发送工具到MCP服务器
7
+ * @param server - MCP服务器实例,用于注册工具
8
+ */
9
+ function registerWeChatWorkTool(server) {
10
+ // 注册名为send_wechat_work_message的工具
11
+ server.registerTool('send_wechat_work_message', {
12
+ // 工具标题
13
+ title: '企业微信消息发送',
14
+ // 工具描述,说明其功能
15
+ description: '通过企业微信机器人发送消息',
16
+ // 输入参数的Schema定义
17
+ inputSchema: zod_1.z.object({
18
+ // 企业微信机器人webhook的key部分(可选)
19
+ webhook_key: zod_1.z.string().optional()
20
+ .describe("企业微信机器人webhook的key部分(可选,默认使用环境变量 WECHAT_WEBHOOK_KEY)"),
21
+ // 要发送的消息内容
22
+ message: zod_1.z.string()
23
+ .describe("要发送的消息内容"),
24
+ // 消息类型
25
+ message_type: zod_1.z.enum(["text", "markdown"]).optional().default("text")
26
+ .describe("消息类型,可选:text(默认)、markdown")
27
+ }).required({
28
+ message: true
29
+ })
30
+ },
31
+ // 异步处理函数,接收输入参数并返回发送结果
32
+ async (args) => {
33
+ try {
34
+ const webhookKey = args.webhook_key || process.env.WECHAT_WEBHOOK_KEY;
35
+ const message = args.message;
36
+ const messageType = args.message_type || "text";
37
+ if (!message) {
38
+ return {
39
+ content: [
40
+ {
41
+ type: 'text',
42
+ text: '错误:消息内容不能为空'
43
+ }
44
+ ],
45
+ isError: true
46
+ };
47
+ }
48
+ const webhookUrl = `https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${webhookKey}`;
49
+ const body = {
50
+ msgtype: messageType,
51
+ [messageType]: {
52
+ content: message
53
+ }
54
+ };
55
+ const response = await fetch(webhookUrl, {
56
+ method: 'POST',
57
+ headers: {
58
+ 'Content-Type': 'application/json; charset=UTF-8',
59
+ 'User-Agent': 'MCP-Server/1.0'
60
+ },
61
+ body: JSON.stringify(body)
62
+ });
63
+ if (!response.ok) {
64
+ const errorData = await response.json();
65
+ throw new Error(`企业微信API错误: ${errorData.errmsg || '未知错误'}`);
66
+ }
67
+ const responseJson = await response.json();
68
+ if (responseJson.errcode !== 0) {
69
+ throw new Error(`企业微信API错误: ${responseJson.errmsg || '未知错误'}`);
70
+ }
71
+ const now = new Date();
72
+ const sendTime = now.toLocaleString('zh-CN', {
73
+ year: 'numeric',
74
+ month: '2-digit',
75
+ day: '2-digit',
76
+ hour: '2-digit',
77
+ minute: '2-digit',
78
+ second: '2-digit'
79
+ });
80
+ const result = {
81
+ success: true,
82
+ message: "消息发送成功",
83
+ response: responseJson,
84
+ send_time: sendTime,
85
+ webhook_key: webhookKey
86
+ };
87
+ return {
88
+ content: [
89
+ {
90
+ type: 'text',
91
+ text: JSON.stringify(result, null, 2)
92
+ }
93
+ ]
94
+ };
95
+ }
96
+ catch (error) {
97
+ const errorMessage = error instanceof Error ? error.message : '发生未知错误';
98
+ return {
99
+ content: [
100
+ {
101
+ type: 'text',
102
+ text: `错误: ${errorMessage}`
103
+ }
104
+ ],
105
+ isError: true
106
+ };
107
+ }
108
+ });
109
+ }
110
+ //# sourceMappingURL=wechat-work.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wechat-work.js","sourceRoot":"","sources":["../../src/tools/wechat-work.ts"],"names":[],"mappings":";;AAOA,wDAoHC;AA1HD,6BAAsB;AAEtB;;;GAGG;AACH,SAAgB,sBAAsB,CAAC,MAAiB;IACpD,kCAAkC;IAClC,MAAM,CAAC,YAAY,CACf,0BAA0B,EAC1B;QACI,OAAO;QACP,KAAK,EAAE,UAAU;QACjB,aAAa;QACb,WAAW,EAAE,eAAe;QAC5B,gBAAgB;QAChB,WAAW,EAAE,OAAC,CAAC,MAAM,CAAC;YAClB,2BAA2B;YAC3B,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;iBAC7B,QAAQ,CAAC,sDAAsD,CAAC;YAC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;iBACJ;gBACD,OAAO,EAAE,IAAI;aAChB,CAAC;QACN,CAAC;IACL,CAAC,CACJ,CAAC;AACN,CAAC"}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "amcjt-mcp-server",
3
+ "version": "0.0.1",
4
+ "description": "A demo MCP server with stdio transport",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "amcjt-mcp-server": "dist/index.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "dev": "tsx src/index.ts",
12
+ "start": "node dist/index.js",
13
+ "prepare": "npm run build"
14
+ },
15
+ "keywords": [
16
+ "mcp",
17
+ "server",
18
+ "stdio",
19
+ "tools"
20
+ ],
21
+ "author": "jint",
22
+ "license": "MIT",
23
+ "dependencies": {
24
+ "@modelcontextprotocol/sdk": "^1.26.0",
25
+ "dotenv": "^17.3.1",
26
+ "zod": "^4.3.6"
27
+ },
28
+ "devDependencies": {
29
+ "@types/dotenv": "^6.1.1",
30
+ "@types/node": "^20.0.0",
31
+ "tsx": "^4.0.0",
32
+ "typescript": "^5.0.0"
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "README.md"
37
+ ],
38
+ "engines": {
39
+ "node": ">=18.0.0"
40
+ }
41
+ }