/** * MCP protocol-version handling for the stdio servers (ADR-524). * * Ruflo ships three stdio entry points (`bin/cli.js` auto-detect, `bin/mcp-server.js`, * and `MCPServerManager` in mcp-server.ts). All three answered `initialize` with a * hardcoded `2024-11-05` and knew nothing of the 2026-07-28 revision, which drops the * handshake and carries the version on every request. This module is the one place * that decides which revision a message speaks, so the three handlers cannot drift. * * Dual-era behaviour (spec: basic/versioning): * - `initialize` selects legacy semantics; the requested legacy version is echoed. * - a request carrying `_meta["io.modelcontextprotocol/protocolVersion"]` is served * statelessly: `resultType` and `serverInfo` on every result, cache hints on lists, * `-32602` for an unknown resource, `-32022` for an unsupported version. * - `server/discover` is always answered, so a dual-era client's stdio probe succeeds. */ export declare const MODERN_PROTOCOL_VERSIONS: readonly ["2026-07-28"]; export declare const LEGACY_PROTOCOL_VERSIONS: readonly ["2025-11-25", "2025-06-18", "2024-11-05"]; export declare const SUPPORTED_PROTOCOL_VERSIONS: readonly string[]; /** Offered to a legacy client whose requested version we do not know. */ export declare const LATEST_LEGACY_PROTOCOL_VERSION: "2025-11-25"; export declare const META_PROTOCOL_VERSION = "io.modelcontextprotocol/protocolVersion"; export declare const META_CLIENT_CAPABILITIES = "io.modelcontextprotocol/clientCapabilities"; export declare const META_SERVER_INFO = "io.modelcontextprotocol/serverInfo"; export declare const ERROR_INVALID_PARAMS = -32602; export declare const ERROR_UNSUPPORTED_PROTOCOL_VERSION = -32022; /** 2025-11-25 and earlier; replaced by -32602 in 2026-07-28. */ export declare const ERROR_LEGACY_RESOURCE_NOT_FOUND = -32002; /** Tool catalogue is fixed for the life of a stdio process; five minutes is a conservative hint. */ export declare const TOOLS_LIST_TTL_MS = 300000; export declare const DISCOVER_TTL_MS = 3600000; export interface ServerIdentity { name: string; version: string; } export interface ProtocolContext { /** True when the request used 2026-07-28 per-request metadata. */ modern: boolean; /** Version the request declared, or undefined for legacy requests. */ version?: string; /** Validated W3C traceparent, if the client propagated one. */ traceparent?: string; tracestate?: string; } export interface JsonRpcMessage { jsonrpc?: string; id?: string | number | null; method?: string; params?: unknown; } export interface JsonRpcResponse { jsonrpc: '2.0'; id?: string | number | null; result?: Record; error?: { code: number; message: string; data?: unknown; }; } export type Preflight = { response: JsonRpcResponse; context?: undefined; } | { response?: undefined; context: ProtocolContext; }; /** The CLI package version, read once from package.json (dist/src/ → ../../). */ export declare function rufloPackageVersion(): string; export declare function defaultServerIdentity(): ServerIdentity; /** Pick the legacy version to answer `initialize` with (spec: echo if supported, else our latest). */ export declare function negotiateLegacyVersion(requested: unknown): string; export declare function isValidTraceparent(value: unknown): value is string; /** * Decide how to serve one inbound message before the handler's own switch runs. * Returns a complete response for `initialize`, `server/discover` and protocol * errors; otherwise returns the context the handler passes to `finalizeResponse`. */ export declare function protocolPreflight(message: JsonRpcMessage, capabilities: Record, identity?: ServerIdentity): Preflight; /** The resource-not-found code the request's revision expects. */ export declare function resourceNotFoundCode(context: ProtocolContext): number; /** Stable, name-ordered copy so `tools/list` is byte-identical across calls (prompt-cache friendly). */ export declare function sortToolsDeterministically(tools: readonly T[]): T[]; /** Tool-call context fields to forward, so handlers and logs can join the caller's trace. */ export declare function traceContextFields(context: ProtocolContext): Record; /** Add the 2026-07-28 result fields to a handler's response. Legacy responses pass through untouched. */ export declare function finalizeResponse(response: JsonRpcResponse | null, method: string | undefined, context: ProtocolContext, identity?: ServerIdentity): JsonRpcResponse | null; //# sourceMappingURL=mcp-protocol.d.ts.map