"use strict";
// =============================================================================
// Pure Agent - MCP Resource Tools
// Ported from Hermes mcp_tool.py (resource/prompt tools)
// =============================================================================
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerMCPResourceTools = registerMCPResourceTools;
const tool_registry_1 = require("../tool-registry");
const result_types_1 = require("../result-types");
const mcp_client_1 = require("../mcp-client");
// ---------------------------------------------------------------------------
// mcp_list_resources handler
// ---------------------------------------------------------------------------
async function mcpListResourcesHandler(_args, _context) {
    // MCP resources require the server to support resources capability
    // For now, return a note that this requires connected MCP servers with resource support
    const tools = (0, mcp_client_1.getMCPTools)();
    if (tools.length === 0) {
        return (0, result_types_1.toolResult)({
            success: true,
            resources: [],
            message: 'No MCP servers connected. Connect MCP servers to access their resources.',
        });
    }
    return (0, result_types_1.toolResult)({
        success: true,
        resources: [],
        message: 'Resource listing requires MCP servers with resources capability. Check mcp_status for connected servers.',
    });
}
// ---------------------------------------------------------------------------
// mcp_read_resource handler
// ---------------------------------------------------------------------------
async function mcpReadResourceHandler(args, context) {
    const { uri, server_name } = args;
    if (!uri)
        return (0, result_types_1.toolError)('Missing required parameter: uri');
    return (0, result_types_1.toolResult)({
        success: false,
        error: 'Resource reading requires MCP server support. Ensure the target server has resources capability enabled.',
        uri,
    });
}
// ---------------------------------------------------------------------------
// mcp_list_prompts handler
// ---------------------------------------------------------------------------
async function mcpListPromptsHandler(_args, _context) {
    const tools = (0, mcp_client_1.getMCPTools)();
    if (tools.length === 0) {
        return (0, result_types_1.toolResult)({
            success: true,
            prompts: [],
            message: 'No MCP servers connected.',
        });
    }
    return (0, result_types_1.toolResult)({
        success: true,
        prompts: [],
        message: 'Prompt listing requires MCP servers with prompts capability.',
    });
}
// ---------------------------------------------------------------------------
// mcp_get_prompt handler
// ---------------------------------------------------------------------------
async function mcpGetPromptHandler(args, _context) {
    const { name, arguments: promptArgs } = args;
    if (!name)
        return (0, result_types_1.toolError)('Missing required parameter: name');
    return (0, result_types_1.toolResult)({
        success: false,
        error: 'Prompt retrieval requires MCP server support.',
        name,
    });
}
// ---------------------------------------------------------------------------
// Registration
// ---------------------------------------------------------------------------
function registerMCPResourceTools() {
    tool_registry_1.registry.register({
        name: 'mcp_list_resources',
        toolset: 'mcp',
        schema: {
            description: 'List available resources from connected MCP servers. Resources are files, databases, or other data sources that MCP servers can provide.',
            parameters: { type: 'object', properties: {}, required: [] },
        },
        handler: mcpListResourcesHandler,
        isAsync: true,
        description: 'List MCP resources',
        emoji: '📦',
    });
    tool_registry_1.registry.register({
        name: 'mcp_read_resource',
        toolset: 'mcp',
        schema: {
            description: 'Read a specific resource from an MCP server by its URI.',
            parameters: {
                type: 'object',
                properties: {
                    uri: { type: 'string', description: 'Resource URI' },
                    server_name: { type: 'string', description: 'MCP server name (optional)' },
                },
                required: ['uri'],
            },
        },
        handler: mcpReadResourceHandler,
        isAsync: true,
        description: 'Read MCP resource',
        emoji: '📖',
    });
    tool_registry_1.registry.register({
        name: 'mcp_list_prompts',
        toolset: 'mcp',
        schema: {
            description: 'List available prompt templates from connected MCP servers.',
            parameters: { type: 'object', properties: {}, required: [] },
        },
        handler: mcpListPromptsHandler,
        isAsync: true,
        description: 'List MCP prompts',
        emoji: '💬',
    });
    tool_registry_1.registry.register({
        name: 'mcp_get_prompt',
        toolset: 'mcp',
        schema: {
            description: 'Get a specific prompt template from an MCP server.',
            parameters: {
                type: 'object',
                properties: {
                    name: { type: 'string', description: 'Prompt name' },
                    arguments: { type: 'object', description: 'Prompt arguments' },
                },
                required: ['name'],
            },
        },
        handler: mcpGetPromptHandler,
        isAsync: true,
        description: 'Get MCP prompt',
        emoji: '📝',
    });
}
// Auto-register
registerMCPResourceTools();
//# sourceMappingURL=mcp-resources.js.map