import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
import * as z from 'zod';
import { executeClio } from '../clio/executor.js';
/**
* Register the raw CLIO command escape hatch.
* Allows executing any CLIO command with freeform arguments.
*/
export function registerRawTool(server: McpServer): void {
server.registerTool(
'clio-raw',
{
description: 'Execute any CLIO command with custom arguments. Use this for commands not yet supported by dedicated tools. Example: "get-pkg-list -e myenv" or "compile-configuration -e production"',
inputSchema: {
command: z.string().describe('Full CLIO command with arguments (e.g., "get-pkg-list -e myenv" or "push-pkg MyPackage -e dev")'),
},
annotations: {
title: 'CLIO Raw Command',
openWorldHint: true,
destructiveHint: true, // Unknown commands could be destructive
},
},
async ({ command }): Promise<CallToolResult> => {
// Parse the command string into parts
const parts = command.trim().split(/\s+/);
if (parts.length === 0) {
return {
content: [
{
type: 'text',
text: 'Error: Empty command provided',
},
],
isError: true,
};
}
const clioCommand = parts[0];
const args = parts.slice(1);
const result = await executeClio(clioCommand, args);
if (!result.success) {
return {
content: [
{
type: 'text',
text: `Error executing clio ${clioCommand}:\n${result.error}\n\n${result.output}`,
},
],
isError: true,
};
}
return {
content: [
{
type: 'text',
text: result.output,
},
],
};
}
);
}