{"version":3,"file":"index.mjs","names":["COMPLETABLE_SYMBOL: unique symbol","_serverInfo: Implementation","transportSessionId: string | undefined","formParams: ElicitRequestFormParams","toolDefinition: Tool","templateResources: Resource[]","registeredResource: RegisteredResource","registeredResourceTemplate: RegisteredResourceTemplate","registeredPrompt: RegisteredPrompt","registeredTool: RegisteredTool","_callbacks: {\n            /**\n             * A callback to list all resources matching this template. This is required to be specified, even if `undefined`, to avoid accidentally forgetting resource listing.\n             */\n            list: ListResourcesCallback | undefined;\n\n            /**\n             * An optional callback to autocomplete variables within the URI template. Useful for clients and users to discover possible values.\n             */\n            complete?: {\n                [variable: string]: CompleteResourceTemplateCallback;\n            };\n        }","callback","EMPTY_COMPLETION_RESULT: CompleteResult","hostname: string","error: { code: number; message: string; data?: string }","streamController: ReadableStreamDefaultController<Uint8Array>","headers: Record<string, string>","streamId: string | undefined","messages: JSONRPCMessage[]","closeSSEStream: (() => void) | undefined","closeStandaloneSSEStream: (() => void) | undefined","eventId: string | undefined","_defaultValidator: jsonSchemaValidator | undefined","coreFromJsonSchema"],"sources":["../src/server/completable.ts","../src/server/server.ts","../src/server/mcp.ts","../src/server/middleware/hostHeaderValidation.ts","../src/server/streamableHttp.ts","../src/fromJsonSchema.ts"],"sourcesContent":["import type { StandardSchemaV1 } from '@modelcontextprotocol/core-internal';\n\nexport const COMPLETABLE_SYMBOL: unique symbol = Symbol.for('mcp.completable');\n\nexport type CompleteCallback<T extends StandardSchemaV1 = StandardSchemaV1> = (\n    value: StandardSchemaV1.InferInput<T>,\n    context?: {\n        arguments?: Record<string, string>;\n    }\n) => StandardSchemaV1.InferInput<T>[] | Promise<StandardSchemaV1.InferInput<T>[]>;\n\nexport type CompletableMeta<T extends StandardSchemaV1 = StandardSchemaV1> = {\n    complete: CompleteCallback<T>;\n};\n\nexport type CompletableSchema<T extends StandardSchemaV1> = T & {\n    [COMPLETABLE_SYMBOL]: CompletableMeta<T>;\n};\n\n/**\n * Wraps a schema to provide autocompletion capabilities. Useful for, e.g., prompt arguments in MCP.\n *\n * @example\n * ```ts source=\"./completable.examples.ts#completable_basicUsage\"\n * server.registerPrompt(\n *     'review-code',\n *     {\n *         title: 'Code Review',\n *         argsSchema: z.object({\n *             language: completable(z.string().describe('Programming language'), value =>\n *                 ['typescript', 'javascript', 'python', 'rust', 'go'].filter(lang => lang.startsWith(value))\n *             )\n *         })\n *     },\n *     ({ language }) => ({\n *         messages: [\n *             {\n *                 role: 'user' as const,\n *                 content: {\n *                     type: 'text' as const,\n *                     text: `Review this ${language} code.`\n *                 }\n *             }\n *         ]\n *     })\n * );\n * ```\n *\n * @see {@linkcode server/mcp.McpServer.registerPrompt | McpServer.registerPrompt} for using completable schemas in prompt argument definitions\n */\nexport function completable<T extends StandardSchemaV1>(schema: T, complete: CompleteCallback<T>): CompletableSchema<T> {\n    Object.defineProperty(schema as object, COMPLETABLE_SYMBOL, {\n        value: { complete } as CompletableMeta<T>,\n        enumerable: false,\n        writable: false,\n        configurable: false\n    });\n    return schema as CompletableSchema<T>;\n}\n\n/**\n * Checks if a schema is completable (has completion metadata).\n */\nexport function isCompletable(schema: unknown): schema is CompletableSchema<StandardSchemaV1> {\n    return !!schema && typeof schema === 'object' && COMPLETABLE_SYMBOL in (schema as object);\n}\n\n/**\n * Gets the completer callback from a completable schema, if it exists.\n */\nexport function getCompleter<T extends StandardSchemaV1>(schema: T): CompleteCallback<T> | undefined {\n    const meta = (schema as unknown as { [COMPLETABLE_SYMBOL]?: CompletableMeta<T> })[COMPLETABLE_SYMBOL];\n    return meta?.complete as CompleteCallback<T> | undefined;\n}\n","import type {\n    BaseContext,\n    ClientCapabilities,\n    CreateMessageRequest,\n    CreateMessageRequestParamsBase,\n    CreateMessageRequestParamsWithTools,\n    CreateMessageResult,\n    CreateMessageResultWithTools,\n    ElicitRequestFormParams,\n    ElicitRequestURLParams,\n    ElicitResult,\n    Implementation,\n    InitializeRequest,\n    InitializeResult,\n    JSONRPCRequest,\n    JsonSchemaType,\n    jsonSchemaValidator,\n    ListRootsRequest,\n    LoggingLevel,\n    LoggingMessageNotification,\n    MessageExtraInfo,\n    NotificationMethod,\n    NotificationOptions,\n    ProtocolOptions,\n    RequestMethod,\n    RequestOptions,\n    ResourceUpdatedNotification,\n    Result,\n    ServerCapabilities,\n    ServerContext,\n    ToolResultContent,\n    ToolUseContent\n} from '@modelcontextprotocol/core-internal';\nimport {\n    CallToolRequestSchema,\n    CallToolResultSchema,\n    CreateMessageResultSchema,\n    CreateMessageResultWithToolsSchema,\n    ElicitResultSchema,\n    EmptyResultSchema,\n    LATEST_PROTOCOL_VERSION,\n    ListRootsResultSchema,\n    LoggingLevelSchema,\n    mergeCapabilities,\n    parseSchema,\n    Protocol,\n    ProtocolError,\n    ProtocolErrorCode,\n    SdkError,\n    SdkErrorCode\n} from '@modelcontextprotocol/core-internal';\nimport { DefaultJsonSchemaValidator } from '@modelcontextprotocol/server/_shims';\n\nexport type ServerOptions = ProtocolOptions & {\n    /**\n     * Capabilities to advertise as being supported by this server.\n     *\n     * Note: per the MCP spec, a server that declares a capability MUST respond to that\n     * capability's requests (e.g. `tools/list` for `tools`) — potentially with an empty\n     * result — rather than with a \"Method not found\" error. {@linkcode server/mcp.McpServer | McpServer}\n     * handles this automatically for capabilities declared here; when using the low-level\n     * {@linkcode Server} directly, you are responsible for registering a request handler for\n     * every capability you declare.\n     */\n    capabilities?: ServerCapabilities;\n\n    /**\n     * Optional instructions describing how to use the server and its features.\n     */\n    instructions?: string;\n\n    /**\n     * JSON Schema validator for elicitation response validation.\n     *\n     * The validator is used to validate user input returned from elicitation\n     * requests against the requested schema.\n     *\n     * @default Runtime-selected validator (AJV-backed on Node.js, `@cfworker/json-schema`-backed on browser/workerd runtimes)\n     */\n    jsonSchemaValidator?: jsonSchemaValidator;\n};\n\n/**\n * An MCP server on top of a pluggable transport.\n *\n * This server will automatically respond to the initialization flow as initiated from the client.\n *\n * @deprecated Use {@linkcode server/mcp.McpServer | McpServer} instead for the high-level API. Only use `Server` for advanced use cases.\n */\nexport class Server extends Protocol<ServerContext> {\n    private _clientCapabilities?: ClientCapabilities;\n    private _clientVersion?: Implementation;\n    private _negotiatedProtocolVersion?: string;\n    private _capabilities: ServerCapabilities;\n    private _instructions?: string;\n    private _jsonSchemaValidator: jsonSchemaValidator;\n\n    /**\n     * Callback for when initialization has fully completed (i.e., the client has sent an `notifications/initialized` notification).\n     */\n    oninitialized?: () => void;\n\n    /**\n     * Initializes this server with the given name and version information.\n     */\n    constructor(\n        private _serverInfo: Implementation,\n        options?: ServerOptions\n    ) {\n        super(options);\n        this._capabilities = options?.capabilities ? { ...options.capabilities } : {};\n        this._instructions = options?.instructions;\n        this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new DefaultJsonSchemaValidator();\n\n        this.setRequestHandler('initialize', request => this._oninitialize(request));\n        this.setNotificationHandler('notifications/initialized', () => this.oninitialized?.());\n\n        if (this._capabilities.logging) {\n            this._registerLoggingHandler();\n        }\n    }\n\n    /**\n     * Registers the built-in `logging/setLevel` request handler.\n     *\n     * @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577).\n     * Remains functional during the deprecation window (at least twelve months).\n     * Migrate to stderr logging (STDIO servers) or OpenTelemetry.\n     */\n    private _registerLoggingHandler(): void {\n        this.setRequestHandler('logging/setLevel', async (request, ctx) => {\n            const transportSessionId: string | undefined =\n                ctx.sessionId || (ctx.http?.req?.headers.get('mcp-session-id') as string) || undefined;\n            const { level } = request.params;\n            const parseResult = parseSchema(LoggingLevelSchema, level);\n            if (parseResult.success) {\n                this._loggingLevels.set(transportSessionId, parseResult.data);\n            }\n            return {};\n        });\n    }\n\n    protected override buildContext(ctx: BaseContext, transportInfo?: MessageExtraInfo): ServerContext {\n        // Only create http when there's actual HTTP transport info or auth info\n        const hasHttpInfo = ctx.http || transportInfo?.request || transportInfo?.closeSSEStream || transportInfo?.closeStandaloneSSEStream;\n        return {\n            ...ctx,\n            mcpReq: {\n                ...ctx.mcpReq,\n                // Deprecated as of protocol version 2026-07-28 (SEP-2577): `log` and\n                // `requestSampling` remain functional during the deprecation window\n                // (at least twelve months). See ServerContext for migration guidance.\n                log: (level, data, logger) => this.sendLoggingMessage({ level, data, logger }),\n                elicitInput: (params, options) => this.elicitInput(params, options),\n                requestSampling: (params, options) => this.createMessage(params, options)\n            },\n            http: hasHttpInfo\n                ? {\n                      ...ctx.http,\n                      req: transportInfo?.request,\n                      closeSSE: transportInfo?.closeSSEStream,\n                      closeStandaloneSSE: transportInfo?.closeStandaloneSSEStream\n                  }\n                : undefined\n        };\n    }\n\n    // Map log levels by session id\n    private _loggingLevels = new Map<string | undefined, LoggingLevel>();\n\n    // Map LogLevelSchema to severity index\n    private readonly LOG_LEVEL_SEVERITY = new Map(LoggingLevelSchema.options.map((level, index) => [level, index]));\n\n    // Is a message with the given level ignored in the log level set for the given session id?\n    private isMessageIgnored = (level: LoggingLevel, sessionId?: string): boolean => {\n        const currentLevel = this._loggingLevels.get(sessionId);\n        return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level)! < this.LOG_LEVEL_SEVERITY.get(currentLevel)! : false;\n    };\n\n    /**\n     * Registers new capabilities. This can only be called before connecting to a transport.\n     *\n     * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).\n     */\n    public registerCapabilities(capabilities: ServerCapabilities): void {\n        if (this.transport) {\n            throw new SdkError(SdkErrorCode.AlreadyConnected, 'Cannot register capabilities after connecting to transport');\n        }\n        const hadLogging = !!this._capabilities.logging;\n        this._capabilities = mergeCapabilities(this._capabilities, capabilities);\n        if (!hadLogging && this._capabilities.logging) {\n            this._registerLoggingHandler();\n        }\n    }\n\n    /**\n     * Enforces server-side validation for `tools/call` results regardless of how the\n     * handler was registered.\n     */\n    protected override _wrapHandler(\n        method: string,\n        handler: (request: JSONRPCRequest, ctx: ServerContext) => Promise<Result>\n    ): (request: JSONRPCRequest, ctx: ServerContext) => Promise<Result> {\n        if (method !== 'tools/call') {\n            return handler;\n        }\n        return async (request, ctx) => {\n            const validatedRequest = parseSchema(CallToolRequestSchema, request);\n            if (!validatedRequest.success) {\n                const errorMessage =\n                    validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);\n                throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid tools/call request: ${errorMessage}`);\n            }\n\n            const result = await handler(request, ctx);\n\n            const validationResult = parseSchema(CallToolResultSchema, result);\n            if (!validationResult.success) {\n                const errorMessage =\n                    validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);\n                throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid tools/call result: ${errorMessage}`);\n            }\n\n            return validationResult.data;\n        };\n    }\n\n    protected assertCapabilityForMethod(method: RequestMethod | string): void {\n        switch (method) {\n            case 'sampling/createMessage': {\n                if (!this._clientCapabilities?.sampling) {\n                    throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Client does not support sampling (required for ${method})`);\n                }\n                break;\n            }\n\n            case 'elicitation/create': {\n                if (!this._clientCapabilities?.elicitation) {\n                    throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Client does not support elicitation (required for ${method})`);\n                }\n                break;\n            }\n\n            case 'roots/list': {\n                if (!this._clientCapabilities?.roots) {\n                    throw new SdkError(\n                        SdkErrorCode.CapabilityNotSupported,\n                        `Client does not support listing roots (required for ${method})`\n                    );\n                }\n                break;\n            }\n\n            case 'ping': {\n                // No specific capability required for ping\n                break;\n            }\n        }\n    }\n\n    protected assertNotificationCapability(method: NotificationMethod | string): void {\n        switch (method) {\n            case 'notifications/message': {\n                if (!this._capabilities.logging) {\n                    throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support logging (required for ${method})`);\n                }\n                break;\n            }\n\n            case 'notifications/resources/updated':\n            case 'notifications/resources/list_changed': {\n                if (!this._capabilities.resources) {\n                    throw new SdkError(\n                        SdkErrorCode.CapabilityNotSupported,\n                        `Server does not support notifying about resources (required for ${method})`\n                    );\n                }\n                break;\n            }\n\n            case 'notifications/tools/list_changed': {\n                if (!this._capabilities.tools) {\n                    throw new SdkError(\n                        SdkErrorCode.CapabilityNotSupported,\n                        `Server does not support notifying of tool list changes (required for ${method})`\n                    );\n                }\n                break;\n            }\n\n            case 'notifications/prompts/list_changed': {\n                if (!this._capabilities.prompts) {\n                    throw new SdkError(\n                        SdkErrorCode.CapabilityNotSupported,\n                        `Server does not support notifying of prompt list changes (required for ${method})`\n                    );\n                }\n                break;\n            }\n\n            case 'notifications/elicitation/complete': {\n                if (!this._clientCapabilities?.elicitation?.url) {\n                    throw new SdkError(\n                        SdkErrorCode.CapabilityNotSupported,\n                        `Client does not support URL elicitation (required for ${method})`\n                    );\n                }\n                break;\n            }\n\n            case 'notifications/cancelled': {\n                // Cancellation notifications are always allowed\n                break;\n            }\n\n            case 'notifications/progress': {\n                // Progress notifications are always allowed\n                break;\n            }\n        }\n    }\n\n    protected assertRequestHandlerCapability(method: string): void {\n        switch (method) {\n            case 'completion/complete': {\n                if (!this._capabilities.completions) {\n                    throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support completions (required for ${method})`);\n                }\n                break;\n            }\n\n            case 'logging/setLevel': {\n                if (!this._capabilities.logging) {\n                    throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support logging (required for ${method})`);\n                }\n                break;\n            }\n\n            case 'prompts/get':\n            case 'prompts/list': {\n                if (!this._capabilities.prompts) {\n                    throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support prompts (required for ${method})`);\n                }\n                break;\n            }\n\n            case 'resources/list':\n            case 'resources/templates/list':\n            case 'resources/read': {\n                if (!this._capabilities.resources) {\n                    throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support resources (required for ${method})`);\n                }\n                break;\n            }\n\n            case 'tools/call':\n            case 'tools/list': {\n                if (!this._capabilities.tools) {\n                    throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support tools (required for ${method})`);\n                }\n                break;\n            }\n\n            case 'ping':\n            case 'initialize': {\n                // No specific capability required for these methods\n                break;\n            }\n        }\n    }\n\n    private async _oninitialize(request: InitializeRequest): Promise<InitializeResult> {\n        const requestedVersion = request.params.protocolVersion;\n\n        this._clientCapabilities = request.params.capabilities;\n        this._clientVersion = request.params.clientInfo;\n\n        const protocolVersion = this._supportedProtocolVersions.includes(requestedVersion)\n            ? requestedVersion\n            : (this._supportedProtocolVersions[0] ?? LATEST_PROTOCOL_VERSION);\n\n        this._negotiatedProtocolVersion = protocolVersion;\n        this.transport?.setProtocolVersion?.(protocolVersion);\n\n        return {\n            protocolVersion,\n            capabilities: this.getCapabilities(),\n            serverInfo: this._serverInfo,\n            ...(this._instructions && { instructions: this._instructions })\n        };\n    }\n\n    /**\n     * After initialization has completed, this will be populated with the client's reported capabilities.\n     */\n    getClientCapabilities(): ClientCapabilities | undefined {\n        return this._clientCapabilities;\n    }\n\n    /**\n     * After initialization has completed, this will be populated with information about the client's name and version.\n     */\n    getClientVersion(): Implementation | undefined {\n        return this._clientVersion;\n    }\n\n    /**\n     * After initialization has completed, this will be populated with the protocol version negotiated\n     * with the client (the version the server responded with during the initialize handshake), or\n     * `undefined` before initialization.\n     */\n    getNegotiatedProtocolVersion(): string | undefined {\n        return this._negotiatedProtocolVersion;\n    }\n\n    /**\n     * Returns the current server capabilities.\n     */\n    public getCapabilities(): ServerCapabilities {\n        return this._capabilities;\n    }\n\n    async ping() {\n        return this._requestWithSchema({ method: 'ping' }, EmptyResultSchema);\n    }\n\n    /**\n     * Request LLM sampling from the client (without tools).\n     * Returns single content block for backwards compatibility.\n     *\n     * @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577).\n     * Remains functional during the deprecation window (at least twelve months).\n     * Migrate to calling LLM provider APIs directly.\n     */\n    async createMessage(params: CreateMessageRequestParamsBase, options?: RequestOptions): Promise<CreateMessageResult>;\n\n    /**\n     * Request LLM sampling from the client with tool support.\n     * Returns content that may be a single block or array (for parallel tool calls).\n     *\n     * @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577).\n     * Remains functional during the deprecation window (at least twelve months).\n     * Migrate to calling LLM provider APIs directly.\n     */\n    async createMessage(params: CreateMessageRequestParamsWithTools, options?: RequestOptions): Promise<CreateMessageResultWithTools>;\n\n    /**\n     * Request LLM sampling from the client.\n     * When tools may or may not be present, returns the union type.\n     *\n     * @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577).\n     * Remains functional during the deprecation window (at least twelve months).\n     * Migrate to calling LLM provider APIs directly.\n     */\n    async createMessage(\n        params: CreateMessageRequest['params'],\n        options?: RequestOptions\n    ): Promise<CreateMessageResult | CreateMessageResultWithTools>;\n\n    // Implementation\n    async createMessage(\n        params: CreateMessageRequest['params'],\n        options?: RequestOptions\n    ): Promise<CreateMessageResult | CreateMessageResultWithTools> {\n        // Capability check - only required when tools/toolChoice are provided\n        if ((params.tools || params.toolChoice) && !this._clientCapabilities?.sampling?.tools) {\n            throw new SdkError(SdkErrorCode.CapabilityNotSupported, 'Client does not support sampling tools capability.');\n        }\n\n        // Message structure validation - always validate tool_use/tool_result pairs.\n        // These may appear even without tools/toolChoice in the current request when\n        // a previous sampling request returned tool_use and this is a follow-up with results.\n        if (params.messages.length > 0) {\n            const lastMessage = params.messages.at(-1)!;\n            const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];\n            const hasToolResults = lastContent.some(c => c.type === 'tool_result');\n\n            const previousMessage = params.messages.length > 1 ? params.messages.at(-2) : undefined;\n            const previousContent = previousMessage\n                ? Array.isArray(previousMessage.content)\n                    ? previousMessage.content\n                    : [previousMessage.content]\n                : [];\n            const hasPreviousToolUse = previousContent.some(c => c.type === 'tool_use');\n\n            if (hasToolResults) {\n                if (lastContent.some(c => c.type !== 'tool_result')) {\n                    throw new ProtocolError(\n                        ProtocolErrorCode.InvalidParams,\n                        'The last message must contain only tool_result content if any is present'\n                    );\n                }\n                if (!hasPreviousToolUse) {\n                    throw new ProtocolError(\n                        ProtocolErrorCode.InvalidParams,\n                        'tool_result blocks are not matching any tool_use from the previous message'\n                    );\n                }\n            }\n            if (hasPreviousToolUse) {\n                const toolUseIds = new Set(previousContent.filter(c => c.type === 'tool_use').map(c => (c as ToolUseContent).id));\n                const toolResultIds = new Set(\n                    lastContent.filter(c => c.type === 'tool_result').map(c => (c as ToolResultContent).toolUseId)\n                );\n                if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every(id => toolResultIds.has(id))) {\n                    throw new ProtocolError(\n                        ProtocolErrorCode.InvalidParams,\n                        'ids of tool_result blocks and tool_use blocks from previous message do not match'\n                    );\n                }\n            }\n        }\n\n        // Use different schemas based on whether tools are provided\n        if (params.tools) {\n            return this._requestWithSchema({ method: 'sampling/createMessage', params }, CreateMessageResultWithToolsSchema, options);\n        }\n        return this._requestWithSchema({ method: 'sampling/createMessage', params }, CreateMessageResultSchema, options);\n    }\n\n    /**\n     * Creates an elicitation request for the given parameters.\n     * For backwards compatibility, `mode` may be omitted for form requests and will default to `\"form\"`.\n     * @param params The parameters for the elicitation request.\n     * @param options Optional request options.\n     * @returns The result of the elicitation request.\n     */\n    async elicitInput(params: ElicitRequestFormParams | ElicitRequestURLParams, options?: RequestOptions): Promise<ElicitResult> {\n        const mode = (params.mode ?? 'form') as 'form' | 'url';\n\n        switch (mode) {\n            case 'url': {\n                if (!this._clientCapabilities?.elicitation?.url) {\n                    throw new SdkError(SdkErrorCode.CapabilityNotSupported, 'Client does not support url elicitation.');\n                }\n\n                const urlParams = params as ElicitRequestURLParams;\n                return this._requestWithSchema({ method: 'elicitation/create', params: urlParams }, ElicitResultSchema, options);\n            }\n            case 'form': {\n                if (!this._clientCapabilities?.elicitation?.form) {\n                    throw new SdkError(SdkErrorCode.CapabilityNotSupported, 'Client does not support form elicitation.');\n                }\n\n                const formParams: ElicitRequestFormParams =\n                    params.mode === 'form' ? (params as ElicitRequestFormParams) : { ...(params as ElicitRequestFormParams), mode: 'form' };\n\n                const result = await this._requestWithSchema(\n                    { method: 'elicitation/create', params: formParams },\n                    ElicitResultSchema,\n                    options\n                );\n\n                if (result.action === 'accept' && result.content && formParams.requestedSchema) {\n                    try {\n                        const validator = this._jsonSchemaValidator.getValidator(formParams.requestedSchema as JsonSchemaType);\n                        const validationResult = validator(result.content);\n\n                        if (!validationResult.valid) {\n                            throw new ProtocolError(\n                                ProtocolErrorCode.InvalidParams,\n                                `Elicitation response content does not match requested schema: ${validationResult.errorMessage}`\n                            );\n                        }\n                    } catch (error) {\n                        if (error instanceof ProtocolError) {\n                            throw error;\n                        }\n                        throw new ProtocolError(\n                            ProtocolErrorCode.InternalError,\n                            `Error validating elicitation response: ${error instanceof Error ? error.message : String(error)}`\n                        );\n                    }\n                }\n                return result;\n            }\n        }\n    }\n\n    /**\n     * Creates a reusable callback that, when invoked, will send a `notifications/elicitation/complete`\n     * notification for the specified elicitation ID.\n     *\n     * @param elicitationId The ID of the elicitation to mark as complete.\n     * @param options Optional notification options. Useful when the completion notification should be related to a prior request.\n     * @returns A function that emits the completion notification when awaited.\n     */\n    createElicitationCompletionNotifier(elicitationId: string, options?: NotificationOptions): () => Promise<void> {\n        if (!this._clientCapabilities?.elicitation?.url) {\n            throw new SdkError(\n                SdkErrorCode.CapabilityNotSupported,\n                'Client does not support URL elicitation (required for notifications/elicitation/complete)'\n            );\n        }\n\n        return () =>\n            this.notification(\n                {\n                    method: 'notifications/elicitation/complete',\n                    params: {\n                        elicitationId\n                    }\n                },\n                options\n            );\n    }\n\n    /**\n     * Requests the list of roots from the client.\n     *\n     * @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577).\n     * Remains functional during the deprecation window (at least twelve months).\n     * Migrate to passing paths via tool parameters, resource URIs, or configuration.\n     */\n    async listRoots(params?: ListRootsRequest['params'], options?: RequestOptions) {\n        return this._requestWithSchema({ method: 'roots/list', params }, ListRootsResultSchema, options);\n    }\n\n    /**\n     * Sends a logging message to the client, if connected.\n     * Note: You only need to send the parameters object, not the entire JSON-RPC message.\n     * @see {@linkcode LoggingMessageNotification}\n     * @param params\n     * @param sessionId Optional for stateless transports and backward compatibility.\n     *\n     * @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577).\n     * Remains functional during the deprecation window (at least twelve months).\n     * Migrate to stderr logging (STDIO servers) or OpenTelemetry.\n     */\n    async sendLoggingMessage(params: LoggingMessageNotification['params'], sessionId?: string) {\n        if (this._capabilities.logging && !this.isMessageIgnored(params.level, sessionId)) {\n            return this.notification({ method: 'notifications/message', params });\n        }\n    }\n\n    async sendResourceUpdated(params: ResourceUpdatedNotification['params']) {\n        return this.notification({\n            method: 'notifications/resources/updated',\n            params\n        });\n    }\n\n    async sendResourceListChanged() {\n        return this.notification({\n            method: 'notifications/resources/list_changed'\n        });\n    }\n\n    async sendToolListChanged() {\n        return this.notification({ method: 'notifications/tools/list_changed' });\n    }\n\n    async sendPromptListChanged() {\n        return this.notification({ method: 'notifications/prompts/list_changed' });\n    }\n}\n","import type {\n    BaseMetadata,\n    CallToolResult,\n    CompleteRequestPrompt,\n    CompleteRequestResourceTemplate,\n    CompleteResult,\n    GetPromptResult,\n    Icon,\n    Implementation,\n    ListPromptsResult,\n    ListResourcesResult,\n    ListToolsResult,\n    LoggingMessageNotification,\n    Prompt,\n    PromptReference,\n    ReadResourceResult,\n    Resource,\n    ResourceTemplateReference,\n    Result,\n    ServerContext,\n    StandardSchemaWithJSON,\n    Tool,\n    ToolAnnotations,\n    ToolExecution,\n    Transport,\n    Variables\n} from '@modelcontextprotocol/core-internal';\nimport {\n    assertCompleteRequestPrompt,\n    assertCompleteRequestResourceTemplate,\n    normalizeRawShapeSchema,\n    promptArgumentsFromStandardSchema,\n    ProtocolError,\n    ProtocolErrorCode,\n    standardSchemaToJsonSchema,\n    UriTemplate,\n    validateAndWarnToolName,\n    validateStandardSchema\n} from '@modelcontextprotocol/core-internal';\nimport type * as z from 'zod/v4';\n\nimport { getCompleter, isCompletable } from './completable';\nimport type { ServerOptions } from './server';\nimport { Server } from './server';\n\n/**\n * High-level MCP server that provides a simpler API for working with resources, tools, and prompts.\n * For advanced usage (like sending notifications or setting custom request handlers), use the underlying\n * {@linkcode Server} instance available via the {@linkcode McpServer.server | server} property.\n *\n * @example\n * ```ts source=\"./mcp.examples.ts#McpServer_basicUsage\"\n * const server = new McpServer({\n *     name: 'my-server',\n *     version: '1.0.0'\n * });\n * ```\n */\nexport class McpServer {\n    /**\n     * The underlying {@linkcode Server} instance, useful for advanced operations like sending notifications.\n     */\n    public readonly server: Server;\n\n    private _registeredResources: { [uri: string]: RegisteredResource } = {};\n    private _registeredResourceTemplates: {\n        [name: string]: RegisteredResourceTemplate;\n    } = {};\n    private _registeredTools: { [name: string]: RegisteredTool } = {};\n    private _registeredPrompts: { [name: string]: RegisteredPrompt } = {};\n\n    constructor(serverInfo: Implementation, options?: ServerOptions) {\n        this.server = new Server(serverInfo, options);\n\n        // Per the MCP spec, a server that declares a primitive capability MUST respond to its\n        // list method (potentially with an empty result) rather than \"Method not found\" — even\n        // if nothing has been registered yet. Handlers are normally installed lazily on first\n        // registration, so eagerly install them here for any capability declared up front.\n        // (Users of the low-level `Server` class remain responsible for their own handlers.)\n        if (options?.capabilities?.tools) {\n            this.setToolRequestHandlers();\n        }\n        if (options?.capabilities?.resources) {\n            this.setResourceRequestHandlers();\n        }\n        if (options?.capabilities?.prompts) {\n            this.setPromptRequestHandlers();\n        }\n    }\n\n    /**\n     * Attaches to the given transport, starts it, and starts listening for messages.\n     *\n     * The `server` object assumes ownership of the {@linkcode Transport}, replacing any callbacks that have already been set, and expects that it is the only user of the {@linkcode Transport} instance going forward.\n     *\n     * @example\n     * ```ts source=\"./mcp.examples.ts#McpServer_connect_stdio\"\n     * const server = new McpServer({ name: 'my-server', version: '1.0.0' });\n     * const transport = new StdioServerTransport();\n     * await server.connect(transport);\n     * ```\n     */\n    async connect(transport: Transport): Promise<void> {\n        return await this.server.connect(transport);\n    }\n\n    /**\n     * Closes the connection.\n     */\n    async close(): Promise<void> {\n        await this.server.close();\n    }\n\n    private _toolHandlersInitialized = false;\n\n    private setToolRequestHandlers() {\n        if (this._toolHandlersInitialized) {\n            return;\n        }\n\n        this.server.assertCanSetRequestHandler('tools/list');\n        this.server.assertCanSetRequestHandler('tools/call');\n\n        this.server.registerCapabilities({\n            tools: {\n                listChanged: this.server.getCapabilities().tools?.listChanged ?? true\n            }\n        });\n\n        // Note: tools are listed in registration (insertion) order, which keeps the ordering\n        // deterministic across requests when the underlying tool set has not changed, as\n        // recommended by the spec.\n        this.server.setRequestHandler(\n            'tools/list',\n            (): ListToolsResult => ({\n                tools: Object.entries(this._registeredTools)\n                    .filter(([, tool]) => tool.enabled)\n                    .map(([name, tool]): Tool => {\n                        const toolDefinition: Tool = {\n                            name,\n                            title: tool.title,\n                            description: tool.description,\n                            inputSchema: tool.inputSchema\n                                ? (standardSchemaToJsonSchema(tool.inputSchema, 'input') as Tool['inputSchema'])\n                                : EMPTY_OBJECT_JSON_SCHEMA,\n                            annotations: tool.annotations,\n                            icons: tool.icons,\n                            execution: tool.execution,\n                            _meta: tool._meta\n                        };\n\n                        if (tool.outputSchema) {\n                            toolDefinition.outputSchema = standardSchemaToJsonSchema(tool.outputSchema, 'output') as Tool['outputSchema'];\n                        }\n\n                        return toolDefinition;\n                    })\n            })\n        );\n\n        this.server.setRequestHandler('tools/call', async (request, ctx): Promise<CallToolResult> => {\n            const tool = this._registeredTools[request.params.name];\n            if (!tool) {\n                throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Tool ${request.params.name} not found`);\n            }\n            if (!tool.enabled) {\n                throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);\n            }\n\n            try {\n                const args = await this.validateToolInput(tool, request.params.arguments, request.params.name);\n                const result = await this.executeToolHandler(tool, args, ctx);\n                await this.validateToolOutput(tool, result, request.params.name);\n                return result;\n            } catch (error) {\n                if (error instanceof ProtocolError && error.code === ProtocolErrorCode.UrlElicitationRequired) {\n                    throw error; // Return the error to the caller without wrapping in CallToolResult\n                }\n                return this.createToolError(error instanceof Error ? error.message : String(error));\n            }\n        });\n\n        this._toolHandlersInitialized = true;\n    }\n\n    /**\n     * Creates a tool error result.\n     *\n     * @param errorMessage - The error message.\n     * @returns The tool error result.\n     */\n    private createToolError(errorMessage: string): CallToolResult {\n        return {\n            content: [\n                {\n                    type: 'text',\n                    text: errorMessage\n                }\n            ],\n            isError: true\n        };\n    }\n\n    /**\n     * Validates tool input arguments against the tool's input schema.\n     */\n    private async validateToolInput<\n        ToolType extends RegisteredTool,\n        Args extends ToolType['inputSchema'] extends infer InputSchema\n            ? InputSchema extends StandardSchemaWithJSON\n                ? StandardSchemaWithJSON.InferOutput<InputSchema>\n                : undefined\n            : undefined\n    >(tool: ToolType, args: Args, toolName: string): Promise<Args> {\n        if (!tool.inputSchema) {\n            return undefined as Args;\n        }\n\n        const parseResult = await validateStandardSchema(tool.inputSchema, args ?? {});\n        if (!parseResult.success) {\n            throw new ProtocolError(\n                ProtocolErrorCode.InvalidParams,\n                `Input validation error: Invalid arguments for tool ${toolName}: ${parseResult.error}`\n            );\n        }\n\n        return parseResult.data as unknown as Args;\n    }\n\n    /**\n     * Validates tool output against the tool's output schema.\n     */\n    private async validateToolOutput(tool: RegisteredTool, result: CallToolResult, toolName: string): Promise<void> {\n        if (!tool.outputSchema) {\n            return;\n        }\n\n        if (result.isError) {\n            return;\n        }\n\n        if (!result.structuredContent) {\n            throw new ProtocolError(\n                ProtocolErrorCode.InvalidParams,\n                `Output validation error: Tool ${toolName} has an output schema but no structured content was provided`\n            );\n        }\n\n        // if the tool has an output schema, validate structured content\n        const parseResult = await validateStandardSchema(tool.outputSchema, result.structuredContent);\n        if (!parseResult.success) {\n            throw new ProtocolError(\n                ProtocolErrorCode.InvalidParams,\n                `Output validation error: Invalid structured content for tool ${toolName}: ${parseResult.error}`\n            );\n        }\n    }\n\n    /**\n     * Executes a tool handler.\n     */\n    private async executeToolHandler(tool: RegisteredTool, args: unknown, ctx: ServerContext): Promise<CallToolResult> {\n        // Executor encapsulates handler invocation with proper types\n        return tool.executor(args, ctx);\n    }\n\n    private _completionHandlerInitialized = false;\n\n    private setCompletionRequestHandler() {\n        if (this._completionHandlerInitialized) {\n            return;\n        }\n\n        this.server.assertCanSetRequestHandler('completion/complete');\n\n        this.server.registerCapabilities({\n            completions: {}\n        });\n\n        this.server.setRequestHandler('completion/complete', async (request): Promise<CompleteResult> => {\n            switch (request.params.ref.type) {\n                case 'ref/prompt': {\n                    assertCompleteRequestPrompt(request);\n                    return this.handlePromptCompletion(request, request.params.ref);\n                }\n\n                case 'ref/resource': {\n                    assertCompleteRequestResourceTemplate(request);\n                    return this.handleResourceCompletion(request, request.params.ref);\n                }\n\n                default: {\n                    throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid completion reference: ${request.params.ref}`);\n                }\n            }\n        });\n\n        this._completionHandlerInitialized = true;\n    }\n\n    private async handlePromptCompletion(request: CompleteRequestPrompt, ref: PromptReference): Promise<CompleteResult> {\n        const prompt = this._registeredPrompts[ref.name];\n        if (!prompt) {\n            throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Prompt ${ref.name} not found`);\n        }\n\n        if (!prompt.enabled) {\n            throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Prompt ${ref.name} disabled`);\n        }\n\n        if (!prompt.argsSchema) {\n            return EMPTY_COMPLETION_RESULT;\n        }\n\n        const promptShape = getSchemaShape(prompt.argsSchema);\n        const field = unwrapOptionalSchema(promptShape?.[request.params.argument.name]);\n        if (!isCompletable(field)) {\n            return EMPTY_COMPLETION_RESULT;\n        }\n\n        const completer = getCompleter(field);\n        if (!completer) {\n            return EMPTY_COMPLETION_RESULT;\n        }\n\n        const suggestions = await completer(request.params.argument.value, request.params.context);\n        return createCompletionResult(suggestions);\n    }\n\n    private async handleResourceCompletion(\n        request: CompleteRequestResourceTemplate,\n        ref: ResourceTemplateReference\n    ): Promise<CompleteResult> {\n        const template = Object.values(this._registeredResourceTemplates).find(t => t.resourceTemplate.uriTemplate.toString() === ref.uri);\n\n        if (!template) {\n            if (this._registeredResources[ref.uri]) {\n                // Attempting to autocomplete a fixed resource URI is not an error in the spec (but probably should be).\n                return EMPTY_COMPLETION_RESULT;\n            }\n\n            throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Resource template ${request.params.ref.uri} not found`);\n        }\n\n        const completer = template.resourceTemplate.completeCallback(request.params.argument.name);\n        if (!completer) {\n            return EMPTY_COMPLETION_RESULT;\n        }\n\n        const suggestions = await completer(request.params.argument.value, request.params.context);\n        return createCompletionResult(suggestions);\n    }\n\n    private _resourceHandlersInitialized = false;\n\n    private setResourceRequestHandlers() {\n        if (this._resourceHandlersInitialized) {\n            return;\n        }\n\n        this.server.assertCanSetRequestHandler('resources/list');\n        this.server.assertCanSetRequestHandler('resources/templates/list');\n        this.server.assertCanSetRequestHandler('resources/read');\n\n        this.server.registerCapabilities({\n            resources: {\n                listChanged: this.server.getCapabilities().resources?.listChanged ?? true\n            }\n        });\n\n        this.server.setRequestHandler('resources/list', async (_request, ctx) => {\n            const resources = Object.entries(this._registeredResources)\n                .filter(([_, resource]) => resource.enabled)\n                .map(([uri, resource]) => ({\n                    uri,\n                    name: resource.name,\n                    ...resource.metadata\n                }));\n\n            const templateResources: Resource[] = [];\n            for (const template of Object.values(this._registeredResourceTemplates)) {\n                if (!template.resourceTemplate.listCallback) {\n                    continue;\n                }\n\n                const result = await template.resourceTemplate.listCallback(ctx);\n                for (const resource of result.resources) {\n                    templateResources.push({\n                        ...template.metadata,\n                        // the defined resource metadata should override the template metadata if present\n                        ...resource\n                    });\n                }\n            }\n\n            return { resources: [...resources, ...templateResources] };\n        });\n\n        this.server.setRequestHandler('resources/templates/list', async () => {\n            const resourceTemplates = Object.entries(this._registeredResourceTemplates).map(([name, template]) => ({\n                name,\n                uriTemplate: template.resourceTemplate.uriTemplate.toString(),\n                ...template.metadata\n            }));\n\n            return { resourceTemplates };\n        });\n\n        this.server.setRequestHandler('resources/read', async (request, ctx) => {\n            const uri = new URL(request.params.uri);\n\n            // First check for exact resource match\n            const resource = this._registeredResources[uri.toString()];\n            if (resource) {\n                if (!resource.enabled) {\n                    throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Resource ${uri} disabled`);\n                }\n                return resource.readCallback(uri, ctx);\n            }\n\n            // Then check templates\n            for (const template of Object.values(this._registeredResourceTemplates)) {\n                const variables = template.resourceTemplate.uriTemplate.match(uri.toString());\n                if (variables) {\n                    return template.readCallback(uri, variables, ctx);\n                }\n            }\n\n            throw new ProtocolError(ProtocolErrorCode.ResourceNotFound, `Resource ${uri} not found`);\n        });\n\n        this._resourceHandlersInitialized = true;\n    }\n\n    private _promptHandlersInitialized = false;\n\n    private setPromptRequestHandlers() {\n        if (this._promptHandlersInitialized) {\n            return;\n        }\n\n        this.server.assertCanSetRequestHandler('prompts/list');\n        this.server.assertCanSetRequestHandler('prompts/get');\n\n        this.server.registerCapabilities({\n            prompts: {\n                listChanged: this.server.getCapabilities().prompts?.listChanged ?? true\n            }\n        });\n\n        this.server.setRequestHandler(\n            'prompts/list',\n            (): ListPromptsResult => ({\n                prompts: Object.entries(this._registeredPrompts)\n                    .filter(([, prompt]) => prompt.enabled)\n                    .map(([name, prompt]): Prompt => {\n                        return {\n                            name,\n                            title: prompt.title,\n                            description: prompt.description,\n                            arguments: prompt.argsSchema ? promptArgumentsFromStandardSchema(prompt.argsSchema) : undefined,\n                            icons: prompt.icons,\n                            _meta: prompt._meta\n                        };\n                    })\n            })\n        );\n\n        this.server.setRequestHandler('prompts/get', async (request, ctx): Promise<GetPromptResult> => {\n            const prompt = this._registeredPrompts[request.params.name];\n            if (!prompt) {\n                throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Prompt ${request.params.name} not found`);\n            }\n\n            if (!prompt.enabled) {\n                throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Prompt ${request.params.name} disabled`);\n            }\n\n            // Handler encapsulates parsing and callback invocation with proper types\n            return prompt.handler(request.params.arguments, ctx);\n        });\n\n        this._promptHandlersInitialized = true;\n    }\n\n    /**\n     * Registers a resource with a config object and callback.\n     * For static resources, use a URI string. For dynamic resources, use a {@linkcode ResourceTemplate}.\n     *\n     * @example\n     * ```ts source=\"./mcp.examples.ts#McpServer_registerResource_static\"\n     * server.registerResource(\n     *     'config',\n     *     'config://app',\n     *     {\n     *         title: 'Application Config',\n     *         mimeType: 'text/plain'\n     *     },\n     *     async uri => ({\n     *         contents: [{ uri: uri.href, text: 'App configuration here' }]\n     *     })\n     * );\n     * ```\n     */\n    registerResource(name: string, uriOrTemplate: string, config: ResourceMetadata, readCallback: ReadResourceCallback): RegisteredResource;\n    registerResource(\n        name: string,\n        uriOrTemplate: ResourceTemplate,\n        config: ResourceMetadata,\n        readCallback: ReadResourceTemplateCallback\n    ): RegisteredResourceTemplate;\n    registerResource(\n        name: string,\n        uriOrTemplate: string | ResourceTemplate,\n        config: ResourceMetadata,\n        readCallback: ReadResourceCallback | ReadResourceTemplateCallback\n    ): RegisteredResource | RegisteredResourceTemplate {\n        if (typeof uriOrTemplate === 'string') {\n            if (this._registeredResources[uriOrTemplate]) {\n                throw new Error(`Resource ${uriOrTemplate} is already registered`);\n            }\n\n            const registeredResource = this._createRegisteredResource(\n                name,\n                (config as BaseMetadata).title,\n                uriOrTemplate,\n                config,\n                readCallback as ReadResourceCallback\n            );\n\n            this.setResourceRequestHandlers();\n            this.sendResourceListChanged();\n            return registeredResource;\n        } else {\n            if (this._registeredResourceTemplates[name]) {\n                throw new Error(`Resource template ${name} is already registered`);\n            }\n\n            const registeredResourceTemplate = this._createRegisteredResourceTemplate(\n                name,\n                (config as BaseMetadata).title,\n                uriOrTemplate,\n                config,\n                readCallback as ReadResourceTemplateCallback\n            );\n\n            this.setResourceRequestHandlers();\n            this.sendResourceListChanged();\n            return registeredResourceTemplate;\n        }\n    }\n\n    private _createRegisteredResource(\n        name: string,\n        title: string | undefined,\n        uri: string,\n        metadata: ResourceMetadata | undefined,\n        readCallback: ReadResourceCallback\n    ): RegisteredResource {\n        const registeredResource: RegisteredResource = {\n            name,\n            title,\n            metadata,\n            readCallback,\n            enabled: true,\n            disable: () => registeredResource.update({ enabled: false }),\n            enable: () => registeredResource.update({ enabled: true }),\n            remove: () => registeredResource.update({ uri: null }),\n            update: updates => {\n                if (updates.uri !== undefined && updates.uri !== uri) {\n                    delete this._registeredResources[uri];\n                    if (updates.uri) this._registeredResources[updates.uri] = registeredResource;\n                }\n                if (updates.name !== undefined) registeredResource.name = updates.name;\n                if (updates.title !== undefined) registeredResource.title = updates.title;\n                if (updates.metadata !== undefined) registeredResource.metadata = updates.metadata;\n                if (updates.callback !== undefined) registeredResource.readCallback = updates.callback;\n                if (updates.enabled !== undefined) registeredResource.enabled = updates.enabled;\n                this.sendResourceListChanged();\n            }\n        };\n        this._registeredResources[uri] = registeredResource;\n        return registeredResource;\n    }\n\n    private _createRegisteredResourceTemplate(\n        name: string,\n        title: string | undefined,\n        template: ResourceTemplate,\n        metadata: ResourceMetadata | undefined,\n        readCallback: ReadResourceTemplateCallback\n    ): RegisteredResourceTemplate {\n        const registeredResourceTemplate: RegisteredResourceTemplate = {\n            resourceTemplate: template,\n            title,\n            metadata,\n            readCallback,\n            enabled: true,\n            disable: () => registeredResourceTemplate.update({ enabled: false }),\n            enable: () => registeredResourceTemplate.update({ enabled: true }),\n            remove: () => registeredResourceTemplate.update({ name: null }),\n            update: updates => {\n                if (updates.name !== undefined && updates.name !== name) {\n                    delete this._registeredResourceTemplates[name];\n                    if (updates.name) this._registeredResourceTemplates[updates.name] = registeredResourceTemplate;\n                }\n                if (updates.title !== undefined) registeredResourceTemplate.title = updates.title;\n                if (updates.template !== undefined) registeredResourceTemplate.resourceTemplate = updates.template;\n                if (updates.metadata !== undefined) registeredResourceTemplate.metadata = updates.metadata;\n                if (updates.callback !== undefined) registeredResourceTemplate.readCallback = updates.callback;\n                if (updates.enabled !== undefined) registeredResourceTemplate.enabled = updates.enabled;\n                this.sendResourceListChanged();\n            }\n        };\n        this._registeredResourceTemplates[name] = registeredResourceTemplate;\n\n        // If the resource template has any completion callbacks, enable completions capability\n        const variableNames = template.uriTemplate.variableNames;\n        const hasCompleter = Array.isArray(variableNames) && variableNames.some(v => !!template.completeCallback(v));\n        if (hasCompleter) {\n            this.setCompletionRequestHandler();\n        }\n\n        return registeredResourceTemplate;\n    }\n\n    private _createRegisteredPrompt(\n        name: string,\n        title: string | undefined,\n        description: string | undefined,\n        argsSchema: StandardSchemaWithJSON | undefined,\n        callback: PromptCallback<StandardSchemaWithJSON | undefined>,\n        icons: Icon[] | undefined,\n        _meta: Record<string, unknown> | undefined\n    ): RegisteredPrompt {\n        // Track current schema and callback for handler regeneration\n        let currentArgsSchema = argsSchema;\n        let currentCallback = callback;\n\n        const registeredPrompt: RegisteredPrompt = {\n            title,\n            description,\n            argsSchema,\n            icons,\n            _meta,\n            handler: createPromptHandler(name, argsSchema, callback),\n            enabled: true,\n            disable: () => registeredPrompt.update({ enabled: false }),\n            enable: () => registeredPrompt.update({ enabled: true }),\n            remove: () => registeredPrompt.update({ name: null }),\n            update: updates => {\n                if (updates.name !== undefined && updates.name !== name) {\n                    delete this._registeredPrompts[name];\n                    if (updates.name) this._registeredPrompts[updates.name] = registeredPrompt;\n                }\n                if (updates.title !== undefined) registeredPrompt.title = updates.title;\n                if (updates.description !== undefined) registeredPrompt.description = updates.description;\n                if (updates.icons !== undefined) registeredPrompt.icons = updates.icons;\n                if (updates._meta !== undefined) registeredPrompt._meta = updates._meta;\n\n                // Track if we need to regenerate the handler\n                let needsHandlerRegen = false;\n                if (updates.argsSchema !== undefined) {\n                    registeredPrompt.argsSchema = updates.argsSchema;\n                    currentArgsSchema = updates.argsSchema;\n                    needsHandlerRegen = true;\n                }\n                if (updates.callback !== undefined) {\n                    currentCallback = updates.callback as PromptCallback<StandardSchemaWithJSON | undefined>;\n                    needsHandlerRegen = true;\n                }\n                if (needsHandlerRegen) {\n                    registeredPrompt.handler = createPromptHandler(name, currentArgsSchema, currentCallback);\n                }\n\n                if (updates.enabled !== undefined) registeredPrompt.enabled = updates.enabled;\n                this.sendPromptListChanged();\n            }\n        };\n        this._registeredPrompts[name] = registeredPrompt;\n\n        // If any argument uses a Completable schema, enable completions capability\n        if (argsSchema) {\n            const shape = getSchemaShape(argsSchema);\n            if (shape) {\n                const hasCompletable = Object.values(shape).some(field => {\n                    const inner = unwrapOptionalSchema(field);\n                    return isCompletable(inner);\n                });\n                if (hasCompletable) {\n                    this.setCompletionRequestHandler();\n                }\n            }\n        }\n\n        return registeredPrompt;\n    }\n\n    private _createRegisteredTool(\n        name: string,\n        title: string | undefined,\n        description: string | undefined,\n        inputSchema: StandardSchemaWithJSON | undefined,\n        outputSchema: StandardSchemaWithJSON | undefined,\n        annotations: ToolAnnotations | undefined,\n        icons: Icon[] | undefined,\n        execution: ToolExecution | undefined,\n        _meta: Record<string, unknown> | undefined,\n        handler: AnyToolHandler<StandardSchemaWithJSON | undefined>\n    ): RegisteredTool {\n        // Validate tool name according to SEP specification\n        validateAndWarnToolName(name);\n\n        // Track current handler for executor regeneration\n        let currentHandler = handler;\n\n        const registeredTool: RegisteredTool = {\n            title,\n            description,\n            inputSchema,\n            outputSchema,\n            annotations,\n            icons,\n            execution,\n            _meta,\n            handler: handler,\n            executor: createToolExecutor(inputSchema, handler),\n            enabled: true,\n            disable: () => registeredTool.update({ enabled: false }),\n            enable: () => registeredTool.update({ enabled: true }),\n            remove: () => registeredTool.update({ name: null }),\n            update: updates => {\n                if (updates.name !== undefined && updates.name !== name) {\n                    if (typeof updates.name === 'string') {\n                        validateAndWarnToolName(updates.name);\n                    }\n                    delete this._registeredTools[name];\n                    if (updates.name) this._registeredTools[updates.name] = registeredTool;\n                }\n                if (updates.title !== undefined) registeredTool.title = updates.title;\n                if (updates.description !== undefined) registeredTool.description = updates.description;\n\n                // Track if we need to regenerate the executor\n                let needsExecutorRegen = false;\n                if (updates.paramsSchema !== undefined) {\n                    registeredTool.inputSchema = updates.paramsSchema;\n                    needsExecutorRegen = true;\n                }\n                if (updates.callback !== undefined) {\n                    registeredTool.handler = updates.callback;\n                    currentHandler = updates.callback as AnyToolHandler<StandardSchemaWithJSON | undefined>;\n                    needsExecutorRegen = true;\n                }\n                if (needsExecutorRegen) {\n                    registeredTool.executor = createToolExecutor(registeredTool.inputSchema, currentHandler);\n                }\n\n                if (updates.outputSchema !== undefined) registeredTool.outputSchema = updates.outputSchema;\n                if (updates.annotations !== undefined) registeredTool.annotations = updates.annotations;\n                if (updates.icons !== undefined) registeredTool.icons = updates.icons;\n                if (updates._meta !== undefined) registeredTool._meta = updates._meta;\n                if (updates.enabled !== undefined) registeredTool.enabled = updates.enabled;\n                this.sendToolListChanged();\n            }\n        };\n        this._registeredTools[name] = registeredTool;\n\n        this.setToolRequestHandlers();\n        this.sendToolListChanged();\n\n        return registeredTool;\n    }\n\n    /**\n     * Registers a tool with a config object and callback.\n     *\n     * @example\n     * ```ts source=\"./mcp.examples.ts#McpServer_registerTool_basic\"\n     * server.registerTool(\n     *     'calculate-bmi',\n     *     {\n     *         title: 'BMI Calculator',\n     *         description: 'Calculate Body Mass Index',\n     *         inputSchema: z.object({\n     *             weightKg: z.number(),\n     *             heightM: z.number()\n     *         }),\n     *         outputSchema: z.object({ bmi: z.number() })\n     *     },\n     *     async ({ weightKg, heightM }) => {\n     *         const output = { bmi: weightKg / (heightM * heightM) };\n     *         return {\n     *             content: [{ type: 'text', text: JSON.stringify(output) }],\n     *             structuredContent: output\n     *         };\n     *     }\n     * );\n     * ```\n     */\n    registerTool<OutputArgs extends StandardSchemaWithJSON, InputArgs extends StandardSchemaWithJSON | undefined = undefined>(\n        name: string,\n        config: {\n            title?: string;\n            description?: string;\n            inputSchema?: InputArgs;\n            outputSchema?: OutputArgs;\n            annotations?: ToolAnnotations;\n            icons?: Icon[];\n            _meta?: Record<string, unknown>;\n        },\n        cb: ToolCallback<InputArgs>\n    ): RegisteredTool;\n    /** @deprecated Wrap with `z.object({...})` instead. Raw-shape form: `inputSchema`/`outputSchema` may be a plain `{ field: z.string() }` record; it is auto-wrapped with `z.object()`. */\n    registerTool<InputArgs extends ZodRawShape, OutputArgs extends ZodRawShape | StandardSchemaWithJSON | undefined = undefined>(\n        name: string,\n        config: {\n            title?: string;\n            description?: string;\n            inputSchema?: InputArgs;\n            outputSchema?: OutputArgs;\n            annotations?: ToolAnnotations;\n            icons?: Icon[];\n            _meta?: Record<string, unknown>;\n        },\n        cb: LegacyToolCallback<InputArgs>\n    ): RegisteredTool;\n    registerTool(\n        name: string,\n        config: {\n            title?: string;\n            description?: string;\n            inputSchema?: StandardSchemaWithJSON | ZodRawShape;\n            outputSchema?: StandardSchemaWithJSON | ZodRawShape;\n            annotations?: ToolAnnotations;\n            icons?: Icon[];\n            _meta?: Record<string, unknown>;\n        },\n        cb: ToolCallback<StandardSchemaWithJSON | undefined> | LegacyToolCallback<ZodRawShape>\n    ): RegisteredTool {\n        if (this._registeredTools[name]) {\n            throw new Error(`Tool ${name} is already registered`);\n        }\n\n        const { title, description, inputSchema, outputSchema, annotations, icons, _meta } = config;\n\n        return this._createRegisteredTool(\n            name,\n            title,\n            description,\n            normalizeRawShapeSchema(inputSchema),\n            normalizeRawShapeSchema(outputSchema),\n            annotations,\n            icons,\n            undefined,\n            _meta,\n            cb as ToolCallback<StandardSchemaWithJSON | undefined>\n        );\n    }\n\n    /**\n     * Registers a prompt with a config object and callback.\n     *\n     * @example\n     * ```ts source=\"./mcp.examples.ts#McpServer_registerPrompt_basic\"\n     * server.registerPrompt(\n     *     'review-code',\n     *     {\n     *         title: 'Code Review',\n     *         description: 'Review code for best practices',\n     *         argsSchema: z.object({ code: z.string() })\n     *     },\n     *     ({ code }) => ({\n     *         messages: [\n     *             {\n     *                 role: 'user' as const,\n     *                 content: {\n     *                     type: 'text' as const,\n     *                     text: `Please review this code:\\n\\n${code}`\n     *                 }\n     *             }\n     *         ]\n     *     })\n     * );\n     * ```\n     */\n    registerPrompt<Args extends StandardSchemaWithJSON>(\n        name: string,\n        config: {\n            title?: string;\n            description?: string;\n            argsSchema?: Args;\n            icons?: Icon[];\n            _meta?: Record<string, unknown>;\n        },\n        cb: PromptCallback<Args>\n    ): RegisteredPrompt;\n    /** @deprecated Wrap with `z.object({...})` instead. Raw-shape form: `argsSchema` may be a plain `{ field: z.string() }` record; it is auto-wrapped with `z.object()`. */\n    registerPrompt<Args extends ZodRawShape>(\n        name: string,\n        config: {\n            title?: string;\n            description?: string;\n            argsSchema?: Args;\n            icons?: Icon[];\n            _meta?: Record<string, unknown>;\n        },\n        cb: LegacyPromptCallback<Args>\n    ): RegisteredPrompt;\n    registerPrompt(\n        name: string,\n        config: {\n            title?: string;\n            description?: string;\n            argsSchema?: StandardSchemaWithJSON | ZodRawShape;\n            icons?: Icon[];\n            _meta?: Record<string, unknown>;\n        },\n        cb: PromptCallback<StandardSchemaWithJSON> | LegacyPromptCallback<ZodRawShape>\n    ): RegisteredPrompt {\n        if (this._registeredPrompts[name]) {\n            throw new Error(`Prompt ${name} is already registered`);\n        }\n\n        const { title, description, argsSchema, icons, _meta } = config;\n\n        const registeredPrompt = this._createRegisteredPrompt(\n            name,\n            title,\n            description,\n            normalizeRawShapeSchema(argsSchema),\n            cb as PromptCallback<StandardSchemaWithJSON | undefined>,\n            icons,\n            _meta\n        );\n\n        this.setPromptRequestHandlers();\n        this.sendPromptListChanged();\n\n        return registeredPrompt;\n    }\n\n    /**\n     * Checks if the server is connected to a transport.\n     * @returns `true` if the server is connected\n     */\n    isConnected() {\n        return this.server.transport !== undefined;\n    }\n\n    /**\n     * Sends a logging message to the client, if connected.\n     * Note: You only need to send the parameters object, not the entire JSON-RPC message.\n     * @see {@linkcode LoggingMessageNotification}\n     * @param params\n     * @param sessionId Optional for stateless transports and backward compatibility.\n     *\n     * @example\n     * ```ts source=\"./mcp.examples.ts#McpServer_sendLoggingMessage_basic\"\n     * await server.sendLoggingMessage({\n     *     level: 'info',\n     *     data: 'Processing complete'\n     * });\n     * ```\n     *\n     * @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577).\n     * Remains functional during the deprecation window (at least twelve months).\n     * Migrate to stderr logging (STDIO servers) or OpenTelemetry.\n     */\n    async sendLoggingMessage(params: LoggingMessageNotification['params'], sessionId?: string) {\n        return this.server.sendLoggingMessage(params, sessionId);\n    }\n    /**\n     * Sends a resource list changed event to the client, if connected.\n     */\n    sendResourceListChanged() {\n        if (this.isConnected()) {\n            this.server.sendResourceListChanged();\n        }\n    }\n\n    /**\n     * Sends a tool list changed event to the client, if connected.\n     */\n    sendToolListChanged() {\n        if (this.isConnected()) {\n            this.server.sendToolListChanged();\n        }\n    }\n\n    /**\n     * Sends a prompt list changed event to the client, if connected.\n     */\n    sendPromptListChanged() {\n        if (this.isConnected()) {\n            this.server.sendPromptListChanged();\n        }\n    }\n}\n\n/**\n * A callback to complete one variable within a resource template's URI template.\n */\nexport type CompleteResourceTemplateCallback = (\n    value: string,\n    context?: {\n        arguments?: Record<string, string>;\n    }\n) => string[] | Promise<string[]>;\n\n/**\n * A resource template combines a URI pattern with optional functionality to enumerate\n * all resources matching that pattern.\n */\nexport class ResourceTemplate {\n    private _uriTemplate: UriTemplate;\n\n    constructor(\n        uriTemplate: string | UriTemplate,\n        private _callbacks: {\n            /**\n             * A callback to list all resources matching this template. This is required to be specified, even if `undefined`, to avoid accidentally forgetting resource listing.\n             */\n            list: ListResourcesCallback | undefined;\n\n            /**\n             * An optional callback to autocomplete variables within the URI template. Useful for clients and users to discover possible values.\n             */\n            complete?: {\n                [variable: string]: CompleteResourceTemplateCallback;\n            };\n        }\n    ) {\n        this._uriTemplate = typeof uriTemplate === 'string' ? new UriTemplate(uriTemplate) : uriTemplate;\n    }\n\n    /**\n     * Gets the URI template pattern.\n     */\n    get uriTemplate(): UriTemplate {\n        return this._uriTemplate;\n    }\n\n    /**\n     * Gets the list callback, if one was provided.\n     */\n    get listCallback(): ListResourcesCallback | undefined {\n        return this._callbacks.list;\n    }\n\n    /**\n     * Gets the callback for completing a specific URI template variable, if one was provided.\n     */\n    completeCallback(variable: string): CompleteResourceTemplateCallback | undefined {\n        return this._callbacks.complete?.[variable];\n    }\n}\n\n/**\n * A plain record of Zod field schemas, e.g. `{ name: z.string() }`. Accepted by\n * `registerTool`/`registerPrompt` as a shorthand; auto-wrapped with `z.object()`.\n * Zod schemas only — `z.object()` cannot wrap other Standard Schema libraries.\n */\nexport type ZodRawShape = Record<string, z.ZodType>;\n\n/** Infers the parsed-output type of a {@linkcode ZodRawShape}. */\nexport type InferRawShape<S extends ZodRawShape> = z.infer<z.ZodObject<S>>;\n\n/** {@linkcode ToolCallback} variant used when `inputSchema` is a {@linkcode ZodRawShape}. */\nexport type LegacyToolCallback<Args extends ZodRawShape | undefined> = Args extends ZodRawShape\n    ? (args: InferRawShape<Args>, ctx: ServerContext) => CallToolResult | Promise<CallToolResult>\n    : (ctx: ServerContext) => CallToolResult | Promise<CallToolResult>;\n\n/** {@linkcode PromptCallback} variant used when `argsSchema` is a {@linkcode ZodRawShape}. */\nexport type LegacyPromptCallback<Args extends ZodRawShape | undefined> = Args extends ZodRawShape\n    ? (args: InferRawShape<Args>, ctx: ServerContext) => GetPromptResult | Promise<GetPromptResult>\n    : (ctx: ServerContext) => GetPromptResult | Promise<GetPromptResult>;\n\nexport type BaseToolCallback<\n    SendResultT extends Result,\n    Ctx extends ServerContext,\n    Args extends StandardSchemaWithJSON | undefined\n> = Args extends StandardSchemaWithJSON\n    ? (args: StandardSchemaWithJSON.InferOutput<Args>, ctx: Ctx) => SendResultT | Promise<SendResultT>\n    : (ctx: Ctx) => SendResultT | Promise<SendResultT>;\n\n/**\n * Callback for a tool handler registered with {@linkcode McpServer.registerTool}.\n */\nexport type ToolCallback<Args extends StandardSchemaWithJSON | undefined = undefined> = BaseToolCallback<\n    CallToolResult,\n    ServerContext,\n    Args\n>;\n\n/**\n * Tool handler callback type.\n */\nexport type AnyToolHandler<Args extends StandardSchemaWithJSON | undefined = undefined> = ToolCallback<Args>;\n\n/**\n * Internal executor type that encapsulates handler invocation with proper types.\n */\ntype ToolExecutor = (args: unknown, ctx: ServerContext) => Promise<CallToolResult>;\n\nexport type RegisteredTool = {\n    title?: string;\n    description?: string;\n    inputSchema?: StandardSchemaWithJSON;\n    outputSchema?: StandardSchemaWithJSON;\n    annotations?: ToolAnnotations;\n    icons?: Icon[];\n    execution?: ToolExecution;\n    _meta?: Record<string, unknown>;\n    handler: AnyToolHandler<StandardSchemaWithJSON | undefined>;\n    /** @hidden */\n    executor: ToolExecutor;\n    enabled: boolean;\n    enable(): void;\n    disable(): void;\n    update(updates: {\n        name?: string | null;\n        title?: string;\n        description?: string;\n        paramsSchema?: StandardSchemaWithJSON;\n        outputSchema?: StandardSchemaWithJSON;\n        annotations?: ToolAnnotations;\n        icons?: Icon[];\n        _meta?: Record<string, unknown>;\n        callback?: ToolCallback<StandardSchemaWithJSON>;\n        enabled?: boolean;\n    }): void;\n    remove(): void;\n};\n\n/**\n * Creates an executor that invokes the handler with the appropriate arguments.\n * When `inputSchema` is defined, the handler is called with `(args, ctx)`.\n * When `inputSchema` is undefined, the handler is called with just `(ctx)`.\n */\nfunction createToolExecutor(\n    inputSchema: StandardSchemaWithJSON | undefined,\n    handler: AnyToolHandler<StandardSchemaWithJSON | undefined>\n): ToolExecutor {\n    if (inputSchema) {\n        const callback = handler as ToolCallbackInternal;\n        return async (args, ctx) => callback(args, ctx);\n    }\n\n    // When no inputSchema, call with just ctx (the handler expects (ctx) signature)\n    const callback = handler as (ctx: ServerContext) => CallToolResult | Promise<CallToolResult>;\n    return async (_args, ctx) => callback(ctx);\n}\n\nconst EMPTY_OBJECT_JSON_SCHEMA = {\n    type: 'object' as const,\n    properties: {}\n};\n\n/**\n * Additional, optional information for annotating a resource.\n */\nexport type ResourceMetadata = Omit<Resource, 'uri' | 'name'>;\n\n/**\n * Callback to list all resources matching a given template.\n */\nexport type ListResourcesCallback = (ctx: ServerContext) => ListResourcesResult | Promise<ListResourcesResult>;\n\n/**\n * Callback to read a resource at a given URI.\n */\nexport type ReadResourceCallback = (uri: URL, ctx: ServerContext) => ReadResourceResult | Promise<ReadResourceResult>;\n\nexport type RegisteredResource = {\n    name: string;\n    title?: string;\n    metadata?: ResourceMetadata;\n    readCallback: ReadResourceCallback;\n    enabled: boolean;\n    enable(): void;\n    disable(): void;\n    update(updates: {\n        name?: string;\n        title?: string;\n        uri?: string | null;\n        metadata?: ResourceMetadata;\n        callback?: ReadResourceCallback;\n        enabled?: boolean;\n    }): void;\n    remove(): void;\n};\n\n/**\n * Callback to read a resource at a given URI, following a filled-in URI template.\n */\nexport type ReadResourceTemplateCallback = (\n    uri: URL,\n    variables: Variables,\n    ctx: ServerContext\n) => ReadResourceResult | Promise<ReadResourceResult>;\n\nexport type RegisteredResourceTemplate = {\n    resourceTemplate: ResourceTemplate;\n    title?: string;\n    metadata?: ResourceMetadata;\n    readCallback: ReadResourceTemplateCallback;\n    enabled: boolean;\n    enable(): void;\n    disable(): void;\n    update(updates: {\n        name?: string | null;\n        title?: string;\n        template?: ResourceTemplate;\n        metadata?: ResourceMetadata;\n        callback?: ReadResourceTemplateCallback;\n        enabled?: boolean;\n    }): void;\n    remove(): void;\n};\n\nexport type PromptCallback<Args extends StandardSchemaWithJSON | undefined = undefined> = Args extends StandardSchemaWithJSON\n    ? (args: StandardSchemaWithJSON.InferOutput<Args>, ctx: ServerContext) => GetPromptResult | Promise<GetPromptResult>\n    : (ctx: ServerContext) => GetPromptResult | Promise<GetPromptResult>;\n\n/**\n * Internal handler type that encapsulates parsing and callback invocation.\n * This allows type-safe handling without runtime type assertions.\n */\ntype PromptHandler = (args: Record<string, unknown> | undefined, ctx: ServerContext) => Promise<GetPromptResult>;\n\ntype ToolCallbackInternal = (args: unknown, ctx: ServerContext) => CallToolResult | Promise<CallToolResult>;\n\nexport type RegisteredPrompt = {\n    title?: string;\n    description?: string;\n    argsSchema?: StandardSchemaWithJSON;\n    icons?: Icon[];\n    _meta?: Record<string, unknown>;\n    /** @hidden */\n    handler: PromptHandler;\n    enabled: boolean;\n    enable(): void;\n    disable(): void;\n    update<Args extends StandardSchemaWithJSON>(updates: {\n        name?: string | null;\n        title?: string;\n        description?: string;\n        argsSchema?: Args;\n        icons?: Icon[];\n        _meta?: Record<string, unknown>;\n        callback?: PromptCallback<Args>;\n        enabled?: boolean;\n    }): void;\n    remove(): void;\n};\n\n/**\n * Creates a type-safe prompt handler that captures the schema and callback in a closure.\n * This eliminates the need for type assertions at the call site.\n */\nfunction createPromptHandler(\n    name: string,\n    argsSchema: StandardSchemaWithJSON | undefined,\n    callback: PromptCallback<StandardSchemaWithJSON | undefined>\n): PromptHandler {\n    if (argsSchema) {\n        const typedCallback = callback as (args: unknown, ctx: ServerContext) => GetPromptResult | Promise<GetPromptResult>;\n\n        return async (args, ctx) => {\n            const parseResult = await validateStandardSchema(argsSchema, args);\n            if (!parseResult.success) {\n                throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid arguments for prompt ${name}: ${parseResult.error}`);\n            }\n            return typedCallback(parseResult.data, ctx);\n        };\n    } else {\n        const typedCallback = callback as (ctx: ServerContext) => GetPromptResult | Promise<GetPromptResult>;\n\n        return async (_args, ctx) => {\n            return typedCallback(ctx);\n        };\n    }\n}\n\nfunction createCompletionResult(suggestions: readonly unknown[]): CompleteResult {\n    const values = suggestions.map(String).slice(0, 100);\n    return {\n        completion: {\n            values,\n            total: suggestions.length,\n            hasMore: suggestions.length > 100\n        }\n    };\n}\n\nconst EMPTY_COMPLETION_RESULT: CompleteResult = {\n    completion: {\n        values: [],\n        hasMore: false\n    }\n};\n\n/** @internal Gets the shape of a Zod object schema */\nfunction getSchemaShape(schema: unknown): Record<string, unknown> | undefined {\n    const candidate = schema as { shape?: unknown };\n    if (candidate.shape && typeof candidate.shape === 'object') {\n        return candidate.shape as Record<string, unknown>;\n    }\n    return undefined;\n}\n\n/** @internal Checks if a Zod schema is optional */\nfunction isOptionalSchema(schema: unknown): boolean {\n    const candidate = schema as { type?: string } | null | undefined;\n    return candidate?.type === 'optional';\n}\n\n/** @internal Unwraps an optional Zod schema */\nfunction unwrapOptionalSchema(schema: unknown): unknown {\n    if (!isOptionalSchema(schema)) {\n        return schema;\n    }\n    const candidate = schema as { def?: { innerType?: unknown } };\n    return candidate.def?.innerType ?? schema;\n}\n","export type HostHeaderValidationResult =\n    | { ok: true; hostname: string }\n    | {\n          ok: false;\n          errorCode: 'missing_host' | 'invalid_host_header' | 'invalid_host';\n          message: string;\n          hostHeader?: string;\n          hostname?: string;\n      };\n\n/**\n * Parse and validate a `Host` header against an allowlist of hostnames (port-agnostic).\n *\n * - Input host header may include a port (e.g. `localhost:3000`) or IPv6 brackets (e.g. `[::1]:3000`).\n * - Allowlist items should be hostnames only (no ports). For IPv6, include brackets (e.g. `[::1]`).\n */\nexport function validateHostHeader(hostHeader: string | null | undefined, allowedHostnames: string[]): HostHeaderValidationResult {\n    if (!hostHeader) {\n        return { ok: false, errorCode: 'missing_host', message: 'Missing Host header' };\n    }\n\n    // Use URL API to parse hostname (handles IPv4, IPv6, and regular hostnames)\n    let hostname: string;\n    try {\n        hostname = new URL(`http://${hostHeader}`).hostname;\n    } catch {\n        return { ok: false, errorCode: 'invalid_host_header', message: `Invalid Host header: ${hostHeader}`, hostHeader };\n    }\n\n    if (!allowedHostnames.includes(hostname)) {\n        return { ok: false, errorCode: 'invalid_host', message: `Invalid Host: ${hostname}`, hostHeader, hostname };\n    }\n\n    return { ok: true, hostname };\n}\n\n/**\n * Convenience allowlist for `localhost` DNS rebinding protection.\n */\nexport function localhostAllowedHostnames(): string[] {\n    return ['localhost', '127.0.0.1', '[::1]'];\n}\n\n/**\n * Web-standard `Request` helper for DNS rebinding protection.\n * @example\n * ```ts source=\"./hostHeaderValidation.examples.ts#hostHeaderValidationResponse_basicUsage\"\n * const result = validateHostHeader(req.headers.get('host'), ['localhost']);\n * ```\n */\nexport function hostHeaderValidationResponse(req: Request, allowedHostnames: string[]): Response | undefined {\n    const result = validateHostHeader(req.headers.get('host'), allowedHostnames);\n    if (result.ok) return undefined;\n\n    return Response.json(\n        {\n            jsonrpc: '2.0',\n            error: {\n                code: -32_000,\n                message: result.message\n            },\n            id: null\n        },\n        {\n            status: 403,\n            headers: { 'Content-Type': 'application/json' }\n        }\n    );\n}\n","/**\n * Web Standards Streamable HTTP Server Transport\n *\n * This is the core transport implementation using Web Standard APIs (`Request`, `Response`, `ReadableStream`).\n * It can run on any runtime that supports Web Standards: Node.js 18+, Cloudflare Workers, Deno, Bun, etc.\n *\n * For Node.js Express/HTTP compatibility, use {@linkcode @modelcontextprotocol/node!NodeStreamableHTTPServerTransport | NodeStreamableHTTPServerTransport} which wraps this transport.\n */\n\nimport type { AuthInfo, JSONRPCMessage, MessageExtraInfo, RequestId, Transport } from '@modelcontextprotocol/core-internal';\nimport {\n    DEFAULT_NEGOTIATED_PROTOCOL_VERSION,\n    isInitializeRequest,\n    isJSONRPCErrorResponse,\n    isJSONRPCRequest,\n    isJSONRPCResultResponse,\n    JSONRPCMessageSchema,\n    SUPPORTED_PROTOCOL_VERSIONS\n} from '@modelcontextprotocol/core-internal';\n\nexport type StreamId = string;\nexport type EventId = string;\n\n/**\n * Interface for resumability support via event storage\n */\nexport interface EventStore {\n    /**\n     * Stores an event for later retrieval\n     * @param streamId ID of the stream the event belongs to\n     * @param message The JSON-RPC message to store\n     * @returns The generated event ID for the stored event\n     */\n    storeEvent(streamId: StreamId, message: JSONRPCMessage): Promise<EventId>;\n\n    /**\n     * Get the stream ID associated with a given event ID.\n     * @param eventId The event ID to look up\n     * @returns The stream ID, or `undefined` if not found\n     *\n     * Optional: If not provided, the SDK will use the `streamId` returned by\n     * {@linkcode replayEventsAfter} for stream mapping.\n     */\n    getStreamIdForEventId?(eventId: EventId): Promise<StreamId | undefined>;\n\n    replayEventsAfter(\n        lastEventId: EventId,\n        {\n            send\n        }: {\n            send: (eventId: EventId, message: JSONRPCMessage) => Promise<void>;\n        }\n    ): Promise<StreamId>;\n}\n\n/**\n * Internal stream mapping for managing SSE connections\n */\ninterface StreamMapping {\n    /** Stream controller for pushing SSE data - only used with `ReadableStream` approach */\n    controller?: ReadableStreamDefaultController<Uint8Array>;\n    /** Text encoder for SSE formatting */\n    encoder?: InstanceType<typeof TextEncoder>;\n    /** Promise resolver for JSON response mode */\n    resolveJson?: (response: Response) => void;\n    /** Cleanup function to close stream and remove mapping */\n    cleanup: () => void;\n}\n\n/**\n * Configuration options for {@linkcode WebStandardStreamableHTTPServerTransport}\n */\nexport interface WebStandardStreamableHTTPServerTransportOptions {\n    /**\n     * Function that generates a session ID for the transport.\n     * The session ID SHOULD be globally unique and cryptographically secure (e.g., a securely generated UUID, a JWT, or a cryptographic hash)\n     *\n     * If not provided, session management is disabled (stateless mode).\n     */\n    sessionIdGenerator?: (() => string) | undefined;\n\n    /**\n     * A callback for session initialization events\n     * This is called when the server initializes a new session.\n     * Useful in cases when you need to register multiple mcp sessions\n     * and need to keep track of them.\n     * @param sessionId The generated session ID\n     */\n    onsessioninitialized?: ((sessionId: string) => void | Promise<void>) | undefined;\n\n    /**\n     * A callback for session close events\n     * This is called when the server closes a session due to a `DELETE` request.\n     * Useful in cases when you need to clean up resources associated with the session.\n     * Note that this is different from the transport closing, if you are handling\n     * HTTP requests from multiple nodes you might want to close each\n     * {@linkcode WebStandardStreamableHTTPServerTransport} after a request is completed while still keeping the\n     * session open/running.\n     * @param sessionId The session ID that was closed\n     */\n    onsessionclosed?: ((sessionId: string) => void | Promise<void>) | undefined;\n\n    /**\n     * If `true`, the server will return JSON responses instead of starting an SSE stream.\n     * This can be useful for simple request/response scenarios without streaming.\n     * Default is `false` (SSE streams are preferred).\n     */\n    enableJsonResponse?: boolean;\n\n    /**\n     * Event store for resumability support\n     * If provided, resumability will be enabled, allowing clients to reconnect and resume messages\n     */\n    eventStore?: EventStore;\n\n    /**\n     * List of allowed `Host` header values for DNS rebinding protection.\n     * If not specified, host validation is disabled.\n     * @deprecated Use external middleware for host validation instead.\n     */\n    allowedHosts?: string[];\n\n    /**\n     * List of allowed `Origin` header values for DNS rebinding protection.\n     * If not specified, origin validation is disabled.\n     * @deprecated Use external middleware for origin validation instead.\n     */\n    allowedOrigins?: string[];\n\n    /**\n     * Enable DNS rebinding protection (requires `allowedHosts` and/or `allowedOrigins` to be configured).\n     * Default is `false` for backwards compatibility.\n     * @deprecated Use external middleware for DNS rebinding protection instead.\n     */\n    enableDnsRebindingProtection?: boolean;\n\n    /**\n     * Retry interval in milliseconds to suggest to clients in SSE `retry` field.\n     * When set, the server will send a `retry` field in SSE priming events to control\n     * client reconnection timing for polling behavior.\n     */\n    retryInterval?: number;\n\n    /**\n     * List of protocol versions that this transport will accept.\n     * Used to validate the `mcp-protocol-version` header in incoming requests.\n     *\n     * Note: When using {@linkcode server/server.Server.connect | Server.connect()}, the server automatically passes its\n     * `supportedProtocolVersions` to the transport, so you typically don't need\n     * to set this option directly.\n     *\n     * @default {@linkcode SUPPORTED_PROTOCOL_VERSIONS}\n     */\n    supportedProtocolVersions?: string[];\n}\n\n/**\n * Options for handling a request\n */\nexport interface HandleRequestOptions {\n    /**\n     * Pre-parsed request body. If provided, the transport will use this instead of parsing `req.json()`.\n     * Useful when using body-parser middleware that has already parsed the body.\n     */\n    parsedBody?: unknown;\n\n    /**\n     * Authentication info from middleware. If provided, will be passed to message handlers.\n     */\n    authInfo?: AuthInfo;\n}\n\n/**\n * Server transport for Web Standards Streamable HTTP: this implements the MCP Streamable HTTP transport specification\n * using Web Standard APIs (`Request`, `Response`, `ReadableStream`).\n *\n * This transport works on any runtime that supports Web Standards: Node.js 18+, Cloudflare Workers, Deno, Bun, etc.\n *\n * In stateful mode:\n * - Session ID is generated and included in response headers\n * - Session ID is always included in initialization responses\n * - Requests with invalid session IDs are rejected with `404 Not Found`\n * - Non-initialization requests without a session ID are rejected with `400 Bad Request`\n * - State is maintained in-memory (connections, message history)\n *\n * In stateless mode:\n * - No Session ID is included in any responses\n * - No session validation is performed\n *\n * @example Stateful setup\n * ```ts source=\"./streamableHttp.examples.ts#WebStandardStreamableHTTPServerTransport_stateful\"\n * const server = new McpServer({ name: 'my-server', version: '1.0.0' });\n *\n * const transport = new WebStandardStreamableHTTPServerTransport({\n *     sessionIdGenerator: () => crypto.randomUUID()\n * });\n *\n * await server.connect(transport);\n * ```\n *\n * @example Stateless setup\n * ```ts source=\"./streamableHttp.examples.ts#WebStandardStreamableHTTPServerTransport_stateless\"\n * const transport = new WebStandardStreamableHTTPServerTransport({\n *     sessionIdGenerator: undefined\n * });\n * ```\n *\n * @example Hono.js\n * ```ts source=\"./streamableHttp.examples.ts#WebStandardStreamableHTTPServerTransport_hono\"\n * app.all('/mcp', async c => {\n *     return transport.handleRequest(c.req.raw);\n * });\n * ```\n *\n * @example Cloudflare Workers\n * ```ts source=\"./streamableHttp.examples.ts#WebStandardStreamableHTTPServerTransport_workers\"\n * const worker = {\n *     async fetch(request: Request): Promise<Response> {\n *         return transport.handleRequest(request);\n *     }\n * };\n * ```\n */\nexport class WebStandardStreamableHTTPServerTransport implements Transport {\n    // when sessionId is not set (undefined), it means the transport is in stateless mode\n    private sessionIdGenerator: (() => string) | undefined;\n    private _started: boolean = false;\n    private _closed: boolean = false;\n    private _streamMapping: Map<string, StreamMapping> = new Map();\n    private _requestToStreamMapping: Map<RequestId, string> = new Map();\n    private _requestResponseMap: Map<RequestId, JSONRPCMessage> = new Map();\n    private _initialized: boolean = false;\n    private _enableJsonResponse: boolean = false;\n    private _standaloneSseStreamId: string = '_GET_stream';\n    private _eventStore?: EventStore;\n    private _onsessioninitialized?: ((sessionId: string) => void | Promise<void>) | undefined;\n    private _onsessionclosed?: ((sessionId: string) => void | Promise<void>) | undefined;\n    private _allowedHosts?: string[];\n    private _allowedOrigins?: string[];\n    private _enableDnsRebindingProtection: boolean;\n    private _retryInterval?: number;\n    private _supportedProtocolVersions: string[];\n\n    sessionId?: string;\n    onclose?: () => void;\n    onerror?: (error: Error) => void;\n    onmessage?: (message: JSONRPCMessage, extra?: MessageExtraInfo) => void;\n\n    constructor(options: WebStandardStreamableHTTPServerTransportOptions = {}) {\n        this.sessionIdGenerator = options.sessionIdGenerator;\n        this._enableJsonResponse = options.enableJsonResponse ?? false;\n        this._eventStore = options.eventStore;\n        this._onsessioninitialized = options.onsessioninitialized;\n        this._onsessionclosed = options.onsessionclosed;\n        this._allowedHosts = options.allowedHosts;\n        this._allowedOrigins = options.allowedOrigins;\n        this._enableDnsRebindingProtection = options.enableDnsRebindingProtection ?? false;\n        this._retryInterval = options.retryInterval;\n        this._supportedProtocolVersions = options.supportedProtocolVersions ?? SUPPORTED_PROTOCOL_VERSIONS;\n    }\n\n    /**\n     * Starts the transport. This is required by the {@linkcode Transport} interface but is a no-op\n     * for the Streamable HTTP transport as connections are managed per-request.\n     */\n    async start(): Promise<void> {\n        if (this._started) {\n            throw new Error('Transport already started');\n        }\n        this._started = true;\n    }\n\n    /**\n     * Sets the supported protocol versions for header validation.\n     * Called by the server during {@linkcode server/server.Server.connect | connect()} to pass its supported versions.\n     */\n    setSupportedProtocolVersions(versions: string[]): void {\n        this._supportedProtocolVersions = versions;\n    }\n\n    /**\n     * Helper to create a JSON error response\n     */\n    private createJsonErrorResponse(\n        status: number,\n        code: number,\n        message: string,\n        options?: { headers?: Record<string, string>; data?: string }\n    ): Response {\n        const error: { code: number; message: string; data?: string } = { code, message };\n        if (options?.data !== undefined) {\n            error.data = options.data;\n        }\n        return Response.json(\n            {\n                jsonrpc: '2.0',\n                error,\n                id: null\n            },\n            {\n                status,\n                headers: {\n                    'Content-Type': 'application/json',\n                    ...options?.headers\n                }\n            }\n        );\n    }\n\n    /**\n     * Validates request headers for DNS rebinding protection.\n     * @returns Error response if validation fails, `undefined` if validation passes.\n     */\n    private validateRequestHeaders(req: Request): Response | undefined {\n        // Skip validation if protection is not enabled\n        if (!this._enableDnsRebindingProtection) {\n            return undefined;\n        }\n\n        // Validate Host header if allowedHosts is configured\n        if (this._allowedHosts && this._allowedHosts.length > 0) {\n            const hostHeader = req.headers.get('host');\n            if (!hostHeader || !this._allowedHosts.includes(hostHeader)) {\n                const error = `Invalid Host header: ${hostHeader}`;\n                this.onerror?.(new Error(error));\n                return this.createJsonErrorResponse(403, -32_000, error);\n            }\n        }\n\n        // Validate Origin header if allowedOrigins is configured\n        if (this._allowedOrigins && this._allowedOrigins.length > 0) {\n            const originHeader = req.headers.get('origin');\n            if (originHeader && !this._allowedOrigins.includes(originHeader)) {\n                const error = `Invalid Origin header: ${originHeader}`;\n                this.onerror?.(new Error(error));\n                return this.createJsonErrorResponse(403, -32_000, error);\n            }\n        }\n\n        return undefined;\n    }\n\n    /**\n     * Handles an incoming HTTP request, whether `GET`, `POST`, or `DELETE`\n     * Returns a `Response` object (Web Standard)\n     */\n    async handleRequest(req: Request, options?: HandleRequestOptions): Promise<Response> {\n        // Validate request headers for DNS rebinding protection\n        const validationError = this.validateRequestHeaders(req);\n        if (validationError) {\n            return validationError;\n        }\n\n        switch (req.method) {\n            case 'POST': {\n                return this.handlePostRequest(req, options);\n            }\n            case 'GET': {\n                return this.handleGetRequest(req);\n            }\n            case 'DELETE': {\n                return this.handleDeleteRequest(req);\n            }\n            default: {\n                return this.handleUnsupportedRequest();\n            }\n        }\n    }\n\n    /**\n     * Returns true if the client's protocol version supports empty SSE data in\n     * priming events (the fix shipped with protocol version `2025-11-25`).\n     *\n     * The version is checked for membership in this transport instance's\n     * supported protocol versions rather than with an open-ended\n     * `>= '2025-11-25'` comparison: the value may come from an `initialize`\n     * request body, which (unlike the `MCP-Protocol-Version` header) is not\n     * validated against `supportedProtocolVersions` before reaching this\n     * check. An unknown future version string must not silently enable\n     * behavior reserved for versions this transport actually supports.\n     */\n    private supportsEmptySSEData(protocolVersion: string): boolean {\n        return this._supportedProtocolVersions.includes(protocolVersion) && protocolVersion >= '2025-11-25';\n    }\n\n    /**\n     * Writes a priming event to establish resumption capability.\n     * Only sends if `eventStore` is configured (opt-in for resumability) and\n     * the client's protocol version supports empty SSE data (a supported\n     * version that is >= `2025-11-25`).\n     */\n    private async writePrimingEvent(\n        controller: ReadableStreamDefaultController<Uint8Array>,\n        encoder: InstanceType<typeof TextEncoder>,\n        streamId: string,\n        protocolVersion: string\n    ): Promise<void> {\n        if (!this._eventStore) {\n            return;\n        }\n\n        // Priming events have empty data which older clients cannot handle.\n        // Only send priming events to clients whose protocol version includes\n        // the fix for handling empty SSE data.\n        if (!this.supportsEmptySSEData(protocolVersion)) {\n            return;\n        }\n\n        const primingEventId = await this._eventStore.storeEvent(streamId, {} as JSONRPCMessage);\n\n        let primingEvent = `id: ${primingEventId}\\ndata: \\n\\n`;\n        if (this._retryInterval !== undefined) {\n            primingEvent = `id: ${primingEventId}\\nretry: ${this._retryInterval}\\ndata: \\n\\n`;\n        }\n        controller.enqueue(encoder.encode(primingEvent));\n    }\n\n    /**\n     * Handles `GET` requests for SSE stream\n     */\n    private async handleGetRequest(req: Request): Promise<Response> {\n        // The client MUST include an Accept header, listing text/event-stream as a supported content type.\n        const acceptHeader = req.headers.get('accept');\n        if (!acceptHeader?.includes('text/event-stream')) {\n            this.onerror?.(new Error('Not Acceptable: Client must accept text/event-stream'));\n            return this.createJsonErrorResponse(406, -32_000, 'Not Acceptable: Client must accept text/event-stream');\n        }\n\n        // If an Mcp-Session-Id is returned by the server during initialization,\n        // clients using the Streamable HTTP transport MUST include it\n        // in the Mcp-Session-Id header on all of their subsequent HTTP requests.\n        const sessionError = this.validateSession(req);\n        if (sessionError) {\n            return sessionError;\n        }\n        const protocolError = this.validateProtocolVersion(req);\n        if (protocolError) {\n            return protocolError;\n        }\n\n        // Handle resumability: check for Last-Event-ID header\n        if (this._eventStore) {\n            const lastEventId = req.headers.get('last-event-id');\n            if (lastEventId) {\n                return this.replayEvents(lastEventId);\n            }\n        }\n\n        // Check if there's already an active standalone SSE stream for this session\n        if (this._streamMapping.get(this._standaloneSseStreamId) !== undefined) {\n            // Only one GET SSE stream is allowed per session\n            this.onerror?.(new Error('Conflict: Only one SSE stream is allowed per session'));\n            return this.createJsonErrorResponse(409, -32_000, 'Conflict: Only one SSE stream is allowed per session');\n        }\n\n        const encoder = new TextEncoder();\n        let streamController: ReadableStreamDefaultController<Uint8Array>;\n\n        // Create a ReadableStream with a controller we can use to push SSE events\n        const readable = new ReadableStream<Uint8Array>({\n            start: controller => {\n                streamController = controller;\n            },\n            cancel: () => {\n                // Stream was cancelled by client\n                this._streamMapping.delete(this._standaloneSseStreamId);\n            }\n        });\n\n        const headers: Record<string, string> = {\n            'Content-Type': 'text/event-stream',\n            'Cache-Control': 'no-cache, no-transform',\n            Connection: 'keep-alive'\n        };\n\n        // After initialization, always include the session ID if we have one\n        if (this.sessionId !== undefined) {\n            headers['mcp-session-id'] = this.sessionId;\n        }\n\n        // Store the stream mapping with the controller for pushing data\n        this._streamMapping.set(this._standaloneSseStreamId, {\n            controller: streamController!,\n            encoder,\n            cleanup: () => {\n                this._streamMapping.delete(this._standaloneSseStreamId);\n                try {\n                    streamController!.close();\n                } catch {\n                    // Controller might already be closed\n                }\n            }\n        });\n\n        return new Response(readable, { headers });\n    }\n\n    /**\n     * Replays events that would have been sent after the specified event ID\n     * Only used when resumability is enabled\n     */\n    private async replayEvents(lastEventId: string): Promise<Response> {\n        if (!this._eventStore) {\n            this.onerror?.(new Error('Event store not configured'));\n            return this.createJsonErrorResponse(400, -32_000, 'Event store not configured');\n        }\n\n        try {\n            // If getStreamIdForEventId is available, use it for conflict checking\n            let streamId: string | undefined;\n            if (this._eventStore.getStreamIdForEventId) {\n                streamId = await this._eventStore.getStreamIdForEventId(lastEventId);\n\n                if (!streamId) {\n                    this.onerror?.(new Error('Invalid event ID format'));\n                    return this.createJsonErrorResponse(400, -32_000, 'Invalid event ID format');\n                }\n\n                // Check conflict with the SAME streamId we'll use for mapping\n                if (this._streamMapping.get(streamId) !== undefined) {\n                    this.onerror?.(new Error('Conflict: Stream already has an active connection'));\n                    return this.createJsonErrorResponse(409, -32_000, 'Conflict: Stream already has an active connection');\n                }\n            }\n\n            const headers: Record<string, string> = {\n                'Content-Type': 'text/event-stream',\n                'Cache-Control': 'no-cache, no-transform',\n                Connection: 'keep-alive'\n            };\n\n            if (this.sessionId !== undefined) {\n                headers['mcp-session-id'] = this.sessionId;\n            }\n\n            // Create a ReadableStream with controller for SSE\n            const encoder = new TextEncoder();\n            let streamController: ReadableStreamDefaultController<Uint8Array>;\n\n            const readable = new ReadableStream<Uint8Array>({\n                start: controller => {\n                    streamController = controller;\n                },\n                cancel: () => {\n                    // Stream was cancelled by client\n                    // Cleanup will be handled by the mapping\n                }\n            });\n\n            // Replay events - returns the streamId for backwards compatibility\n            const replayedStreamId = await this._eventStore.replayEventsAfter(lastEventId, {\n                send: async (eventId: string, message: JSONRPCMessage) => {\n                    const success = this.writeSSEEvent(streamController!, encoder, message, eventId);\n                    if (!success) {\n                        try {\n                            streamController!.close();\n                        } catch {\n                            // Controller might already be closed\n                        }\n                    }\n                }\n            });\n\n            this._streamMapping.set(replayedStreamId, {\n                controller: streamController!,\n                encoder,\n                cleanup: () => {\n                    this._streamMapping.delete(replayedStreamId);\n                    try {\n                        streamController!.close();\n                    } catch {\n                        // Controller might already be closed\n                    }\n                }\n            });\n\n            return new Response(readable, { headers });\n        } catch (error) {\n            this.onerror?.(error as Error);\n            return this.createJsonErrorResponse(500, -32_000, 'Error replaying events');\n        }\n    }\n\n    /**\n     * Writes an event to an SSE stream via controller with proper formatting\n     */\n    private writeSSEEvent(\n        controller: ReadableStreamDefaultController<Uint8Array>,\n        encoder: InstanceType<typeof TextEncoder>,\n        message: JSONRPCMessage,\n        eventId?: string\n    ): boolean {\n        try {\n            let eventData = `event: message\\n`;\n            // Include event ID if provided - this is important for resumability\n            if (eventId) {\n                eventData += `id: ${eventId}\\n`;\n            }\n            eventData += `data: ${JSON.stringify(message)}\\n\\n`;\n            controller.enqueue(encoder.encode(eventData));\n            return true;\n        } catch (error) {\n            this.onerror?.(error as Error);\n            return false;\n        }\n    }\n\n    /**\n     * Handles unsupported requests (`PUT`, `PATCH`, etc.)\n     */\n    private handleUnsupportedRequest(): Response {\n        this.onerror?.(new Error('Method not allowed.'));\n        return Response.json(\n            {\n                jsonrpc: '2.0',\n                error: {\n                    code: -32_000,\n                    message: 'Method not allowed.'\n                },\n                id: null\n            },\n            {\n                status: 405,\n                headers: {\n                    Allow: 'GET, POST, DELETE',\n                    'Content-Type': 'application/json'\n                }\n            }\n        );\n    }\n\n    /**\n     * Handles `POST` requests containing JSON-RPC messages\n     */\n    private async handlePostRequest(req: Request, options?: HandleRequestOptions): Promise<Response> {\n        try {\n            // Validate the Accept header\n            const acceptHeader = req.headers.get('accept');\n            // The client MUST include an Accept header, listing both application/json and text/event-stream as supported content types.\n            if (!acceptHeader?.includes('application/json') || !acceptHeader.includes('text/event-stream')) {\n                this.onerror?.(new Error('Not Acceptable: Client must accept both application/json and text/event-stream'));\n                return this.createJsonErrorResponse(\n                    406,\n                    -32_000,\n                    'Not Acceptable: Client must accept both application/json and text/event-stream'\n                );\n            }\n\n            const ct = req.headers.get('content-type');\n            if (!ct || !ct.includes('application/json')) {\n                this.onerror?.(new Error('Unsupported Media Type: Content-Type must be application/json'));\n                return this.createJsonErrorResponse(415, -32_000, 'Unsupported Media Type: Content-Type must be application/json');\n            }\n\n            const request = req;\n\n            let rawMessage;\n            if (options?.parsedBody === undefined) {\n                try {\n                    rawMessage = await req.json();\n                } catch (error) {\n                    this.onerror?.(error as Error);\n                    return this.createJsonErrorResponse(400, -32_700, 'Parse error: Invalid JSON');\n                }\n            } else {\n                rawMessage = options.parsedBody;\n            }\n\n            let messages: JSONRPCMessage[];\n\n            // handle batch and single messages\n            try {\n                messages = Array.isArray(rawMessage)\n                    ? rawMessage.map(msg => JSONRPCMessageSchema.parse(msg))\n                    : [JSONRPCMessageSchema.parse(rawMessage)];\n            } catch (error) {\n                this.onerror?.(error as Error);\n                return this.createJsonErrorResponse(400, -32_700, 'Parse error: Invalid JSON-RPC message');\n            }\n\n            // Check if this is an initialization request\n            // https://spec.modelcontextprotocol.io/specification/2025-03-26/basic/lifecycle/\n            const isInitializationRequest = messages.some(element => isInitializeRequest(element));\n            if (isInitializationRequest) {\n                // If it's a server with session management and the session ID is already set we should reject the request\n                // to avoid re-initialization.\n                if (this._initialized && this.sessionId !== undefined) {\n                    this.onerror?.(new Error('Invalid Request: Server already initialized'));\n                    return this.createJsonErrorResponse(400, -32_600, 'Invalid Request: Server already initialized');\n                }\n                if (messages.length > 1) {\n                    this.onerror?.(new Error('Invalid Request: Only one initialization request is allowed'));\n                    return this.createJsonErrorResponse(400, -32_600, 'Invalid Request: Only one initialization request is allowed');\n                }\n                this.sessionId = this.sessionIdGenerator?.();\n                this._initialized = true;\n\n                // If we have a session ID and an onsessioninitialized handler, call it immediately\n                // This is needed in cases where the server needs to keep track of multiple sessions\n                if (this.sessionId && this._onsessioninitialized) {\n                    await Promise.resolve(this._onsessioninitialized(this.sessionId));\n                }\n            }\n            if (!isInitializationRequest) {\n                // If an Mcp-Session-Id is returned by the server during initialization,\n                // clients using the Streamable HTTP transport MUST include it\n                // in the Mcp-Session-Id header on all of their subsequent HTTP requests.\n                const sessionError = this.validateSession(req);\n                if (sessionError) {\n                    return sessionError;\n                }\n                // Mcp-Protocol-Version header is required for all requests after initialization.\n                const protocolError = this.validateProtocolVersion(req);\n                if (protocolError) {\n                    return protocolError;\n                }\n            }\n\n            // check if it contains requests\n            const hasRequests = messages.some(element => isJSONRPCRequest(element));\n\n            if (!hasRequests) {\n                // if it only contains notifications or responses, return 202\n                for (const message of messages) {\n                    this.onmessage?.(message, { authInfo: options?.authInfo, request });\n                }\n                return new Response(null, { status: 202 });\n            }\n\n            // The default behavior is to use SSE streaming\n            // but in some cases server will return JSON responses\n            const streamId = crypto.randomUUID();\n\n            // Extract protocol version for priming event decision.\n            // For initialize requests, get from request params.\n            // For other requests, get from header (already validated).\n            const initRequest = messages.find(m => isInitializeRequest(m));\n            const clientProtocolVersion = initRequest\n                ? initRequest.params.protocolVersion\n                : (req.headers.get('mcp-protocol-version') ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION);\n\n            if (this._enableJsonResponse) {\n                // For JSON response mode, return a Promise that resolves when all responses are ready\n                return new Promise<Response>(resolve => {\n                    this._streamMapping.set(streamId, {\n                        resolveJson: resolve,\n                        cleanup: () => {\n                            this._streamMapping.delete(streamId);\n                        }\n                    });\n\n                    for (const message of messages) {\n                        if (isJSONRPCRequest(message)) {\n                            this._requestToStreamMapping.set(message.id, streamId);\n                        }\n                    }\n\n                    for (const message of messages) {\n                        this.onmessage?.(message, { authInfo: options?.authInfo, request });\n                    }\n                });\n            }\n\n            // SSE streaming mode - use ReadableStream with controller for more reliable data pushing\n            const encoder = new TextEncoder();\n            let streamController: ReadableStreamDefaultController<Uint8Array>;\n\n            const readable = new ReadableStream<Uint8Array>({\n                start: controller => {\n                    streamController = controller;\n                },\n                cancel: () => {\n                    // Stream was cancelled by client\n                    this._streamMapping.delete(streamId);\n                }\n            });\n\n            const headers: Record<string, string> = {\n                'Content-Type': 'text/event-stream',\n                'Cache-Control': 'no-cache',\n                Connection: 'keep-alive'\n            };\n\n            // After initialization, always include the session ID if we have one\n            if (this.sessionId !== undefined) {\n                headers['mcp-session-id'] = this.sessionId;\n            }\n\n            // Store the response for this request to send messages back through this connection\n            // We need to track by request ID to maintain the connection\n            for (const message of messages) {\n                if (isJSONRPCRequest(message)) {\n                    this._streamMapping.set(streamId, {\n                        controller: streamController!,\n                        encoder,\n                        cleanup: () => {\n                            this._streamMapping.delete(streamId);\n                            try {\n                                streamController!.close();\n                            } catch {\n                                // Controller might already be closed\n                            }\n                        }\n                    });\n                    this._requestToStreamMapping.set(message.id, streamId);\n                }\n            }\n\n            // Write priming event if event store is configured (after mapping is set up)\n            await this.writePrimingEvent(streamController!, encoder, streamId, clientProtocolVersion);\n\n            // handle each message\n            for (const message of messages) {\n                // Build closeSSEStream callback for requests when eventStore is configured\n                // AND client supports resumability (a supported protocol version >= 2025-11-25).\n                // Old clients can't resume if the stream is closed early because they\n                // didn't receive a priming event with an event ID.\n                let closeSSEStream: (() => void) | undefined;\n                let closeStandaloneSSEStream: (() => void) | undefined;\n                if (isJSONRPCRequest(message) && this._eventStore && this.supportsEmptySSEData(clientProtocolVersion)) {\n                    closeSSEStream = () => {\n                        this.closeSSEStream(message.id);\n                    };\n                    closeStandaloneSSEStream = () => {\n                        this.closeStandaloneSSEStream();\n                    };\n                }\n\n                this.onmessage?.(message, { authInfo: options?.authInfo, request, closeSSEStream, closeStandaloneSSEStream });\n            }\n            // The server SHOULD NOT close the SSE stream before sending all JSON-RPC responses\n            // This will be handled by the send() method when responses are ready\n\n            return new Response(readable, { status: 200, headers });\n        } catch (error) {\n            // return JSON-RPC formatted error\n            this.onerror?.(error as Error);\n            return this.createJsonErrorResponse(400, -32_700, 'Parse error', { data: String(error) });\n        }\n    }\n\n    /**\n     * Handles `DELETE` requests to terminate sessions\n     */\n    private async handleDeleteRequest(req: Request): Promise<Response> {\n        const sessionError = this.validateSession(req);\n        if (sessionError) {\n            return sessionError;\n        }\n        const protocolError = this.validateProtocolVersion(req);\n        if (protocolError) {\n            return protocolError;\n        }\n\n        await Promise.resolve(this._onsessionclosed?.(this.sessionId!));\n        await this.close();\n        return new Response(null, { status: 200 });\n    }\n\n    /**\n     * Validates session ID for non-initialization requests.\n     * Returns `Response` error if invalid, `undefined` otherwise\n     */\n    private validateSession(req: Request): Response | undefined {\n        if (this.sessionIdGenerator === undefined) {\n            // If the sessionIdGenerator ID is not set, the session management is disabled\n            // and we don't need to validate the session ID\n            return undefined;\n        }\n        if (!this._initialized) {\n            // If the server has not been initialized yet, reject all requests\n            this.onerror?.(new Error('Bad Request: Server not initialized'));\n            return this.createJsonErrorResponse(400, -32_000, 'Bad Request: Server not initialized');\n        }\n\n        const sessionId = req.headers.get('mcp-session-id');\n\n        if (!sessionId) {\n            // Non-initialization requests without a session ID should return 400 Bad Request\n            this.onerror?.(new Error('Bad Request: Mcp-Session-Id header is required'));\n            return this.createJsonErrorResponse(400, -32_000, 'Bad Request: Mcp-Session-Id header is required');\n        }\n\n        if (sessionId !== this.sessionId) {\n            // Reject requests with invalid session ID with 404 Not Found\n            this.onerror?.(new Error('Session not found'));\n            return this.createJsonErrorResponse(404, -32_001, 'Session not found');\n        }\n\n        return undefined;\n    }\n\n    /**\n     * Validates the `MCP-Protocol-Version` header on incoming requests.\n     *\n     * For initialization: Version negotiation handles unknown versions gracefully\n     * (server responds with its supported version).\n     *\n     * For subsequent requests with `MCP-Protocol-Version` header:\n     * - Accept if in supported list\n     * - 400 if unsupported\n     *\n     * For HTTP requests without the `MCP-Protocol-Version` header:\n     * - Accept and default to the version negotiated at initialization\n     */\n    private validateProtocolVersion(req: Request): Response | undefined {\n        const protocolVersion = req.headers.get('mcp-protocol-version');\n\n        if (protocolVersion !== null && !this._supportedProtocolVersions.includes(protocolVersion)) {\n            const error = `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${this._supportedProtocolVersions.join(', ')})`;\n            this.onerror?.(new Error(error));\n            return this.createJsonErrorResponse(400, -32_000, error);\n        }\n        return undefined;\n    }\n\n    async close(): Promise<void> {\n        if (this._closed) {\n            return;\n        }\n        this._closed = true;\n\n        // Close all SSE connections\n        for (const { cleanup } of this._streamMapping.values()) {\n            cleanup();\n        }\n        this._streamMapping.clear();\n\n        // Clear any pending responses\n        this._requestResponseMap.clear();\n        this.onclose?.();\n    }\n\n    /**\n     * Close an SSE stream for a specific request, triggering client reconnection.\n     * Use this to implement polling behavior during long-running operations -\n     * client will reconnect after the retry interval specified in the priming event.\n     */\n    closeSSEStream(requestId: RequestId): void {\n        const streamId = this._requestToStreamMapping.get(requestId);\n        if (!streamId) return;\n\n        const stream = this._streamMapping.get(streamId);\n        if (stream) {\n            stream.cleanup();\n        }\n    }\n\n    /**\n     * Close the standalone `GET` SSE stream, triggering client reconnection.\n     * Use this to implement polling behavior for server-initiated notifications.\n     */\n    closeStandaloneSSEStream(): void {\n        const stream = this._streamMapping.get(this._standaloneSseStreamId);\n        if (stream) {\n            stream.cleanup();\n        }\n    }\n\n    async send(message: JSONRPCMessage, options?: { relatedRequestId?: RequestId }): Promise<void> {\n        let requestId = options?.relatedRequestId;\n        if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {\n            // If the message is a response, use the request ID from the message\n            requestId = message.id;\n        }\n\n        // Check if this message should be sent on the standalone SSE stream (no request ID)\n        // Ignore notifications from tools (which have relatedRequestId set)\n        // Those will be sent via dedicated response SSE streams\n        if (requestId === undefined) {\n            // For standalone SSE streams, we can only send requests and notifications\n            if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {\n                throw new Error('Cannot send a response on a standalone SSE stream unless resuming a previous client request');\n            }\n\n            // Generate and store event ID if event store is provided\n            // Store even if stream is disconnected so events can be replayed on reconnect\n            let eventId: string | undefined;\n            if (this._eventStore) {\n                // Stores the event and gets the generated event ID\n                eventId = await this._eventStore.storeEvent(this._standaloneSseStreamId, message);\n            }\n\n            const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId);\n            if (standaloneSse === undefined) {\n                // Stream is disconnected - event is stored for replay, nothing more to do\n                return;\n            }\n\n            // Send the message to the standalone SSE stream\n            if (standaloneSse.controller && standaloneSse.encoder) {\n                this.writeSSEEvent(standaloneSse.controller, standaloneSse.encoder, message, eventId);\n            }\n            return;\n        }\n\n        // Get the response for this request\n        const streamId = this._requestToStreamMapping.get(requestId);\n        if (!streamId) {\n            throw new Error(`No connection established for request ID: ${String(requestId)}`);\n        }\n\n        const stream = this._streamMapping.get(streamId);\n\n        if (!this._enableJsonResponse && stream?.controller && stream?.encoder) {\n            // For SSE responses, generate event ID if event store is provided\n            let eventId: string | undefined;\n\n            if (this._eventStore) {\n                eventId = await this._eventStore.storeEvent(streamId, message);\n            }\n            // Write the event to the response stream\n            this.writeSSEEvent(stream.controller, stream.encoder, message, eventId);\n        }\n\n        if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {\n            this._requestResponseMap.set(requestId, message);\n            const relatedIds = [...this._requestToStreamMapping.entries()].filter(([_, sid]) => sid === streamId).map(([id]) => id);\n\n            // Check if we have responses for all requests using this connection\n            const allResponsesReady = relatedIds.every(id => this._requestResponseMap.has(id));\n\n            if (allResponsesReady) {\n                if (!stream) {\n                    throw new Error(`No connection established for request ID: ${String(requestId)}`);\n                }\n                if (this._enableJsonResponse && stream.resolveJson) {\n                    // All responses ready, send as JSON\n                    const headers: Record<string, string> = {\n                        'Content-Type': 'application/json'\n                    };\n                    if (this.sessionId !== undefined) {\n                        headers['mcp-session-id'] = this.sessionId;\n                    }\n\n                    const responses = relatedIds.map(id => this._requestResponseMap.get(id)!);\n\n                    if (responses.length === 1) {\n                        stream.resolveJson(Response.json(responses[0], { status: 200, headers }));\n                    } else {\n                        stream.resolveJson(Response.json(responses, { status: 200, headers }));\n                    }\n                } else {\n                    // End the SSE stream\n                    stream.cleanup();\n                }\n                // Clean up\n                for (const id of relatedIds) {\n                    this._requestResponseMap.delete(id);\n                    this._requestToStreamMapping.delete(id);\n                }\n            }\n        }\n    }\n}\n","import type { JsonSchemaType, jsonSchemaValidator, StandardSchemaWithJSON } from '@modelcontextprotocol/core-internal';\nimport { fromJsonSchema as coreFromJsonSchema } from '@modelcontextprotocol/core-internal';\nimport { DefaultJsonSchemaValidator } from '@modelcontextprotocol/server/_shims';\n\nlet _defaultValidator: jsonSchemaValidator | undefined;\n\nexport function fromJsonSchema<T = unknown>(schema: JsonSchemaType, validator?: jsonSchemaValidator): StandardSchemaWithJSON<T, T> {\n    return coreFromJsonSchema<T>(schema, validator ?? (_defaultValidator ??= new DefaultJsonSchemaValidator()));\n}\n"],"mappings":";;;;AAEA,MAAaA,qBAAoC,OAAO,IAAI,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgD9E,SAAgB,YAAwC,QAAW,UAAqD;AACpH,QAAO,eAAe,QAAkB,oBAAoB;EACxD,OAAO,EAAE,UAAU;EACnB,YAAY;EACZ,UAAU;EACV,cAAc;EACjB,CAAC;AACF,QAAO;;;;;AAMX,SAAgB,cAAc,QAAgE;AAC1F,QAAO,CAAC,CAAC,UAAU,OAAO,WAAW,YAAY,sBAAuB;;;;;AAM5E,SAAgB,aAAyC,QAA4C;AAEjG,QADc,OAAoE,qBACrE;;;;;;;;;;;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