import { type FrontMcpAuthContext, type FrontMcpFetchInit } from '@frontmcp/auth'; import { type Token } from '@frontmcp/di'; import { type AuthInfo, type CallToolResult } from '@frontmcp/protocol'; import { type RuntimeContext } from '@frontmcp/utils'; import { ConfigService } from '../../builtin/config/providers/config.service'; import { type FrontMcpContext } from '../../context'; import { type ScopeEntry } from '../entries'; import { type ProviderRegistryInterface } from './internal'; import { type FrontMcpLogger } from './logger.interface'; /** * Base constructor arguments for all execution contexts. */ export type ExecutionContextBaseArgs = { providers: ProviderRegistryInterface; logger: FrontMcpLogger; authInfo: Partial; }; /** * Abstract base class for execution contexts (tools, resources, prompts, etc.). * Provides common functionality for dependency injection, logging, and flow control. */ export declare abstract class ExecutionContextBase { private providers; /** * @deprecated Use `context.authInfo` instead. Will be removed in v2.0. */ private readonly _authInfo; /** Unique identifier for this execution run */ protected readonly runId: string; protected readonly logger: FrontMcpLogger; /** Current stage name for tracking/debugging */ protected activeStage: string; /** Error if execution failed */ private _error?; /** Cached auth context (built lazily on first access) */ private _authContext?; constructor(args: ExecutionContextBaseArgs); /** * Get the current FrontMcpContext. * * Provides access to requestId, traceId, sessionId, authInfo, * timing marks, request metadata, transport, and context-aware fetch. * * @throws RequestContextNotAvailableError if called outside of a context scope */ get context(): FrontMcpContext; /** * Get the FrontMcpAuthContext for the current request. * * Provides typed access to user identity, roles, permissions, scopes, * and convenience methods like `hasRole()`, `hasPermission()`, `hasScope()`. * * Custom fields from `ExtendFrontMcpAuthContext` are available if pipes * are configured in `@FrontMcp({ authorities: { pipes } })`. * * @example * ```typescript * if (!this.auth.hasRole('admin')) throw new Error('Admin required'); * const tenantId = this.auth.claims['tenantId']; * ``` */ get auth(): FrontMcpAuthContext; /** * Try to get the context, returning undefined if not available. * * Use this when context may not be available (e.g., during initialization). */ tryGetContext(): FrontMcpContext | undefined; /** * @deprecated Use `context.authInfo` instead. Will be removed in v2.0. * * Get authentication information for the current request. */ get authInfo(): Partial; /** * Get authentication information for the current request. * * Prefers context.authInfo when available (the recommended source), * falls back to the legacy authInfo property for backward compatibility. * * Returns Partial because auth info is progressively populated * during the request lifecycle. Callers should check for required fields. */ getAuthInfo(): Partial; /** * Get a child logger with request context attached. * * The logger includes requestId, traceId, and sessionId in its context. */ protected get contextLogger(): FrontMcpLogger; /** * Get a dependency from the provider registry. * @throws Error if the dependency is not found */ get(token: Token): T; /** * Get the current scope. */ get scope(): ScopeEntry; /** * Try to get a dependency, returning undefined if not found. */ tryGet(token: Token): T | undefined; /** * Invoke another registered tool from inside the current execution context. * * Used by tools, skill actions, agents, CodeCall scripts, and jobs to * compose with internal helper tools (e.g. operations registered by * `@frontmcp/plugin-skilled-openapi`'s OpenAPI internal-tool adapter). * * Trust model: the call runs the standard `tools:call-tool` flow but tags * the request ctx with `internalCall: true`, which the flow honors as a * trusted in-process invocation. This bypasses the external-call gate that * blocks `tools/call` for tools with `metadata.visibility === 'internal'`. * Public and hidden tools are reachable through this helper too. * * Authority/authorization checks still run — an internal call carries the * same `authInfo` as the surrounding request, so ABAC/RBAC guards apply. * * @param name Tool name (or fully-qualified `owner.name`). * @param args Tool arguments — validated by the tool's input schema. * @param opts Optional progress token / abort signal forwarded into `_meta`. * @returns The tool's `CallToolResult`. */ callTool(name: string, args?: Record, opts?: { progressToken?: string | number; signal?: AbortSignal; }): Promise; /** * Fail the execution and trigger error handling. */ protected fail(err: Error): never; /** * Mark the current execution stage (for debugging/tracking). */ mark(stage: string): void; /** * Fetch a URL with context-aware header injection. * * When FrontMcpContext is available, delegates to ctx.fetch() which: * - Auto-injects Authorization header (if authInfo.token is available) * - Auto-injects W3C traceparent header for distributed tracing * - Auto-injects x-request-id header * - Auto-injects custom headers from request metadata * * Falls back to standard fetch if context is not available. */ fetch(input: RequestInfo | URL, init?: FrontMcpFetchInit | RequestInit): Promise; /** * Get the current error, if any. */ protected get error(): Error | undefined; /** * Get the ConfigService for typed environment variable access. * * Available when ConfigPlugin is installed. Provides methods like: * - get(key, defaultValue?) - Get env var with optional default * - getRequired(key) - Get required env var (throws if missing) * - getNumber(key, defaultValue?) - Get as number * - getBoolean(key, defaultValue?) - Get as boolean * - has(key) - Check if env var exists * * @throws Error if ConfigPlugin is not installed */ get config(): ConfigService; /** * Get the current runtime context (platform, runtime, deployment, env). */ get runtimeContext(): RuntimeContext; /** * Check if running on a specific OS platform. * @param platform - 'darwin' (macOS), 'linux', 'win32' (Windows), etc. */ isPlatform(platform: RuntimeContext['platform']): boolean; /** * Check if running in a specific JavaScript runtime. * @param runtime - 'node', 'browser', 'edge', 'bun', 'deno' */ isRuntime(runtime: RuntimeContext['runtime']): boolean; /** * Check if running in a specific deployment mode. * @param deployment - 'serverless' or 'standalone' */ isDeployment(deployment: RuntimeContext['deployment']): boolean; /** * Check if running in a specific environment. * @param env - 'production', 'development', 'test', etc. */ isEnv(env: RuntimeContext['env']): boolean; } //# sourceMappingURL=execution-context.interface.d.ts.map