import * as Context from "../../Context.ts"; import * as Effect from "../../Effect.ts"; import * as Layer from "../../Layer.ts"; import * as Queue from "../../Queue.ts"; import * as Schema from "../../Schema.ts"; import type { Stdio } from "../../Stdio.ts"; import * as HttpRouter from "../http/HttpRouter.ts"; import * as RpcClient from "../rpc/RpcClient.ts"; import type * as RpcGroup from "../rpc/RpcGroup.ts"; import * as RpcMessage from "../rpc/RpcMessage.ts"; import * as RpcServer from "../rpc/RpcServer.ts"; import { CallToolResult, CompleteResult, ElicitationDeclined, GetPromptResult, InternalError, InvalidParams, McpServerClient, Prompt, Resource, ResourceTemplate, ServerNotificationRpcs, Tool as McpTool } from "./McpSchema.ts"; import type { CallTool, ClientCapabilities, Complete, GetPrompt, Param, PromptMessage, ReadResourceResult } from "./McpSchema.ts"; import * as Tool from "./Tool.ts"; import type * as Toolkit from "./Toolkit.ts"; declare const McpServer_base: Context.ServiceClass>; readonly notificationsQueue: Queue.Dequeue>; readonly initializedClients: Set; readonly tools: ReadonlyArray<{ readonly tool: McpTool; readonly annotations: Context.Context; }>; readonly addTool: (options: { readonly tool: McpTool; readonly annotations: Context.Context; readonly handle: (payload: any) => Effect.Effect; }) => Effect.Effect; readonly callTool: (requests: typeof CallTool.payloadSchema.Type) => Effect.Effect; readonly resources: ReadonlyArray<{ readonly resource: Resource; readonly annotations: Context.Context; }>; readonly addResource: (options: { readonly resource: Resource; readonly annotations: Context.Context; readonly handle: Effect.Effect; }) => Effect.Effect; readonly resourceTemplates: ReadonlyArray<{ readonly template: ResourceTemplate; readonly annotations: Context.Context; }>; readonly addResourceTemplate: (options: { readonly template: ResourceTemplate; readonly annotations: Context.Context; readonly routerPath: string; readonly completions: Record Effect.Effect>; readonly handle: (uri: string, params: Array) => Effect.Effect; }) => Effect.Effect; readonly findResource: (uri: string) => Effect.Effect; readonly prompts: ReadonlyArray<{ readonly prompt: Prompt; readonly annotations: Context.Context; }>; readonly addPrompt: (options: { readonly prompt: Prompt; readonly annotations: Context.Context; readonly completions: Record Effect.Effect>; readonly handle: (params: Record) => Effect.Effect; }) => Effect.Effect; readonly getPromptResult: (request: typeof GetPrompt.payloadSchema.Type) => Effect.Effect; readonly completion: (complete: typeof Complete.payloadSchema.Type) => Effect.Effect; }>; /** * Service that stores and serves an MCP server's registered tools, resources, * prompts, completions, and outgoing notifications. * * **Details** * * Handlers use this service to register capabilities and resolve incoming MCP * requests. * * @category server * @since 4.0.0 */ export declare class McpServer extends McpServer_base { /** * Builds an MCP server service from registered tools, prompts, resources, and completions. * * @since 4.0.0 */ static readonly make: Effect.Effect<{ readonly notifications: RpcClient.RpcClient>; readonly notificationsQueue: Queue.Dequeue>; readonly initializedClients: Set; readonly tools: ReadonlyArray<{ readonly tool: McpTool; readonly annotations: Context.Context; }>; readonly addTool: (options: { readonly tool: McpTool; readonly annotations: Context.Context; readonly handle: (payload: any) => Effect.Effect; }) => Effect.Effect; readonly callTool: (requests: typeof CallTool.payloadSchema.Type) => Effect.Effect; readonly resources: ReadonlyArray<{ readonly resource: Resource; readonly annotations: Context.Context; }>; readonly addResource: (options: { readonly resource: Resource; readonly annotations: Context.Context; readonly handle: Effect.Effect; }) => Effect.Effect; readonly resourceTemplates: ReadonlyArray<{ readonly template: ResourceTemplate; readonly annotations: Context.Context; }>; readonly addResourceTemplate: (options: { readonly template: ResourceTemplate; readonly annotations: Context.Context; readonly routerPath: string; readonly completions: Record Effect.Effect>; readonly handle: (uri: string, params: Array) => Effect.Effect; }) => Effect.Effect; readonly findResource: (uri: string) => Effect.Effect; readonly prompts: ReadonlyArray<{ readonly prompt: Prompt; readonly annotations: Context.Context; }>; readonly addPrompt: (options: { readonly prompt: Prompt; readonly annotations: Context.Context; readonly completions: Record Effect.Effect>; readonly handle: (params: Record) => Effect.Effect; }) => Effect.Effect; readonly getPromptResult: (request: typeof GetPrompt.payloadSchema.Type) => Effect.Effect; readonly completion: (complete: typeof Complete.payloadSchema.Type) => Effect.Effect; }, never, import("../../Scope.ts").Scope>; /** * Layer that provides the MCP server and client services. * * @since 4.0.0 */ static readonly layer: Layer.Layer; } /** * Runs an MCP server over the current `RpcServer.Protocol`. * * **Details** * * The server performs initialization and session handling, serves registered * tools, resources, and prompts, and forwards queued server notifications to * initialized clients. * * @category constructors * @since 4.0.0 */ export declare const run: (options: { readonly name: string; readonly version: string; readonly extensions?: Record<`${string}/${string}`, unknown> | undefined; }) => Effect.Effect; /** * Creates a layer that starts an MCP server over an existing * `RpcServer.Protocol` and provides the `McpServer` and `McpServerClient` * services. * * **When to use** * * Use when you already have a custom or externally provided * `RpcServer.Protocol` and want to start an MCP server as part of a layer * graph. * * **Details** * * The returned layer forks `run(options)` in the layer scope and merges * `McpServer.layer`, so registration layers can use the `McpServer` service * while the server is running. * * **Gotchas** * * Unlike `layerStdio` and `layerHttp`, this layer does not install a concrete * transport. The surrounding layer graph must provide `RpcServer.Protocol`. * * @see {@link run} for the effect form used by this layer * @see {@link layerStdio} for a stdio-backed layer that installs the MCP protocol and NDJSON-RPC serialization * @see {@link layerHttp} for an HTTP-backed layer that registers with `HttpRouter` and installs JSON-RPC serialization * * @category layers * @since 4.0.0 */ export declare const layer: (options: { readonly name: string; readonly version: string; readonly extensions?: Record<`${string}/${string}`, unknown> | undefined; }) => Layer.Layer; /** * Runs the McpServer, using stdio for input and output. * * **Example** (Running an MCP server over stdio) * * ```ts * import { Effect, Layer, Logger, Schema } from "effect" * import { NodeRuntime, NodeStdio } from "@effect/platform-node" * import { McpSchema, McpServer } from "effect/unstable/ai" * * const idParam = McpSchema.param("id", Schema.Number) * * // Define a resource template for a README file * const ReadmeTemplate = McpServer.resource`file://readme/${idParam}`({ * name: "README Template", * // You can add auto-completion for the ID parameter * completion: { * id: (_) => Effect.succeed([1, 2, 3, 4, 5]) * }, * content: Effect.fn(function*(_uri, id) { * return `# MCP Server Demo - ID: ${id}` * }) * }) * * // Define a test prompt with parameters * const TestPrompt = McpServer.prompt({ * name: "Test Prompt", * description: "A test prompt to demonstrate MCP server capabilities", * parameters: { * flightNumber: Schema.String * }, * completion: { * flightNumber: () => Effect.succeed(["FL123", "FL456", "FL789"]) * }, * content: ({ flightNumber }) => * Effect.succeed(`Get the booking details for flight number: ${flightNumber}`) * }) * * // Merge all the resources and prompts into a single server layer * const ServerLayer = Layer.mergeAll( * ReadmeTemplate, * TestPrompt * ).pipe( * // Provide the MCP server implementation * Layer.provide(McpServer.layerStdio({ * name: "Demo Server", * version: "1.0.0", * })), * Layer.provide(NodeStdio.layer), * Layer.provide(Layer.succeed(Logger.LogToStderr)(true)) * ) * * Layer.launch(ServerLayer).pipe(NodeRuntime.runMain) * ``` * * @category layers * @since 4.0.0 */ export declare const layerStdio: (options: { readonly name: string; readonly version: string; readonly extensions?: Record<`${string}/${string}`, unknown> | undefined; }) => Layer.Layer; /** * Registers an HTTP POST JSON-RPC route at `options.path` on the current * `HttpRouter`. * * **When to use** * * Use to expose an MCP server through an existing `HttpRouter`. * * **Details** * * This layer composes `layer(options)`, `RpcServer.layerProtocolHttp(options)`, * and `RpcSerialization.layerJsonRpc()`. * * @see {@link layerStdio} for exposing the server over stdio * @see {@link layer} for the base MCP server layer without a transport protocol * * @category layers * @since 4.0.0 */ export declare const layerHttp: (options: { readonly name: string; readonly version: string; readonly path: HttpRouter.PathInput; readonly extensions?: Record<`${string}/${string}`, unknown> | undefined; }) => Layer.Layer; /** * Registers a `Toolkit` with the `McpServer`. * * @category tools * @since 4.0.0 */ export declare const registerToolkit: >(toolkit: Toolkit.Toolkit) => Effect.Effect | Exclude, McpServerClient>>; /** * Registers an `AiToolkit` with the `McpServer`. * * @category tools * @since 4.0.0 */ export declare const toolkit: >(toolkit: Toolkit.Toolkit) => Layer.Layer | Exclude, McpServerClient>>; /** * Utility type that validates a completion-handler record against the allowed * parameter keys. * * @category utility types * @since 4.0.0 */ export type ValidateCompletions = Completions & { readonly [K in keyof Completions]: K extends Keys ? (input: string) => any : never; }; /** * Completion-handler map for a resource URI template. * * **Details** * * Each schema interpolation contributes a parameter key, using an explicit * `Param` name when present or `paramN` otherwise, and each handler returns * candidate values for that parameter. * * @category models * @since 4.0.0 */ export type ResourceCompletions> = { readonly [K in Extract as Schemas[K] extends Param ? Id : `param${K}`]: (input: string) => Effect.Effect, any, any>; }; /** * Registers an MCP resource or resource template from an Effect program. * * **When to use** * * Use when you are already inside an Effect program with an `McpServer` * service and need to add a concrete resource or URI-template resource * directly. * * @see {@link resource} for the layer-based resource registration wrapper * * @category resources * @since 4.0.0 */ export declare const registerResource: { /** * Registers an MCP resource or resource template from an Effect program. * * **When to use** * * Use when you are already inside an Effect program with an `McpServer` * service and need to add a concrete resource or URI-template resource * directly. * * @see {@link resource} for the layer-based resource registration wrapper * * @category resources * @since 4.0.0 */ (options: { readonly uri: string; readonly name: string; readonly description?: string | undefined; readonly mimeType?: string | undefined; readonly audience?: ReadonlyArray<"user" | "assistant"> | undefined; readonly priority?: number | undefined; readonly content: Effect.Effect; readonly annotations?: Context.Context | undefined; }): Effect.Effect | McpServer>; /** * Registers an MCP resource or resource template from an Effect program. * * **When to use** * * Use when you are already inside an Effect program with an `McpServer` * service and need to add a concrete resource or URI-template resource * directly. * * @see {@link resource} for the layer-based resource registration wrapper * * @category resources * @since 4.0.0 */ >(segments: TemplateStringsArray, ...schemas: Schemas): > = {}>(options: { readonly name: string; readonly description?: string | undefined; readonly mimeType?: string | undefined; readonly audience?: ReadonlyArray<"user" | "assistant"> | undefined; readonly priority?: number | undefined; readonly completion?: ValidateCompletions> | undefined; readonly content: (uri: string, ...params: { readonly [K in keyof Schemas]: Schemas[K]["Type"]; }) => Effect.Effect; readonly annotations?: Context.Context | undefined; }) => Effect.Effect infer Ret ? Ret extends Effect.Effect ? _R : never : never), McpServerClient> | McpServer>; }; /** * Creates a layer that registers an MCP resource or resource template. * * **When to use** * * Use to compose resource registration into an MCP server layer. * * @see {@link registerResource} for the Effect-level resource registration API * * @category resources * @since 4.0.0 */ export declare const resource: { /** * Creates a layer that registers an MCP resource or resource template. * * **When to use** * * Use to compose resource registration into an MCP server layer. * * @see {@link registerResource} for the Effect-level resource registration API * * @category resources * @since 4.0.0 */ (options: { readonly uri: string; readonly name: string; readonly description?: string | undefined; readonly mimeType?: string | undefined; readonly audience?: ReadonlyArray<"user" | "assistant"> | undefined; readonly priority?: number | undefined; readonly content: Effect.Effect; }): Layer.Layer>; /** * Creates a layer that registers an MCP resource or resource template. * * **When to use** * * Use to compose resource registration into an MCP server layer. * * @see {@link registerResource} for the Effect-level resource registration API * * @category resources * @since 4.0.0 */ >(segments: TemplateStringsArray, ...schemas: Schemas): > = {}>(options: { readonly name: string; readonly description?: string | undefined; readonly mimeType?: string | undefined; readonly audience?: ReadonlyArray<"user" | "assistant"> | undefined; readonly priority?: number | undefined; readonly completion?: ValidateCompletions> | undefined; readonly content: (uri: string, ...params: { readonly [K in keyof Schemas]: Schemas[K]["Type"]; }) => Effect.Effect; }) => Layer.Layer infer Ret ? Ret extends Effect.Effect ? _R : never : never), McpServerClient>>; }; /** * Registers an MCP prompt from an Effect program. * * **When to use** * * Use when you are already inside an Effect program with an `McpServer` * service and need to add a prompt handler directly. * * **Details** * * Parameters are decoded with the supplied schema, completion handlers encode * per-parameter suggestions, and string prompt content is converted into a user * text message. * * @see {@link prompt} for the layer-based prompt registration wrapper * * @category prompts * @since 4.0.0 */ export declare const registerPrompt: Effect.Effect, any, any>; } = {}>(options: { readonly name: string; readonly description?: string | undefined; readonly parameters?: Params | undefined; readonly completion?: ValidateCompletions> | undefined; readonly content: (params: Params) => Effect.Effect | string, E, R>; readonly annotations?: Context.Context | undefined; }) => Effect.Effect | R, McpServerClient> | McpServer>; /** * Creates a layer that registers an MCP prompt. * * **When to use** * * Use to compose prompt registration into an MCP server layer. * * **Details** * * Parameters are decoded with the supplied schema, completion handlers encode * per-parameter suggestions, and string prompt content is converted into a user * text message. * * @see {@link registerPrompt} for the Effect-level prompt registration API * * @category prompts * @since 4.0.0 */ export declare const prompt: Effect.Effect, any, any>; } = {}>(options: { readonly name: string; readonly description?: string | undefined; readonly parameters?: Params | undefined; readonly completion?: ValidateCompletions> | undefined; readonly content: (params: Schema.Struct.Type) => Effect.Effect | string, E, R>; readonly annotations?: Context.Context | undefined; }) => Layer.Layer | R, McpServerClient>>; /** * Collects structured input from the current MCP client and decodes the * accepted response with `schema`. * * **Details** * * Accepted content is decoded with the supplied schema, declined requests fail * with `ElicitationDeclined`, and canceled requests interrupt the effect. * * @category elicitation * @since 4.0.0 */ export declare const elicit: , unknown>>(options: { readonly message: string; readonly schema: S; }) => Effect.Effect; /** * Accesses the current client's capabilities. * * @category capabilities * @since 4.0.0 */ export declare const clientCapabilities: Effect.Effect; export {}; //# sourceMappingURL=McpServer.d.ts.map