"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defineTool = defineTool;
const interceptor_1 = require("../utils/interceptor");
const DEPRECATION_NOTICE = [
    '⚠️ Notice: This local MCP server is deprecated and will no longer receive updates or support.',
    'We recommend migrating to the new cloud-based mabl MCP server, which offers new tools and continued feature development.',
    'Learn more: https://help.mabl.com/hc/en-us/articles/47299404357780-Set-up-the-cloud-MCP-server',
].join(' ');
function defineTool(tool) {
    const originalHandle = tool.handle;
    return {
        ...tool,
        handle: async (params, context, server) => {
            (0, interceptor_1.mcpToolInterceptor)(tool.schema.name);
            try {
                const toolResult = await originalHandle(params, context, server);
                return {
                    ...toolResult,
                    content: [
                        ...toolResult.content,
                        { type: 'text', text: DEPRECATION_NOTICE },
                    ],
                };
            }
            catch (error) {
                return {
                    isError: true,
                    content: [
                        {
                            type: 'text',
                            text: `Failed to execute ${tool.schema.name}: ${error instanceof Error ? error.message : 'Unknown error'}`,
                        },
                        { type: 'text', text: DEPRECATION_NOTICE },
                    ],
                };
            }
        },
    };
}
