mcp-adder-simple 1.0.8 → 1.0.9
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/mcp-adder.js +65 -4
- package/package.json +1 -1
package/mcp-adder.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const readline = require('readline');
|
|
7
|
-
|
|
7
|
+
const https = require('https');
|
|
8
8
|
// ========== 配置和初始化 ==========
|
|
9
9
|
|
|
10
10
|
// 创建 readline 接口用于处理 stdin/stdout 通信
|
|
@@ -53,7 +53,7 @@ rl.on('line', (line) => {
|
|
|
53
53
|
* 处理 MCP 请求
|
|
54
54
|
* @param {Object} msg - JSON-RPC 请求对象
|
|
55
55
|
*/
|
|
56
|
-
function handleRequest(msg) {
|
|
56
|
+
async function handleRequest(msg) {
|
|
57
57
|
let result = null;
|
|
58
58
|
let error = null;
|
|
59
59
|
|
|
@@ -69,7 +69,7 @@ function handleRequest(msg) {
|
|
|
69
69
|
break;
|
|
70
70
|
|
|
71
71
|
case 'tools/call':
|
|
72
|
-
result = handleToolCall(msg.params);
|
|
72
|
+
result = await handleToolCall(msg.params);
|
|
73
73
|
break;
|
|
74
74
|
|
|
75
75
|
default:
|
|
@@ -158,6 +158,24 @@ function handleToolsList() {
|
|
|
158
158
|
},
|
|
159
159
|
required: ['a', 'b']
|
|
160
160
|
}
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
name: 'sup8_decode',
|
|
164
|
+
description: '解码',
|
|
165
|
+
inputSchema: {
|
|
166
|
+
type: 'object',
|
|
167
|
+
properties: {
|
|
168
|
+
code: {
|
|
169
|
+
type: 'string',
|
|
170
|
+
description: '数码'
|
|
171
|
+
},
|
|
172
|
+
enterpriseNo: {
|
|
173
|
+
type: 'string',
|
|
174
|
+
description: '企业号'
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
required: ['code', 'enterpriseNo']
|
|
178
|
+
}
|
|
161
179
|
}
|
|
162
180
|
]
|
|
163
181
|
};
|
|
@@ -170,7 +188,7 @@ function handleToolsList() {
|
|
|
170
188
|
* @param {Object} params.arguments - 工具参数
|
|
171
189
|
* @returns {Object} 工具执行结果
|
|
172
190
|
*/
|
|
173
|
-
function handleToolCall(params) {
|
|
191
|
+
async function handleToolCall(params) {
|
|
174
192
|
const { name, arguments: args } = params;
|
|
175
193
|
|
|
176
194
|
if (name === 'add_numbers') {
|
|
@@ -209,6 +227,49 @@ function handleToolCall(params) {
|
|
|
209
227
|
]
|
|
210
228
|
};
|
|
211
229
|
|
|
230
|
+
} else if (name === 'sup8_decode') {
|
|
231
|
+
const { code, enterpriseNo } = args;
|
|
232
|
+
|
|
233
|
+
// 参数类型验证
|
|
234
|
+
if (typeof code !== 'string' || typeof enterpriseNo !== 'string') {
|
|
235
|
+
throw new Error('参数必须是字符串');
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// 构建请求 URL
|
|
239
|
+
const url = `https://pts.mama100.cn/restapi/digit/v2/digit/get-digit-info?code=${encodeURIComponent(code)}&enterpriseNo=${encodeURIComponent(enterpriseNo)}`;
|
|
240
|
+
|
|
241
|
+
console.error(`[HTTP] 调用外部API: ${url}`);
|
|
242
|
+
|
|
243
|
+
// 调用外部 API 并返回结果
|
|
244
|
+
const result = await new Promise((resolve, reject) => {
|
|
245
|
+
https.get(url, (res) => {
|
|
246
|
+
let data = '';
|
|
247
|
+
res.on('data', (chunk) => {
|
|
248
|
+
data += chunk;
|
|
249
|
+
});
|
|
250
|
+
res.on('end', () => {
|
|
251
|
+
try {
|
|
252
|
+
const jsonData = JSON.parse(data);
|
|
253
|
+
console.error(`[HTTP] API响应:`, JSON.stringify(jsonData, null, 2));
|
|
254
|
+
resolve(jsonData);
|
|
255
|
+
} catch (e) {
|
|
256
|
+
reject(new Error(`JSON解析失败: ${e.message}`));
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}).on('error', (err) => {
|
|
260
|
+
reject(new Error(`HTTP请求失败: ${err.message}`));
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
// 计算并返回结果
|
|
264
|
+
return {
|
|
265
|
+
content: [
|
|
266
|
+
{
|
|
267
|
+
type: 'text',
|
|
268
|
+
text: JSON.stringify(result, null, 2)
|
|
269
|
+
}
|
|
270
|
+
]
|
|
271
|
+
};
|
|
272
|
+
|
|
212
273
|
} else {
|
|
213
274
|
throw new Error(`未知工具: ${name}`);
|
|
214
275
|
}
|