UNPKG

@voyager-0x/agent-mcp

Version:

Voyager MCP Agent - A powerful Model Context Protocol agent

108 lines (107 loc) 4.89 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.innerToolsMcpModule = exports.GET_MORE_TOOLS = void 0; const zod_1 = __importDefault(require("zod")); const module_js_1 = require("./module.js"); exports.GET_MORE_TOOLS = "getMoreTools"; exports.innerToolsMcpModule = module_js_1.mcpModulesManager.createMcpBuiltinModule({ title: "工具发现与管理", description: "用于发现和获取系统中可用的工具模块,帮助扩展AI助手的能力", }, (mcpServer) => { mcpServer.registerTool("getToolsGroups", { title: "查看可用工具组列表", description: "获取系统中所有可用的工具组信息。每个工具组包含一组相关功能的工具,比如天气查询、文件操作、数据分析等。使用此工具来了解有哪些功能模块可以使用,然后根据用户需求选择合适的工具组进行加载。", }, async () => { const modules = module_js_1.mcpModulesManager.listMcpModules(); const _modules = []; for (const module of modules) { if (module.source !== "builtin") { _modules.push({ title: module.title, description: module.description, id: module.uuid, }); } } if (_modules.length === 0) { return { content: [ { type: "text", text: "当前系统中没有可用的外部工具组。", }, ], }; } const formattedText = `可用工具组列表:\n\n${_modules.map((module, index) => `${index + 1}. **${module.title}** (ID: ${module.id})\n 描述:${module.description}`).join('\n\n')}`; return { content: [ { type: "text", text: formattedText, }, ], }; }); mcpServer.registerTool(exports.GET_MORE_TOOLS, { title: "加载指定工具组的详细工具", description: "根据工具组ID加载具体的工具和资源。当用户需要使用特定功能时,先通过getToolsGroups查看可用工具组,然后使用此工具加载对应工具组中的具体工具。例如:用户想查天气,先查看工具组列表找到天气相关的工具组,然后加载该工具组获取具体的天气查询工具。", inputSchema: { ids: zod_1.default.array(zod_1.default.string()).describe("要加载的工具组ID数组。可以同时加载多个工具组,每个ID对应一个工具组。"), }, }, async ({ ids }) => { if (!ids || ids.length === 0) { return { content: [ { type: "text", text: "错误:请提供至少一个工具组ID。", }, ], }; } const tools = await module_js_1.mcpModulesManager.getTools({ uuids: ids }); const resources = await module_js_1.mcpModulesManager.getResources({ uuids: ids, }); let resultText = "已成功加载工具组!\n\n"; if (tools.length > 0) { resultText += "## 📋 可用工具列表:\n"; tools.forEach((tool, index) => { resultText += `${index + 1}. **${tool.name}**\n`; resultText += ` 描述:${tool.description || '暂无描述'}\n`; if (tool.inputSchema) { resultText += ` 参数:${JSON.stringify(tool.inputSchema, null, 2)}\n`; } resultText += ` 模块ID:${tool.moduleId}\n\n`; }); } else { resultText += "## 📋 工具列表:暂无可用工具\n\n"; } if (resources.length > 0) { resultText += "## 📚 可用资源列表:\n"; resources.forEach((resource, index) => { resultText += `${index + 1}. **${resource.name}**\n`; resultText += ` 描述:${resource.description || '暂无描述'}\n`; resultText += ` URI:${resource.uri}\n`; resultText += ` 模块ID:${resource.moduleId}\n\n`; }); } else { resultText += "## 📚 资源列表:暂无可用资源\n\n"; } resultText += "现在你可以使用这些工具来帮助用户完成任务了!"; return { content: [ { type: "text", text: resultText, }, ], }; }); });