(deps: CommandToolExecutorDeps = {})
| 58 | } |
| 59 | |
| 60 | export function createCommandToolExecutor(deps: CommandToolExecutorDeps = {}): CommandToolExecutor { |
| 61 | return { |
| 62 | execute: async (name, input) => { |
| 63 | if (!isCommandName(name)) { |
| 64 | throw new Error(`Unknown command tool: ${name}`); |
| 65 | } |
| 66 | const config = readMcpToolConfig(input); |
| 67 | const commandInput = stripMcpConfigFields(input); |
| 68 | const client = await createClient(deps, config.client); |
| 69 | const result = await (deps.runCommand ?? runCommand)(client, name, commandInput); |
| 70 | return { |
| 71 | isError: false, |
| 72 | structuredContent: result, |
| 73 | content: [ |
| 74 | { |
| 75 | type: 'text', |
| 76 | text: renderToolText({ |
| 77 | name, |
| 78 | input: commandInput, |
| 79 | result, |
| 80 | outputFormat: config.outputFormat, |
| 81 | responseLevel: config.client.responseLevel, |
| 82 | }), |
| 83 | }, |
| 84 | ], |
| 85 | }; |
| 86 | }, |
| 87 | }; |
| 88 | } |
| 89 | |
| 90 | export const commandToolExecutor = createCommandToolExecutor(); |
| 91 |
no test coverage detected