/**
 * Build compact catalog string from connected MCP servers.
 *
 * Compact format (for mcp tool description — keeps system prompt small):
 *   github: create_issue, search_repos, create_pull_request
 *   postgres: query, list_tables, describe_table
 *
 * Use mcp_describe(server) to get full tool details.
 */
import { getAgentLogPath } from '../../shared/logging/agent-log.js';
/**
 * Build a compact tool catalog — just server names and tool names.
 * Detailed descriptions are available via mcp_describe.
 */
export function buildCatalog(connections) {
    if (connections.length === 0)
        return '';
    const lines = connections.map((conn) => {
        const tools = conn.tools.map((t) => t.name).join(', ');
        return `  ${conn.name}: ${tools}`;
    });
    return `Connected MCP servers and tools:\n${lines.join('\n')}\n\nUse mcp_describe(server) to see tool parameters and descriptions before calling unfamiliar tools.`;
}
/**
 * Build a detailed tool listing for a single server (used by mcp_describe).
 */
export function buildServerDetail(connection) {
    const lines = connection.tools.map((t) => {
        const params = t.parameterNames.join(', ');
        const desc = t.description ? ` — ${t.description}` : '';
        return `  ${t.name}(${params})${desc}`;
    });
    return `${connection.name} — ${connection.tools.length} tools:\n${lines.join('\n')}`;
}
/**
 * Build a status line summary: "github (7 tools), postgres (4 tools)"
 */
function formatAuthSuffix(authStatus) {
    switch (authStatus) {
        case 'configured':
            return 'configured auth';
        case 'oauth':
            return 'oauth';
        case 'not_logged_in':
            return 'needs login';
        case 'unsupported':
        default:
            return 'no auth';
    }
}
export function buildStatusLine(entries) {
    const parts = [];
    let hasFailure = false;
    for (const entry of entries) {
        const authSuffix = entry.transport === 'streamable_http' && entry.authStatus !== 'unsupported'
            ? `, ${formatAuthSuffix(entry.authStatus)}`
            : '';
        if (entry.connected) {
            parts.push(`${entry.name} (${entry.connected.tools.length} tools${authSuffix})`);
        }
        else if (entry.failure) {
            hasFailure = true;
            if (entry.failureKind === 'auth_required') {
                parts.push(`${entry.name} (needs login - run /login -> MCP: ${entry.name})`);
            }
            else {
                parts.push(`${entry.name} (failed)`);
            }
        }
        else {
            parts.push(`${entry.name} (${formatAuthSuffix(entry.authStatus)})`);
        }
    }
    if (parts.length === 0) {
        return '';
    }
    const logSuffix = hasFailure ? `; logs: ${getAgentLogPath()}` : '';
    return `[MCP] ${parts.join(', ')}${logSuffix}`;
}
//# sourceMappingURL=catalog.js.map