xmcp
Version:
The TypeScript MCP framework
27 lines (26 loc) • 1.59 kB
TypeScript
import type { AuthInfo, LoggingLevel, ServerContext } from "@modelcontextprotocol/server";
import type { McpClientInfo } from "../../types/client-info";
export interface RequestContext {
/** Verified authentication supplied by the SDK for this request, if any. */
readonly authInfo?: AuthInfo;
readonly clientInfo?: Readonly<McpClientInfo>;
readonly http?: {
/** The HTTP request ID generated by xmcp, not the JSON-RPC message ID. */
readonly id: string;
readonly headers: Readonly<Record<string, string | readonly string[] | undefined>>;
};
/** The live cancellation signal supplied by the MCP SDK. */
readonly signal: AbortSignal;
/** Store a value for this MCP operation, shared with its async helpers. */
set(key: string | symbol, value: unknown): void;
/** Read a request-local value. The type parameter is a compile-time cast. */
get<T = unknown>(key: string | symbol): T | undefined;
/** Send progress when the current request supplies a progress token. */
progress(value: number, total?: number): Promise<void>;
/** Send an MCP log message using the SDK's capability and level checks. */
log(level: LoggingLevel, data: unknown): Promise<void>;
}
/** Read the current MCP request from a handler or one of its async helpers. */
export declare function getRequestContext(): RequestContext;
/** Internal boundary around MCP operation execution; handler arguments stay intact. */
export declare function withRequestContext<T>(ctx: ServerContext, clientInfo: McpClientInfo | undefined, callback: () => T): T;