import type { Transport as McpTransport } from '@modelcontextprotocol/sdk/shared/transport.js'; import type { JSONRPCMessage } from '@modelcontextprotocol/sdk/types.js'; /** * SdkMcpTransport — In-process MCP transport. * * Instead of spawning a separate MCP server process, this routes JSON-RPC * messages through the SDK's control channel. When the CLI needs to call * a tool on this server, it sends a control_request{subtype:'mcp_message'}. * The SDK routes it to the McpServer instance via this transport, and * returns the response via control_response. * * Lifecycle: * 1. The SDK creates a SdkMcpTransport with a `sendMcpMessage` callback * that writes the outgoing JSON-RPC message back into the control * channel (typically resolving a pending control_request). * 2. When a control_request{type:'mcp_message'} arrives, the SDK calls * `transport.onmessage(msg)` to inject the request into the McpServer. * 3. The McpServer processes the request and calls `transport.send(response)`, * which invokes `sendMcpMessage` to deliver the response back. */ export declare class SdkMcpTransport implements McpTransport { /** * Callback that delivers an outgoing JSON-RPC message from the McpServer * back to the CLI via the control channel. */ private sendMcpMessage; /** * Whether this transport has been closed. */ private isClosed; /** * Called when the transport is closed (either explicitly or due to error). */ onclose?: () => void; /** * Called when an error occurs on the transport. */ onerror?: (error: Error) => void; /** * Called when a message is received from the CLI side. * The McpServer registers this handler to receive incoming JSON-RPC requests. */ onmessage?: (message: JSONRPCMessage) => void; /** * @param sendMcpMessage - Callback invoked when the McpServer sends a * response. This should route the message back through the SDK's * control channel to the CLI process. */ constructor(sendMcpMessage: (msg: JSONRPCMessage) => void); /** * Start the transport. * * No-op for in-process transport — the connection is pre-wired through * the control channel. The McpServer calls this during initialization * but no actual connection setup is needed. */ start(): Promise; /** * Send a JSON-RPC message from the McpServer to the CLI. * * This is called by the McpServer when it has a response (or notification) * to deliver. The message is routed through the `sendMcpMessage` callback * provided at construction time. * * @param message - The JSON-RPC message to send * @throws Error if the transport has been closed */ send(message: JSONRPCMessage): Promise; /** * Close the transport. * * Marks the transport as closed and invokes the `onclose` callback. * Subsequent calls to `send()` will throw. Closing is idempotent — * calling `close()` multiple times is safe. */ close(): Promise; /** * Whether the transport has been closed. */ get closed(): boolean; }