import type { MCPClientCapabilities, MCPInputRequest, McpEra } from '../../types/connector/index.js'; import { type McpParamHeaderBinding } from './x-mcp-header.js'; /** * Write one value into a header field, wrapping it in the base64 sentinel * when it cannot go verbatim. * * Two cases need the wrapper, and the second is the one that is easy to * miss: a value whose bytes are not header-safe (anything non-ASCII, a * newline, a control character), and a value that IS header-safe but * already reads as a sentinel. Sending `=?base64?x?=` unwrapped would have * the server decode a string the caller meant literally, so a plain value * that collides with the marker is wrapped precisely so it survives as * itself. */ export declare function encodeMcpHeaderValue(value: string): string; /** What a request needs in order to be written for a given era. */ export interface McpEnvelopeInput { /** `undefined` before an era has been resolved — `connect()`'s own probe. */ readonly era: McpEra | undefined; readonly method: string; readonly params?: Record; /** Announced in `_meta` on a modern request. Omitted when absent. */ readonly clientInfo?: { readonly name: string; readonly version: string; }; /** Announced in `_meta` on a modern request. `{}` is the honest default. */ readonly capabilities?: MCPClientCapabilities; /** * The `x-mcp-header` bindings of the tool this request calls, validated * out of its `inputSchema`. * * Only `tools/call` has any, and only on a transport that mirrors them: * the values are read from `params.arguments`, and the spec conditions * the whole feature on Streamable HTTP. Empty or absent everywhere else. */ readonly paramHeaders?: readonly McpParamHeaderBinding[]; } /** One request's body and the headers that mirror it. */ export interface McpEnvelope { readonly params: Record | undefined; readonly headers: Record; } /** * Produce a request's `params` and its headers together, for one era. * * This function exists so that the `MCP-Protocol-Version` header and * `_meta['io.modelcontextprotocol/protocolVersion']` are written from ONE * local variable, one line apart. The alternative — building them in the * client and the transport respectively and then asserting somewhere that * they agree — makes a mismatched pair constructible and then tries to * catch it; here there is no expression that can produce one. * * Pure, and the highest-value unit-test target in the modern era: every * wire-format decision a modern request makes is visible in its return * value without a socket, a transport or a server. */ export declare function buildEnvelope(input: McpEnvelopeInput): McpEnvelope; /** A JSON-RPC result read past the MRTR `resultType` envelope. */ export type MCPDecodedResult = { readonly kind: 'complete'; readonly result: unknown; } | { readonly kind: 'input_required'; readonly inputRequests?: readonly MCPInputRequest[]; readonly requestState?: string; }; /** * Read a JSON-RPC result past its `resultType` envelope. * * Absent `resultType` is `complete` — every legacy result, and every modern * result before MRTR, carries none, and the spec's own words are that * clients "MUST treat an absent resultType as complete". An explicit * `"complete"` reads the same way. Anything else recognized becomes the * `input_required` shape; anything unrecognized is refused, per the spec's * other MUST: "A resultType of any value unrecognized by the client MUST be * considered invalid." There is deliberately no third, permissive outcome — * an invalid `resultType` is not a value a caller should be able to read * past by accident, so this throws rather than returning an error variant. * * Pure: given the same `raw`, always the same outcome, no I/O. * * `inputRequests` entries are kept only when they at least name a `method` * — the one field this client reads — so a malformed entry from a * non-conforming server cannot be mistaken for the shape it should have * had. `requestState` is read only as a `string` and is otherwise carried * completely opaquely: this function does not parse it, and neither does * anything that calls it. */ export declare function decodeResult(raw: unknown): MCPDecodedResult; //# sourceMappingURL=envelope.d.ts.map