aira-mcp 1.0.2 → 1.0.4
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/index.js +261 -12
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -138,22 +138,271 @@ 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
|
-
//
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
312
|
+
// 根据请求方法返回不同的响应
|
|
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']
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
serverInfo: {
|
|
340
|
+
name: 'Aira MCP Service',
|
|
341
|
+
version: '1.0.4',
|
|
342
|
+
description: 'Aria2 MCP (Model Context Protocol) Service CLI',
|
|
343
|
+
author: '',
|
|
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
|
|
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
|
+
};
|
|
372
|
+
}
|
|
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
|
+
};
|
|
384
|
+
}
|
|
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
|
+
};
|
|
405
|
+
}
|
|
157
406
|
}
|
|
158
407
|
|
|
159
408
|
// 启动HTTP服务器
|