/** * FrontMcpContextStorage - AsyncLocalStorage wrapper for unified context * * Provides concurrent-safe context propagation using Node.js AsyncLocalStorage. * Access through DI only - never use static imports to access the storage directly. * * @example * ```typescript * // In a flow or middleware * const storage = this.get(FrontMcpContextStorage); * await storage.runFromHeaders(request.headers, { * sessionId: sessionId, * scopeId: scope.id, * }, async () => { * // All code here can access the context via DI * const ctx = this.get(FRONTMCP_CONTEXT); * }); * ``` */ import { type AuthInfo } from '@frontmcp/protocol'; import { FrontMcpContext, type FrontMcpContextArgs } from './frontmcp-context'; /** * FrontMcpContextStorage provides unified context via AsyncLocalStorage. * * This is a GLOBAL-scoped provider because it manages the storage itself, * not the per-context data. The actual FrontMcpContext is accessed via * the FRONTMCP_CONTEXT token which is CONTEXT-scoped. */ export declare class FrontMcpContextStorage { /** * Run a callback with a new FrontMcpContext. * * @param args - Arguments to create the context * @param fn - Async function to run with the context * @returns Result of the callback */ run(args: FrontMcpContextArgs, fn: () => T | Promise): T | Promise; /** * Run with context extracted from HTTP headers. * * Automatically parses trace context from headers using W3C Trace Context * specification with fallback to x-frontmcp-trace-id. * * @param headers - HTTP headers * @param args - Additional context args (sessionId, scopeId) * @param fn - Async function to run * @returns Result of the callback */ runFromHeaders(headers: Record, args: Omit, fn: () => T | Promise): T | Promise; /** * Run with an existing FrontMcpContext. * * Useful when you need to propagate an existing context to a new async scope. * * @param context - Existing FrontMcpContext * @param fn - Async function to run * @returns Result of the callback */ runWithContext(context: FrontMcpContext, fn: () => T | Promise): T | Promise; /** * Get the current FrontMcpContext. * * @returns Current context or undefined if not in a context scope */ getStore(): FrontMcpContext | undefined; /** * Get the current FrontMcpContext, throwing if not available. * * @throws Error if not in a context scope */ getStoreOrThrow(): FrontMcpContext; /** * Check if currently running within a context. * * @returns True if a FrontMcpContext is available */ hasContext(): boolean; /** * Update the authInfo in the current context. * * This mutates the existing context in place to preserve internal state * (marks, store, sessionMetadata) while updating auth info. * * @param authInfo - Auth info fields to set/update (merged with existing) * @param fn - Function to run after update * @returns Result of the callback */ updateAuthInfo(authInfo: Partial, fn: () => T | Promise): T | Promise; } //# sourceMappingURL=frontmcp-context-storage.d.ts.map