/** * MCP Context - Tool execution environment with MCP protocol support * * This module re-exports the core ToolContext interface and adds * MCP-specific functionality for progress notifications via the * MCP protocol. * * Design: MCP layer builds ON TOP of core layer, not the other way around. * * Invariant: All tools receive consistent context interface * Trade-off: Abstraction overhead for tool isolation and testability */ import type { Logger } from 'pino'; import type { RegoEvaluator } from '../config/policy-rego.js'; import { createToolContext as createCoreContext, type ToolContext, type ProgressReporter, type ContextOptions as CoreContextOptions } from '../core/context.js'; export type { ToolContext, ProgressReporter }; /** * Re-exported as CoreContextOptions to distinguish from MCP-specific ContextOptions. * The core version only accepts ProgressReporter functions, while the MCP version * also accepts simple progress tokens (string or number). */ export type { CoreContextOptions }; export { createCoreContext as createCoreToolContext }; /** * Progress input can be: * - A simple progress token (string or number) from MCP protocol * - null or undefined for no progress reporting */ export type ProgressInput = string | number | null | undefined; /** * MCP context options with notification support. * * This interface supports MCP-specific functionality for * progress notifications via the MCP protocol. * * Note: This does not extend CoreContextOptions because the progress * property has a different type (accepts simple tokens: string or number). */ export interface ContextOptions { /** Optional abort signal for cancellation */ signal?: AbortSignal; /** * Progress token from MCP protocol. * When provided along with sendNotification, enables progress notifications. */ progress?: ProgressInput; /** * MCP notification callback for progress updates. * When provided, progress updates are sent via MCP protocol. */ sendNotification?: (notification: unknown) => Promise; /** Optional Rego policy evaluator to pass to tools */ policy?: RegoEvaluator; } /** * Create a ToolContext with optional MCP progress notification support. * * This factory extends the core createToolContext with MCP-specific * functionality. If sendNotification is provided, progress updates * are forwarded through the MCP protocol. * * @param logger - Pino logger instance * @param options - Context options including MCP-specific sendNotification * @returns ToolContext configured for MCP or core usage * * @example * ```typescript * // MCP usage with notifications * const ctx = createToolContext(logger, { * signal: request.signal, * progress: request.params, * sendNotification: server.sendNotification, * }); * * // Simple usage (no MCP) * const ctx = createToolContext(logger); * ``` */ export declare function createToolContext(logger: Logger, options?: ContextOptions): ToolContext; export type { EnhancedProgressReporter } from './context-helpers.js'; export { extractProgressToken, createProgressReporter } from './context-helpers.js'; //# sourceMappingURL=context.d.ts.map