aira-mcp 1.0.3 → 1.0.5

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 (2) hide show
  1. package/index.js +252 -53
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -138,58 +138,270 @@ app.delete('/download/:gid', async (req, res) => {
138
138
  }
139
139
  });
140
140
 
141
+ // 定义服务提供的工具列表
142
+ const tools = [
143
+ {
144
+ name: 'aria2-download',
145
+ description: '使用aria2下载文件',
146
+ parameters: {
147
+ type: 'object',
148
+ properties: {
149
+ uri: {
150
+ type: 'string',
151
+ description: '要下载的文件URI'
152
+ },
153
+ options: {
154
+ type: 'object',
155
+ description: 'aria2下载选项',
156
+ additionalProperties: true
157
+ }
158
+ },
159
+ required: ['uri']
160
+ },
161
+ returnType: {
162
+ type: 'object',
163
+ properties: {
164
+ success: {
165
+ type: 'boolean'
166
+ },
167
+ gid: {
168
+ type: 'string',
169
+ description: 'aria2下载任务ID'
170
+ }
171
+ }
172
+ }
173
+ },
174
+ {
175
+ name: 'aria2-download-magnet',
176
+ description: '使用aria2下载magnet链接',
177
+ parameters: {
178
+ type: 'object',
179
+ properties: {
180
+ hashkey: {
181
+ type: 'string',
182
+ description: 'Magnet链接的hashkey'
183
+ },
184
+ options: {
185
+ type: 'object',
186
+ description: 'aria2下载选项',
187
+ additionalProperties: true
188
+ }
189
+ },
190
+ required: ['hashkey']
191
+ },
192
+ returnType: {
193
+ type: 'object',
194
+ properties: {
195
+ success: {
196
+ type: 'boolean'
197
+ },
198
+ gid: {
199
+ type: 'string',
200
+ description: 'aria2下载任务ID'
201
+ }
202
+ }
203
+ }
204
+ },
205
+ {
206
+ name: 'aria2-get-status',
207
+ description: '获取aria2下载任务状态',
208
+ parameters: {
209
+ type: 'object',
210
+ properties: {
211
+ gid: {
212
+ type: 'string',
213
+ description: 'aria2下载任务ID'
214
+ }
215
+ },
216
+ required: ['gid']
217
+ },
218
+ returnType: {
219
+ type: 'object',
220
+ properties: {
221
+ success: {
222
+ type: 'boolean'
223
+ },
224
+ status: {
225
+ type: 'object',
226
+ description: '下载任务状态信息'
227
+ }
228
+ }
229
+ }
230
+ },
231
+ {
232
+ name: 'aria2-pause',
233
+ description: '暂停aria2下载任务',
234
+ parameters: {
235
+ type: 'object',
236
+ properties: {
237
+ gid: {
238
+ type: 'string',
239
+ description: 'aria2下载任务ID'
240
+ }
241
+ },
242
+ required: ['gid']
243
+ },
244
+ returnType: {
245
+ type: 'object',
246
+ properties: {
247
+ success: {
248
+ type: 'boolean'
249
+ },
250
+ message: {
251
+ type: 'string'
252
+ }
253
+ }
254
+ }
255
+ },
256
+ {
257
+ name: 'aria2-resume',
258
+ description: '恢复aria2下载任务',
259
+ parameters: {
260
+ type: 'object',
261
+ properties: {
262
+ gid: {
263
+ type: 'string',
264
+ description: 'aria2下载任务ID'
265
+ }
266
+ },
267
+ required: ['gid']
268
+ },
269
+ returnType: {
270
+ type: 'object',
271
+ properties: {
272
+ success: {
273
+ type: 'boolean'
274
+ },
275
+ message: {
276
+ type: 'string'
277
+ }
278
+ }
279
+ }
280
+ },
281
+ {
282
+ name: 'aria2-remove',
283
+ description: '删除aria2下载任务',
284
+ parameters: {
285
+ type: 'object',
286
+ properties: {
287
+ gid: {
288
+ type: 'string',
289
+ description: 'aria2下载任务ID'
290
+ }
291
+ },
292
+ required: ['gid']
293
+ },
294
+ returnType: {
295
+ type: 'object',
296
+ properties: {
297
+ success: {
298
+ type: 'boolean'
299
+ },
300
+ message: {
301
+ type: 'string'
302
+ }
303
+ }
304
+ }
305
+ }
306
+ ];
307
+
141
308
  // MCP协议处理
142
309
  function handleMCPRequest(request) {
143
310
  process.stderr.write(`Received MCP request: ${JSON.stringify(request)}\n`);
144
311
 
145
312
  // 根据请求方法返回不同的响应
146
- if (request.method === 'initialize') {
147
- // 处理initialize请求,返回符合MCP协议规范的响应
148
- const response = {
149
- jsonrpc: '2.0',
150
- id: request.id,
151
- result: {
152
- protocolVersion: '2025-06-18',
153
- capabilities: {
154
- // 描述服务支持的功能
155
- httpServer: {
156
- port: port,
157
- endpoints: {
158
- '/health': 'GET',
159
- '/download': 'POST',
160
- '/download/magnet': 'POST',
161
- '/download/{gid}': 'GET',
162
- '/download/{gid}/pause': 'POST',
163
- '/download/{gid}/resume': 'POST',
164
- '/download/{gid}': 'DELETE'
313
+ switch (request.method) {
314
+ case 'initialize':
315
+ // 处理initialize请求,返回符合MCP协议规范的响应
316
+ return {
317
+ jsonrpc: '2.0',
318
+ id: request.id,
319
+ result: {
320
+ protocolVersion: '2025-06-18',
321
+ capabilities: {
322
+ // 描述服务支持的功能
323
+ httpServer: {
324
+ port: port,
325
+ endpoints: {
326
+ '/health': 'GET',
327
+ '/download': 'POST',
328
+ '/download/magnet': 'POST',
329
+ '/download/{gid}': 'GET',
330
+ '/download/{gid}/pause': 'POST',
331
+ '/download/{gid}/resume': 'POST',
332
+ '/download/{gid}': 'DELETE'
333
+ }
334
+ },
335
+ aria2: {
336
+ supportedMethods: ['addUri', 'tellStatus', 'pause', 'unpause', 'remove']
165
337
  }
166
338
  },
167
- aria2: {
168
- supportedMethods: ['addUri', 'tellStatus', 'pause', 'unpause', 'remove']
169
- }
170
- },
171
- serverInfo: {
339
+ serverInfo: {
172
340
  name: 'Aira MCP Service',
173
- version: '1.0.3',
341
+ version: '1.0.5',
174
342
  description: 'Aria2 MCP (Model Context Protocol) Service CLI',
175
343
  author: '',
176
344
  license: 'ISC'
345
+ },
346
+ tools: tools // 添加工具信息
347
+ }
348
+ };
349
+
350
+ case 'listTools':
351
+ // 处理listTools请求,返回工具列表
352
+ return {
353
+ jsonrpc: '2.0',
354
+ id: request.id,
355
+ result: {
356
+ tools: tools
177
357
  }
358
+ };
359
+
360
+ case 'getTool':
361
+ // 处理getTool请求,返回特定工具的详细信息
362
+ const toolName = request.params?.name;
363
+ if (!toolName) {
364
+ return {
365
+ jsonrpc: '2.0',
366
+ id: request.id,
367
+ error: {
368
+ code: -32602,
369
+ message: 'Invalid params: tool name is required'
370
+ }
371
+ };
178
372
  }
179
- };
180
- return response;
181
- } else {
182
- // 处理其他请求
183
- const response = {
184
- jsonrpc: '2.0',
185
- id: request.id,
186
- result: {
187
- message: 'MCP Service is running',
188
- httpPort: port,
189
- status: 'ok'
373
+
374
+ const tool = tools.find(t => t.name === toolName);
375
+ if (!tool) {
376
+ return {
377
+ jsonrpc: '2.0',
378
+ id: request.id,
379
+ error: {
380
+ code: -32602,
381
+ message: `Tool not found: ${toolName}`
382
+ }
383
+ };
190
384
  }
191
- };
192
- return response;
385
+
386
+ return {
387
+ jsonrpc: '2.0',
388
+ id: request.id,
389
+ result: {
390
+ tool: tool
391
+ }
392
+ };
393
+
394
+ default:
395
+ // 处理其他请求
396
+ return {
397
+ jsonrpc: '2.0',
398
+ id: request.id,
399
+ result: {
400
+ message: 'MCP Service is running',
401
+ httpPort: port,
402
+ status: 'ok'
403
+ }
404
+ };
193
405
  }
194
406
  }
195
407
 
@@ -249,18 +461,5 @@ process.on('SIGTERM', () => {
249
461
  process.exit(0);
250
462
  });
251
463
 
252
- // 初始化MCP服务就绪通知
253
- const initResponse = {
254
- jsonrpc: '2.0',
255
- id: null,
256
- result: {
257
- message: 'MCP Service initialized',
258
- httpPort: port,
259
- status: 'ready'
260
- }
261
- };
262
-
263
- // 发送初始化响应
264
- setTimeout(() => {
265
- process.stdout.write(JSON.stringify(initResponse) + '\n');
266
- }, 500);
464
+ // MCP服务不需要发送自定义的初始化响应
465
+ // 客户端会通过调用initialize方法来获取服务信息
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aira-mcp",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "main": "index.js",
5
5
  "bin": {
6
6
  "aira-mcp": "index.js"