import { c as McpHttpSecurityOptions, l as McpHttpSecurityPolicy } from "./mcp-http-security-BXpPP1E-.mjs"; import { NodeMcpRequestHandler, ToNodeHandlerOptions } from "@modelcontextprotocol/node"; import { McpLifecycleObserver, McpOperationContext, McpOperationMiddleware } from "@nestm/mcp-core"; import { AuthInfo, CreateMcpHandlerOptions, Implementation, McpHandlerRequestOptions, McpRequestContext, McpServer, ServerEventBus, ServerNotifier, ServerOptions } from "@modelcontextprotocol/server"; import { ServeStdioOptions, StdioServerHandle } from "@modelcontextprotocol/server/stdio"; //#region src/mcp-server.types.d.ts type MaybePromise = T | PromiseLike; /** Context passed to each feature whenever the official SDK creates a server instance. */ interface McpServerBuildContext extends McpRequestContext { readonly runtimeName: string; /** Token-free verified principal resolved once for this serving unit. */ readonly principal?: McpServerPrincipal; } /** * A reusable contribution to an MCP server. * * Features should only register tools, resources, prompts, and low-level handlers. The official * v2 HTTP factory creates a fresh `McpServer` per request, so long-lived pools and caches should be * captured outside this function. */ type McpServerFeature = (server: McpServer, context: McpServerBuildContext) => MaybePromise; type McpServerRuntimePhase = "build:start" | "build:success" | "build:error" | "handler:error" | "request:rejected" | "close:start" | "close:success" | "close:error"; /** Lifecycle signal suitable for logs, metrics, and OpenTelemetry adapters. */ interface McpServerRuntimeEvent { readonly phase: McpServerRuntimePhase; readonly runtimeName: string; readonly timestamp: number; readonly durationMs?: number; readonly era?: McpRequestContext["era"]; readonly error?: Error; /** HTTP status of a pre-dispatch security rejection (`request:rejected` only). */ readonly status?: number; } type McpServerRuntimeObserver = (event: McpServerRuntimeEvent) => void | PromiseLike; /** Authenticated identity safe to expose to lifecycle observers (token and provider extras omitted). */ interface McpServerPrincipal { readonly clientId: AuthInfo["clientId"]; readonly scopes: readonly string[]; readonly expiresAt?: AuthInfo["expiresAt"]; /** Canonical resource URL string; strings avoid the mutable internal slots of `URL`. */ readonly resource?: string; /** Explicitly projected verified subject; never inferred from clientId. */ readonly subject?: string; /** Explicitly projected verified tenant boundary. */ readonly tenantId?: string; } /** The only application claims accepted into the token-free runtime principal. */ interface McpServerPrincipalClaims { readonly subject?: string; readonly tenantId?: string; } /** Maps verified provider-specific token data onto the narrow safe claims surface. */ type McpServerPrincipalClaimsResolver = (authInfo: Readonly) => MaybePromise; type McpServerOperationContext = McpOperationContext; interface McpServerOperationInput { readonly request: Request; readonly options?: McpHandlerRequestOptions; } type McpServerMiddleware = McpOperationMiddleware; interface McpServerDefinition { /** Stable registry name. This may differ from the wire-level server identity. */ readonly name: string; readonly serverInfo: Implementation; readonly serverOptions?: ServerOptions; readonly features?: readonly McpServerFeature[]; readonly http?: Omit; /** * HTTP pre-dispatch security posture (Origin/Host validation, CORS, body * cap). Applies to `fetch()`, `toNodeHandler()`, and every host built on * them; omitting it keeps the safe defaults (routable browser origins * denied, CORS for localhost-class origins, 1 MiB body cap). */ readonly httpSecurity?: McpHttpSecurityOptions; /** Maximum time close waits for accepted wrapper middleware/build work. Defaults to 30 seconds. */ readonly shutdownTimeoutMs?: number; /** Projects verified subject/tenant claims; arbitrary AuthInfo.extra values are never copied. */ readonly principalClaims?: McpServerPrincipalClaimsResolver; /** Request middleware shared by modern and legacy HTTP traffic. */ readonly middleware?: readonly McpServerMiddleware[]; /** Payload-safe start/success/failure/cancellation signals for each HTTP exchange. */ readonly lifecycleObserver?: McpLifecycleObserver; /** Server-instance construction lifecycle; use `lifecycleObserver` for request telemetry. */ readonly observer?: McpServerRuntimeObserver; /** Isolated error reporter; synchronous throws and asynchronous rejections are contained. */ readonly onError?: (error: Error) => MaybePromise; } //#endregion //#region src/mcp-server.runtime.d.ts /** Owns one named MCP server definition and every HTTP/stdio serving lifecycle. */ declare class McpServerRuntime implements AsyncDisposable { #private; readonly name: string; readonly notify: ServerNotifier; readonly bus: ServerEventBus; /** Resolved HTTP security posture applied ahead of every HTTP dispatch. */ readonly httpSecurity: McpHttpSecurityPolicy; constructor(definition: McpServerDefinition); /** Build the same server factory used by HTTP and stdio serving. */ createServer(context: McpRequestContext): Promise; fetch(request: Request, options?: McpHandlerRequestOptions): Promise; toNodeHandler(options?: ToNodeHandlerOptions): NodeMcpRequestHandler; /** * Reports a pre-dispatch security rejection detected by an outer hardened * layer (a Nest controller seam, a hand-composed facade) so it still surfaces * as a `request:rejected` runtime observer event. */ reportRequestRejected(status: number): void; /** Start a stdio connection backed by this runtime's feature factory. */ serveStdio(options?: Omit): StdioServerHandle; close(): Promise; [Symbol.asyncDispose](): Promise; } /** Projects verified auth data onto the deliberately narrow token-free principal contract. */ declare function resolveMcpServerPrincipal(authInfo: AuthInfo, resolveClaims?: McpServerPrincipalClaimsResolver): Promise; //#endregion export { McpServerDefinition as a, McpServerOperationContext as c, McpServerPrincipalClaims as d, McpServerPrincipalClaimsResolver as f, McpServerRuntimePhase as h, McpServerBuildContext as i, McpServerOperationInput as l, McpServerRuntimeObserver as m, resolveMcpServerPrincipal as n, McpServerFeature as o, McpServerRuntimeEvent as p, MaybePromise as r, McpServerMiddleware as s, McpServerRuntime as t, McpServerPrincipal as u }; //# sourceMappingURL=mcp-server.runtime-Cflw4Og5.d.mts.map