/** * MCP Client Wrapper * * Wraps the MCP SDK client to provide a simpler interface for the agent */ import type { IMcpRequestHeadersStrategy, ToolCall, ToolResult } from '@mcp-abap-adt/llm-agent'; /** Default per-call MCP request timeout in ms (2 minutes). * Consumer can override globally via MCPClientConfig.timeout or per-tool via MCPClientConfig.toolTimeouts. */ export declare const DEFAULT_MCP_REQUEST_TIMEOUT_MS = 120000; /** * Resolve the MCP request timeout for a specific tool call. * * Resolution order (first defined wins): * 1. config.toolTimeouts[name] — per-tool override * 2. config.timeout — global per-call default * 3. DEFAULT_MCP_REQUEST_TIMEOUT_MS (120 000 ms = 2 min) * * resetTimeoutOnProgress is always set to true by callTool so a slow but * actively-reporting tool never hits the ceiling. */ export declare function resolveToolTimeout(name: string, config: Pick): number; type McpToolDef = { name: string; description?: string; inputSchema?: Record; }; type EmbeddedServerInstance = { server?: unknown; }; export type TransportType = 'stdio' | 'sse' | 'stream-http' | 'auto' | 'embedded'; export interface MCPClientConfig { /** * Transport type: * - 'stdio': Standard input/output (for local processes) * - 'sse': Server-Sent Events (GET endpoint) * - 'stream-http': Streamable HTTP (POST endpoint, bidirectional NDJSON) * - 'auto': Automatically detect from URL (defaults to 'stream-http' for HTTP URLs) * - 'embedded': Direct MCP server instance (same process, no transport) * * If URL is provided and transport is 'auto', it will be detected automatically: * - URLs containing '/sse' or ending with '/sse' -> 'sse' * - URLs containing '/stream/http' or '/http' -> 'stream-http' * - Otherwise defaults to 'stream-http' */ transport?: TransportType; /** * For embedded mode: Direct MCP server instance * Use this when MCP server runs in the same process (e.g., imported as submodule) * The server instance must have: * - server.setRequestHandler() method for ListToolsRequestSchema and CallToolRequestSchema * - Or provide tools list and tool call handler directly */ serverInstance?: EmbeddedServerInstance; /** * For embedded mode: Direct access to tools registry * If provided, listTools() will use this instead of calling server */ toolsRegistry?: { getAllTools: () => McpToolDef[]; }; /** * For embedded mode: Direct tool call handler * If provided, callTool() will use this instead of calling server */ toolCallHandler?: (name: string, args: Record) => Promise; /** * Direct tools list provider (DI) * Use this to supply tools without relying on MCP transport details. */ listToolsHandler?: () => Promise; /** * Direct tool call provider (DI) * Use this to supply tool execution without relying on MCP transport details. */ callToolHandler?: (name: string, args: Record) => Promise; /** * For stdio: command and args to execute */ command?: string; args?: string[]; /** * For HTTP transports: URL endpoint * Examples: * - 'http://localhost:4004/mcp/stream/sse' -> SSE transport * - 'http://localhost:4004/mcp/stream/http' -> Streamable HTTP transport */ url?: string; /** * Session ID for HTTP transports (optional, will be generated if not provided) * For Streamable HTTP: first request should omit this, subsequent requests should include it */ sessionId?: string; /** * HTTP headers for authentication and configuration */ headers?: Record; /** Consumer-owned strategy contributing additional HTTP headers to MCP requests. * Independent of the client-side request timeout (see `timeout`/`toolTimeouts`): * a consumer may use this to convey a "willing to wait longer" hint to the server * or other per-request metadata. Default = no-op. */ requestHeadersStrategy?: IMcpRequestHeadersStrategy; /** Default per-call MCP request timeout in ms (default 120000 = 2 min). Per-tool overrides via toolTimeouts. resetTimeoutOnProgress extends it while a tool reports progress. */ timeout?: number; /** * Per-tool MCP request-timeout overrides in ms, keyed by tool name. * Takes precedence over `timeout`. Useful for known slow tools (e.g. long-running ABAP reports). * Example: `{ SlowReport: 900_000 }` — allow 15 min for SlowReport while keeping the 2 min default for everything else. */ toolTimeouts?: Record; } /** * Build StreamableHTTPClientTransport options from an already-resolved sessionId. * The caller MUST resolve the session id (via `_sessionForConnect()`) before calling * this helper — the helper intentionally does NOT read `config.sessionId` so that live * server-assigned ids always survive reconnect. * * No `signal` is set: MCP self-governs its request timeouts via the SDK's own mechanism. */ export declare function buildHttpTransportOptions(opts: { headers?: Record; sessionId?: string; requestHeadersStrategy?: IMcpRequestHeadersStrategy; }): { sessionId?: string; requestInit: { headers: Record; }; }; export declare class MCPClientWrapper { private client; private config; private tools; private detectedTransport; private sessionId?; constructor(config: MCPClientConfig); /** * Detect transport type from config */ private detectTransport; /** * Initialize MCP client connection */ connect(): Promise; /** * Get detected transport type */ getTransport(): TransportType; /** * Get current session ID (for HTTP transports) */ getSessionId(): string | undefined; /** * Session id to (re)connect with: prefer the live server-assigned id so a * reconnect RESUMES the same session (no lost session state / tool result); * fall back to the configured id on a first connect. */ private _sessionForConnect; /** * Get list of available tools */ listTools(): Promise; /** * Execute a tool call */ callTool(toolCall: ToolCall): Promise; /** * Execute multiple tool calls */ callTools(toolCalls: ToolCall[]): Promise; /** * Lightweight ping — verifies the MCP server is reachable * without triggering a full tools/list request. */ ping(): Promise; /** * Disconnect from MCP server */ disconnect(): Promise; } export {}; //# sourceMappingURL=client.d.ts.map