@kya-os/mcp-i
Version:
The TypeScript MCP framework with identity features built-in
38 lines (37 loc) • 1.18 kB
TypeScript
/**
* Request Context Management
*
* Uses AsyncLocalStorage to track request-scoped data like session information
* across async operations without needing to pass it through every function.
*
* This enables the compiler path to access session data (like agentDid) that
* was set during handshake processing.
*/
import type { SessionContext } from '@kya-os/contracts/handshake';
export interface RequestContext {
session?: SessionContext;
requestId?: string;
startTime?: number;
}
/**
* Run a function with request context
*/
export declare function runWithContext<T>(context: RequestContext, fn: () => T | Promise<T>): T | Promise<T>;
/**
* Get the current request context
*/
export declare function getContext(): RequestContext | undefined;
/**
* Get the current session from context
*/
export declare function getCurrentSession(): SessionContext | undefined;
/**
* Get the current agent DID from session
*/
export declare function getCurrentAgentDid(): string | undefined;
/**
* Set session in current context
*
* NOTE: This only works if called within a runWithContext block
*/
export declare function setSession(session: SessionContext): void;