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; }>; /** * @since 4.0.0 * @category server */ export declare class McpServer extends McpServer_base { /** * @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>; /** * @since 4.0.0 */ static readonly layer: Layer.Layer; } /** * @since 4.0.0 * @category constructors */ export declare const run: (options: { readonly name: string; readonly version: string; readonly extensions?: Record<`${string}/${string}`, unknown> | undefined; }) => Effect.Effect; /** * @since 4.0.0 * @category layers */ export declare const layer: (options: { readonly name: string; readonly version: string; readonly extensions?: Record<`${string}/${string}`, unknown> | undefined; }) => Layer.Layer; /** * Run the McpServer, using stdio for input and output. * * @example * ```ts * import { NodeRuntime, NodeStdio } from "@effect/platform-node" * import { Effect, Layer, Logger, Schema } from "effect" * 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) * ``` * * @since 4.0.0 * @category layers */ export declare const layerStdio: (options: { readonly name: string; readonly version: string; readonly extensions?: Record<`${string}/${string}`, unknown> | undefined; }) => Layer.Layer; /** * Run the `McpServer`, registering a router with a `HttpRouter` * * @since 4.0.0 * @category layers */ export declare const layerHttp: (options: { readonly name: string; readonly version: string; readonly path: HttpRouter.PathInput; readonly extensions?: Record<`${string}/${string}`, unknown> | undefined; }) => Layer.Layer; /** * Register a `Toolkit` with the `McpServer`. * * @since 4.0.0 * @category tools */ export declare const registerToolkit: >(toolkit: Toolkit.Toolkit) => Effect.Effect | Exclude, McpServerClient>>; /** * Register an AiToolkit with the McpServer. * * @since 4.0.0 * @category tools */ export declare const toolkit: >(toolkit: Toolkit.Toolkit) => Layer.Layer | Exclude, McpServerClient>>; /** * @since 4.0.0 */ export type ValidateCompletions = Completions & { readonly [K in keyof Completions]: K extends Keys ? (input: string) => any : never; }; /** * @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>; }; /** * Register a resource with the McpServer. * * @since 4.0.0 * @category resources */ export declare const registerResource: { /** * Register a resource with the McpServer. * * @since 4.0.0 * @category resources */ (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>; /** * Register a resource with the McpServer. * * @since 4.0.0 * @category resources */ >(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>; }; /** * Register a resource with the McpServer. * * @since 4.0.0 * @category resources */ export declare const resource: { /** * Register a resource with the McpServer. * * @since 4.0.0 * @category resources */ (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>; /** * Register a resource with the McpServer. * * @since 4.0.0 * @category resources */ >(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>>; }; /** * Register a prompt with the McpServer. * * @since 4.0.0 * @category prompts */ 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>; /** * Register a prompt with the McpServer. * * @since 4.0.0 * @category prompts */ 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>>; /** * Create an elicitation request * * @since 4.0.0 * @category elicitation */ export declare const elicit: , unknown>>(options: { readonly message: string; readonly schema: S; }) => Effect.Effect; /** * Access the current client's capabilities. * * @since 4.0.0 * @category capabilities */ export declare const clientCapabilities: Effect.Effect; export {}; //# sourceMappingURL=McpServer.d.ts.map