import { McpClient } from './mcp-client.js';
import { createTransportFromConfig } from './transports.js';
import { createLogger } from '../lib/logger.js';
export async function createMcpClient(options) {
    const { autoConnect = true } = options;
    const factoryLogger = createLogger('ClientFactory');
    factoryLogger.debug('Creating MCP client', {
        clientName: options.clientInfo.name,
        transportType: options.serverConfig.command ? 'stdio' : 'http',
        hasAuthProvider: !!options.authProvider,
    });
    const clientOptions = {
        capabilities: options.capabilities || {},
        ...(options.listChanged && { listChanged: options.listChanged }),
        logger: createLogger(`McpClient:${options.clientInfo.name}`),
        ...(options.serverConfig.timeout && { requestTimeout: options.serverConfig.timeout * 1000 }),
    };
    const client = new McpClient(options.clientInfo, clientOptions);
    if (autoConnect) {
        factoryLogger.debug('Creating transport with authProvider:', !!options.authProvider);
        factoryLogger.debug('Creating transport with mcpSessionId:', options.mcpSessionId || '(none)');
        const transportOptions = {};
        if (options.authProvider) {
            transportOptions.authProvider = options.authProvider;
        }
        if (options.mcpSessionId) {
            transportOptions.mcpSessionId = options.mcpSessionId;
        }
        const transport = createTransportFromConfig(options.serverConfig, transportOptions);
        await client.connect(transport);
    }
    return client;
}
//# sourceMappingURL=factory.js.map