/**
 * `mcp_describe` tool — describe tools on a connected MCP server.
 *
 * Two modes:
 *   mcp_describe(server)       → list all tools with params and descriptions
 *   mcp_describe(server, tool) → full JSON schema for one tool
 */
import { Type } from '@sinclair/typebox';
import { buildServerDetail } from './catalog.js';
import { errorResult, resolveServer } from './tool-helpers.js';
const schema = Type.Object({
    server: Type.String({ description: 'MCP server name' }),
    tool: Type.Optional(Type.String({
        description: 'Tool name to describe. Omit to list all tools on the server with their parameters and descriptions.'
    }))
});
/** Create the `mcp_describe` tool that lists or details tools on a connected MCP server. */
export function createMcpDescribeTool(connections) {
    return {
        name: 'mcp_describe',
        label: 'MCP Describe',
        description: 'Describe tools on a connected MCP server.\n' +
            '- mcp_describe(server) → list all tools with parameters and descriptions\n' +
            '- mcp_describe(server, tool) → full JSON schema for one tool',
        parameters: schema,
        async execute(_toolCallId, params) {
            const conn = resolveServer(connections, params.server);
            if (typeof conn === 'string')
                return errorResult(conn);
            // No tool specified → list all tools on this server.
            if (!params.tool) {
                return {
                    content: [{ type: 'text', text: buildServerDetail(conn) }],
                    details: undefined
                };
            }
            // Specific tool → return full JSON schema.
            const tool = conn.tools.find((t) => t.name === params.tool);
            if (!tool) {
                const available = conn.tools.map((t) => t.name).join(', ');
                return errorResult(`Unknown tool '${params.tool}' on server '${params.server}'. Available: ${available || '(none)'}`);
            }
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify(tool.inputSchema, null, 2)
                    }
                ],
                details: undefined
            };
        }
    };
}
//# sourceMappingURL=mcp-describe-tool.js.map