EdgeAIG's picture
download
raw
22.5 kB
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<McpServer, "effect/ai/McpServer", {
readonly notifications: RpcClient.RpcClient<RpcGroup.Rpcs<typeof ServerNotificationRpcs>>;
readonly notificationsQueue: Queue.Dequeue<RpcMessage.Request<any>>;
readonly initializedClients: Set<number>;
readonly tools: ReadonlyArray<{
readonly tool: McpTool;
readonly annotations: Context.Context<never>;
}>;
readonly addTool: (options: {
readonly tool: McpTool;
readonly annotations: Context.Context<never>;
readonly handle: (payload: any) => Effect.Effect<CallToolResult, never, McpServerClient>;
}) => Effect.Effect<void>;
readonly callTool: (requests: typeof CallTool.payloadSchema.Type) => Effect.Effect<CallToolResult, InternalError | InvalidParams, McpServerClient>;
readonly resources: ReadonlyArray<{
readonly resource: Resource;
readonly annotations: Context.Context<never>;
}>;
readonly addResource: (options: {
readonly resource: Resource;
readonly annotations: Context.Context<never>;
readonly handle: Effect.Effect<typeof ReadResourceResult.Type, InternalError, McpServerClient>;
}) => Effect.Effect<void>;
readonly resourceTemplates: ReadonlyArray<{
readonly template: ResourceTemplate;
readonly annotations: Context.Context<never>;
}>;
readonly addResourceTemplate: (options: {
readonly template: ResourceTemplate;
readonly annotations: Context.Context<never>;
readonly routerPath: string;
readonly completions: Record<string, (input: string) => Effect.Effect<CompleteResult, InternalError>>;
readonly handle: (uri: string, params: Array<string>) => Effect.Effect<typeof ReadResourceResult.Type, InvalidParams | InternalError, McpServerClient>;
}) => Effect.Effect<void>;
readonly findResource: (uri: string) => Effect.Effect<typeof ReadResourceResult.Type, InvalidParams | InternalError, McpServerClient>;
readonly prompts: ReadonlyArray<{
readonly prompt: Prompt;
readonly annotations: Context.Context<never>;
}>;
readonly addPrompt: (options: {
readonly prompt: Prompt;
readonly annotations: Context.Context<never>;
readonly completions: Record<string, (input: string) => Effect.Effect<CompleteResult, InternalError, McpServerClient>>;
readonly handle: (params: Record<string, string>) => Effect.Effect<GetPromptResult, InternalError | InvalidParams, McpServerClient>;
}) => Effect.Effect<void>;
readonly getPromptResult: (request: typeof GetPrompt.payloadSchema.Type) => Effect.Effect<GetPromptResult, InternalError | InvalidParams, McpServerClient>;
readonly completion: (complete: typeof Complete.payloadSchema.Type) => Effect.Effect<CompleteResult, InternalError, McpServerClient>;
}>;
/**
* 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<RpcGroup.Rpcs<typeof ServerNotificationRpcs>>;
readonly notificationsQueue: Queue.Dequeue<RpcMessage.Request<any>>;
readonly initializedClients: Set<number>;
readonly tools: ReadonlyArray<{
readonly tool: McpTool;
readonly annotations: Context.Context<never>;
}>;
readonly addTool: (options: {
readonly tool: McpTool;
readonly annotations: Context.Context<never>;
readonly handle: (payload: any) => Effect.Effect<CallToolResult, never, McpServerClient>;
}) => Effect.Effect<void>;
readonly callTool: (requests: typeof CallTool.payloadSchema.Type) => Effect.Effect<CallToolResult, InternalError | InvalidParams, McpServerClient>;
readonly resources: ReadonlyArray<{
readonly resource: Resource;
readonly annotations: Context.Context<never>;
}>;
readonly addResource: (options: {
readonly resource: Resource;
readonly annotations: Context.Context<never>;
readonly handle: Effect.Effect<typeof ReadResourceResult.Type, InternalError, McpServerClient>;
}) => Effect.Effect<void>;
readonly resourceTemplates: ReadonlyArray<{
readonly template: ResourceTemplate;
readonly annotations: Context.Context<never>;
}>;
readonly addResourceTemplate: (options: {
readonly template: ResourceTemplate;
readonly annotations: Context.Context<never>;
readonly routerPath: string;
readonly completions: Record<string, (input: string) => Effect.Effect<CompleteResult, InternalError>>;
readonly handle: (uri: string, params: Array<string>) => Effect.Effect<typeof ReadResourceResult.Type, InvalidParams | InternalError, McpServerClient>;
}) => Effect.Effect<void>;
readonly findResource: (uri: string) => Effect.Effect<typeof ReadResourceResult.Type, InvalidParams | InternalError, McpServerClient>;
readonly prompts: ReadonlyArray<{
readonly prompt: Prompt;
readonly annotations: Context.Context<never>;
}>;
readonly addPrompt: (options: {
readonly prompt: Prompt;
readonly annotations: Context.Context<never>;
readonly completions: Record<string, (input: string) => Effect.Effect<CompleteResult, InternalError, McpServerClient>>;
readonly handle: (params: Record<string, string>) => Effect.Effect<GetPromptResult, InternalError | InvalidParams, McpServerClient>;
}) => Effect.Effect<void>;
readonly getPromptResult: (request: typeof GetPrompt.payloadSchema.Type) => Effect.Effect<GetPromptResult, InternalError | InvalidParams, McpServerClient>;
readonly completion: (complete: typeof Complete.payloadSchema.Type) => Effect.Effect<CompleteResult, InternalError, McpServerClient>;
}, never, import("../../Scope.ts").Scope>;
/**
* Layer that provides the MCP server and client services.
*
* @since 4.0.0
*/
static readonly layer: Layer.Layer<McpServer | McpServerClient>;
}
/**
* 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<never, never, McpServer | RpcServer.Protocol>;
/**
* 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<McpServer | McpServerClient, never, RpcServer.Protocol>;
/**
* 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<McpServer | McpServerClient, never, Stdio>;
/**
* 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<McpServer | McpServerClient, never, HttpRouter.HttpRouter>;
/**
* Registers a `Toolkit` with the `McpServer`.
*
* @category tools
* @since 4.0.0
*/
export declare const registerToolkit: <Tools extends Record<string, Tool.Any>>(toolkit: Toolkit.Toolkit<Tools>) => Effect.Effect<void, never, McpServer | Tool.HandlersFor<Tools> | Exclude<Tool.HandlerServices<Tools>, McpServerClient>>;
/**
* Registers an `AiToolkit` with the `McpServer`.
*
* @category tools
* @since 4.0.0
*/
export declare const toolkit: <Tools extends Record<string, Tool.Any>>(toolkit: Toolkit.Toolkit<Tools>) => Layer.Layer<never, never, Tool.HandlersFor<Tools> | Exclude<Tool.HandlerServices<Tools>, 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, Keys extends string> = 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<Schemas extends ReadonlyArray<Schema.Top>> = {
readonly [K in Extract<keyof Schemas, `${number}`> as Schemas[K] extends Param<infer Id, infer _S> ? Id : `param${K}`]: (input: string) => Effect.Effect<Array<Schemas[K]["Type"]>, 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
*/
<E, R>(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<typeof ReadResourceResult.Type | string | Uint8Array, E, R>;
readonly annotations?: Context.Context<never> | undefined;
}): Effect.Effect<void, never, Exclude<R, McpServerClient> | 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
*/
<const Schemas extends ReadonlyArray<Schema.Top>>(segments: TemplateStringsArray, ...schemas: Schemas): <E, R, const Completions extends Partial<ResourceCompletions<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<Completions, keyof ResourceCompletions<Schemas>> | undefined;
readonly content: (uri: string, ...params: {
readonly [K in keyof Schemas]: Schemas[K]["Type"];
}) => Effect.Effect<typeof ReadResourceResult.Type | string | Uint8Array, E, R>;
readonly annotations?: Context.Context<never> | undefined;
}) => Effect.Effect<void, never, Exclude<Schemas[number]["DecodingServices"] | Schemas[number]["EncodingServices"] | R | (Completions[keyof Completions] extends (input: string) => infer Ret ? Ret extends Effect.Effect<infer _A, infer _E, infer _R> ? _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
*/
<E, R>(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<typeof ReadResourceResult.Type | string | Uint8Array, E, R>;
}): Layer.Layer<never, never, Exclude<R, McpServerClient>>;
/**
* 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
*/
<const Schemas extends ReadonlyArray<Schema.Top>>(segments: TemplateStringsArray, ...schemas: Schemas): <E, R, const Completions extends Partial<ResourceCompletions<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<Completions, keyof ResourceCompletions<Schemas>> | undefined;
readonly content: (uri: string, ...params: {
readonly [K in keyof Schemas]: Schemas[K]["Type"];
}) => Effect.Effect<typeof ReadResourceResult.Type | string | Uint8Array, E, R>;
}) => Layer.Layer<never, never, Exclude<R | (Completions[keyof Completions] extends (input: string) => infer Ret ? Ret extends Effect.Effect<infer _A, infer _E, infer _R> ? _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: <E, R, Params extends Schema.Struct.Fields = {}, const Completions extends { readonly [K in keyof Params]?: (input: string) => Effect.Effect<Array<Params[K]>, any, any>; } = {}>(options: {
readonly name: string;
readonly description?: string | undefined;
readonly parameters?: Params | undefined;
readonly completion?: ValidateCompletions<Completions, Extract<keyof Params, string>> | undefined;
readonly content: (params: Params) => Effect.Effect<Array<typeof PromptMessage.Type> | string, E, R>;
readonly annotations?: Context.Context<never> | undefined;
}) => Effect.Effect<void, never, Exclude<Schema.Struct.DecodingServices<Params> | 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: <E, R, Params extends Schema.Struct.Fields = {}, const Completions extends { readonly [K in keyof Params]?: (input: string) => Effect.Effect<Array<Params[K]["Type"]>, any, any>; } = {}>(options: {
readonly name: string;
readonly description?: string | undefined;
readonly parameters?: Params | undefined;
readonly completion?: ValidateCompletions<Completions, Extract<keyof Params, string>> | undefined;
readonly content: (params: Schema.Struct.Type<Params>) => Effect.Effect<Array<typeof PromptMessage.Type> | string, E, R>;
readonly annotations?: Context.Context<never> | undefined;
}) => Layer.Layer<never, never, Exclude<Schema.Struct.DecodingServices<Params> | 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: <S extends Schema.Encoder<Record<string, unknown>, unknown>>(options: {
readonly message: string;
readonly schema: S;
}) => Effect.Effect<S["Type"], ElicitationDeclined, McpServerClient | S["DecodingServices"]>;
/**
* Accesses the current client's capabilities.
*
* @category capabilities
* @since 4.0.0
*/
export declare const clientCapabilities: Effect.Effect<ClientCapabilities, never, McpServerClient>;
export {};
//# sourceMappingURL=McpServer.d.ts.map

Xet Storage Details

Size:
22.5 kB
·
Xet hash:
8c86fd0d53760ab1a328b2af8ae73a404c960bb3c6231ae7fa27f5024399a597

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.