import type { ToolInputSchema } from '#cli/compat/plugin-api'
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js'

export const MCP_PROTOCOL_VERSION = '2025-11-25' as const

export type McpTool = Readonly<{
  name: string
  title?: string
  description?: string
  inputSchema: ToolInputSchema
  outputSchema?: Record<string, unknown>
}>

export interface JsonRpcRequest {
  jsonrpc: '2.0'
  id: string | number
  method: string
  params?: unknown
}

export interface JsonRpcResponse<T = unknown> {
  jsonrpc: '2.0'
  id: string | number
  result?: T
  error?: {
    code: number
    message: string
    data?: unknown
  }
}

export interface InitializeRequest {
  protocolVersion: string
  capabilities: {
    tools?: {
      listChanged?: boolean
    }
  }
  clientInfo: {
    name: string
    version: string
  }
}

export interface InitializeResult {
  protocolVersion?: string
  capabilities?: Record<string, unknown>
  serverInfo?: {
    name?: string
    version?: string
  }
}

export interface ListToolsResult {
  tools: McpTool[]
  nextCursor?: string
}

export interface CallToolRequest {
  name: string
  arguments: Record<string, unknown>
}

export type CallToolResultPayload = CallToolResult
