/** * MCP Elicitation — native in-client approval prompts. * * Implements the MCP elicitation capability (spec revision 2025-06-18): * the server sends an `elicitation/create` JSON-RPC request *to the client*, * the client renders it natively (Claude Code, Codex, Gemini CLI, Cursor…), * and the user's answer comes back as the response. * * Network-AI uses this to surface `ApprovalGate` / `ApprovalInbox` decisions * directly inside the MCP client instead of a separate HTTP inbox: wrap a * request sender with {@link createElicitationApprovalCallback} and pass the * resulting callback to `ApprovalGate`. * * Transport plumbing for stdio servers is provided by * {@link StdioElicitationChannel}: it assigns request ids, writes * newline-delimited JSON-RPC to the client, and resolves pending promises * when responses arrive. * * @example * ```ts * const channel = new StdioElicitationChannel((line) => process.stdout.write(line + '\n')); * // in the stdin loop: if (channel.handleMessage(parsed)) return; // consumed a response * const approvalCallback = createElicitationApprovalCallback( * (params) => channel.request('elicitation/create', params), * ); * const gate = new ApprovalGate(approvalCallback); * ``` * * @module McpElicitation * @version 1.0.0 */ import type { ApprovalRequest, ApprovalDecision } from './agent-runtime'; /** Flat-primitive schema property allowed by MCP elicitation */ export interface ElicitationSchemaProperty { type: 'string' | 'number' | 'integer' | 'boolean'; title?: string; description?: string; enum?: string[]; default?: string | number | boolean; } /** The restricted object schema MCP elicitation requests may carry */ export interface ElicitationRequestedSchema { type: 'object'; properties: Record; required?: string[]; } /** Params for an `elicitation/create` request */ export interface ElicitationCreateParams { /** Human-readable message presented to the user */ message: string; /** Schema describing the structured content requested from the user */ requestedSchema: ElicitationRequestedSchema; } /** Result of an `elicitation/create` request */ export interface ElicitationResult { /** 'accept' (user submitted), 'decline' (explicit no), 'cancel' (dismissed) */ action: 'accept' | 'decline' | 'cancel'; /** The user's structured answer — present only when action is 'accept' */ content?: Record; } /** * Sends an elicitation request to the connected client and resolves its * result. Implementations own the transport (stdio, streamable HTTP, …). */ export type ElicitationRequestSender = (params: ElicitationCreateParams) => Promise; /** Options for {@link createElicitationApprovalCallback} */ export interface ElicitationApprovalOptions { /** Identity recorded on decisions approved via elicitation (default: 'mcp-client') */ approvedBy?: string; /** Overall timeout for the elicitation round-trip in ms (default: 300000 = 5 min) */ timeoutMs?: number; } /** * Build an `ApprovalCallback` (as used by `ApprovalGate` / `AgentRuntime`) * that resolves approvals by asking the connected MCP client through * elicitation. Fail-closed: timeouts, transport errors, declines, and * cancellations all resolve to `approved: false`. */ export declare function createElicitationApprovalCallback(send: ElicitationRequestSender, options?: ElicitationApprovalOptions): (request: ApprovalRequest) => Promise; /** * Server→client request channel for newline-delimited JSON-RPC transports * (stdio). Assigns unique ids to outgoing requests and resolves the pending * promise when the matching response arrives. * * Integration contract for the stdin loop: for every parsed inbound message, * call {@link handleMessage} first — if it returns `true` the message was a * response to a server-initiated request and must not be dispatched as a * client request. */ export declare class StdioElicitationChannel { private readonly write; private readonly pending; private nextId; private readonly defaultTimeoutMs; /** * @param write Writes one serialized JSON-RPC line to the client. * @param defaultTimeoutMs Per-request timeout (default: 300000 = 5 min). */ constructor(write: (line: string) => void, defaultTimeoutMs?: number); /** Number of requests currently awaiting a client response */ get pendingCount(): number; /** * Send a server→client request and resolve its result. * Rejects on timeout, client error response, or malformed result. */ request(method: string, params: ElicitationCreateParams, timeoutMs?: number): Promise; /** * Route an inbound message. Returns `true` when the message was a response * to a pending server-initiated request (and was consumed); `false` when it * is a client request the caller should dispatch normally. */ handleMessage(message: unknown): boolean; /** Reject every pending request (e.g. on shutdown or client disconnect). */ rejectAll(reason?: string): void; } //# sourceMappingURL=mcp-elicitation.d.ts.map