import { api } from './client'

export interface McpAuth {
  kind: string            // none | env_bearer | env_header
  env_key?: string
  header_name?: string
}

export interface McpServer {
  id: string
  name: string
  transport: string       // stdio | sse | http
  command_argv: string[]
  url: string
  auth: McpAuth
  enabled: boolean
  tool_risk_overrides: Record<string, string>
}

export interface McpTool {
  name: string
  description: string
  risk: string            // low | medium | high
}

export interface ProbeResult {
  status: string          // ok | unreachable | auth_failed | registered | unsupported
  tools: McpTool[]
  error: string
}

export const mcpApi = {
  list: () => api.get<{ servers: McpServer[] }>('/mcp'),
  add: (body: Partial<McpServer> & { id: string; allow_argv?: string[] }) =>
    api.post<{ ok: boolean; server: McpServer }>('/mcp', body),
  update: (id: string, body: Partial<McpServer> & { allow_argv?: string[] }) =>
    api.put<{ ok: boolean; server: McpServer }>(`/mcp/${id}`, body),
  remove: (id: string) => api.delete<{ ok: boolean }>(`/mcp/${id}`),
  probe: (id: string) => api.post<ProbeResult>(`/mcp/${id}/probe`),
}
