import type { McpClient, McpServerConfig } from './client'
import { McpHttpClient } from './http-client'
import { McpSseClient } from './sse-client'
import { McpStdioClient } from './stdio-client'

export function createMcpClient(config: McpServerConfig): McpClient {
  if (config.transport === 'http') {
    return new McpHttpClient(config)
  }
  if (config.transport === 'sse') {
    return new McpSseClient(config)
  }
  return new McpStdioClient(config)
}

export function cloneMcpServerConfig(config: McpServerConfig): McpServerConfig {
  if (config.transport === 'http' || config.transport === 'sse') {
    return {
      ...config,
      auth: config.auth ? { ...config.auth } : undefined,
      headers: config.headers ? { ...config.headers } : undefined,
    }
  }

  return {
    ...config,
    args: [...config.args],
    env: config.env ? { ...config.env } : undefined,
  }
}
