UNPKG

@mseep/ableton-copilot-mcp

Version:
52 lines 1.66 kB
import { handleException } from '../error-handler.js'; import { ableton } from '../../ableton.js'; // Container for all decorators export const FactoryContainer = { tools: [], }; async function processToolReq(argsObj, originalFunc) { try { if (!ableton.isConnected()) { throw new Error('Ableton is not connected, please check if Ableton is running.'); } const args = argsObj ? Object.values(argsObj) : []; // @todo: 根据传进来的类型定义来调整参数顺序 const ans = await originalFunc(...args); return { content: [ { type: 'text', text: JSON.stringify(ans), } ] }; } catch (error) { return handleException(error); } } /** * Decorator for registering a tool with the server. */ export function tool(options) { return function (_, propertyKey, descriptor) { let func; const originalFunc = descriptor.value; if (!options) { func = function (server) { server.tool(propertyKey, async (args) => { return await processToolReq(args, originalFunc); }); }; } else { func = function (server) { server.tool(options.name ?? propertyKey, options.description ?? '', options.paramsSchema ?? {}, async (args) => { return await processToolReq(args, originalFunc); }); }; } FactoryContainer.tools.push(func); }; } //# sourceMappingURL=decorator.js.map