/** * Connects to MCP servers with scoped Effect clients. * * Clients discover tools, prompts and resources using the protocol revision selected by * their transport. `callTool` returns tool-reported errors as results; supplying a schema * turns them into a `ToolError` reason that retains the original result. Transport and * protocol failures fail the Effect. Interactive server requests, subscriptions, OAuth * and retries are not included. * * @stability experimental * @since 4.0.6 */ import * as ByteSize from "../ByteSize.ts"; import * as Context from "../Context.ts"; import * as Duration from "../Duration.ts"; import * as Effect from "../Effect.ts"; import * as HttpClient from "../http/HttpClient.ts"; import * as Layer from "../Layer.ts"; import type * as ChildProcess from "../process/ChildProcess.ts"; import { ChildProcessSpawner } from "../process/ChildProcessSpawner.ts"; import * as Schema from "../Schema.ts"; import type * as Scope from "../Scope.ts"; import { McpClientError } from "./McpClientError.ts"; import type * as McpProtocol from "./McpProtocol.ts"; import * as McpSchema from "./McpSchema.ts"; import * as Tool from "./Tool.ts"; import * as Toolkit from "./Toolkit.ts"; /** * Supported MCP wire protocol revisions. * * @stability experimental * @category models * @since 4.0.6 */ export type ProtocolVersion = "2025-11-25" | "2026-07-28"; /** * Service tag for applications that provide one default MCP connection. * * @stability experimental * @category services * @since 4.0.6 */ export declare const McpClient: Context.Service; /** * A scoped connection to one MCP server. * * @stability experimental * @category models * @since 4.0.6 */ export interface McpClient { readonly [TypeId]: typeof TypeId; readonly protocolVersion: ProtocolVersion; readonly serverInfo: McpSchema.Implementation | undefined; readonly instructions?: string | undefined; /** * Returns every tool page as one snapshot, bounded by the deadline, 100 pages and 10,000 tools. * `timeout` overrides the client's discovery deadline. */ readonly listTools: (options?: { readonly timeout?: Duration.Input | undefined; }) => Effect.Effect, McpClientError>; /** Returns every prompt page as one snapshot with the same bounds as `listTools`. */ readonly listPrompts: (options?: { readonly timeout?: Duration.Input | undefined; }) => Effect.Effect, McpClientError>; /** Gets the messages for a discovered prompt. Unbounded unless `timeout` is supplied. */ readonly getPrompt: (params: { readonly prompt: McpSchema.Prompt; readonly arguments?: typeof McpSchema.GetPrompt.payloadSchema.Type["arguments"]; }, options?: { readonly timeout?: Duration.Input | undefined; }) => Effect.Effect; /** Returns every resource page as one snapshot with the same bounds as `listTools`. */ readonly listResources: (options?: { readonly timeout?: Duration.Input | undefined; }) => Effect.Effect, McpClientError>; /** Reads the complete contents of a resource URI. Unbounded unless `timeout` is supplied. */ readonly readResource: (params: { readonly uri: string; }, options?: { readonly timeout?: Duration.Input | undefined; }) => Effect.Effect; /** * Calls a discovered tool, optionally decoding with a schema. Errors retain the full result. * Unbounded unless `timeout` is supplied. */ readonly callTool: { (params: { readonly tool: McpSchema.Tool; readonly schema?: undefined; readonly arguments?: typeof McpSchema.CallTool.payloadSchema.Type["arguments"]; }, options?: { readonly timeout?: Duration.Input | undefined; }): Effect.Effect; (params: { readonly tool: McpSchema.Tool; readonly schema: S; readonly arguments?: typeof McpSchema.CallTool.payloadSchema.Type["arguments"]; }, options?: { readonly timeout?: Duration.Input | undefined; }): Effect.Effect; (params: { readonly tool: McpSchema.Tool; readonly schema?: S | undefined; readonly arguments?: typeof McpSchema.CallTool.payloadSchema.Type["arguments"]; }, options?: { readonly timeout?: Duration.Input | undefined; }): Effect.Effect; }; } /** * Returns whether a value is an MCP client. * * @stability experimental * @category guards * @since 4.0.6 */ export declare const isMcpClient: (value: unknown) => value is McpClient; /** * Constructs and connects a client using the supplied MCP transport service and its protocol adapter. * * **Details** * * `name`, `version` and the optional `title`, `description`, `websiteUrl` and * `icons` identify the client to the server. `timeout` defaults to 60 seconds * and bounds initialization and each complete `listTools`, `listPrompts` or * `listResources` scan. `callTool`, `getPrompt` and `readResource` have no * deadline unless their own `timeout` option is supplied. * Schema decoding requires the schema's services from the caller. * * @stability experimental * @category constructors * @since 4.0.6 */ export declare const make: (options: { readonly name: string; readonly version: string; readonly title?: string | undefined; readonly description?: string | undefined; readonly websiteUrl?: string | undefined; readonly icons?: ReadonlyArray | undefined; readonly timeout?: Duration.Input | undefined; }) => Effect.Effect; /** * Discovers remote tools and binds their handlers using the standard Toolkit implementation. * * **Details** * * Pass an optional prefix such as `"reports__"` to qualify model tool names. * Remote JSON Schemas are advertised without local schema import. Results become * text; tool-reported and operational failures fail the Effect. Use `Tool.make` * or `Tool.dynamic` with `Toolkit.make` for custom validation, approval or results. * Build a new toolkit to discover changes between model turns. * * @stability experimental * @category constructors * @since 4.0.6 */ export declare const toolkit: (client: McpClient, prefix?: string) => Effect.Effect>>, McpClientError>; /** * Service supplied by the built-in MCP transport constructors and layers. * * **Details** * * Transport construction owns cleanup through its Effect scope. * * @stability experimental * @category services * @since 4.0.6 */ export declare const Transport: Context.Service; /** * Exchanges JSON-RPC messages with one MCP server using its protocol adapter. * * @stability experimental * @category models * @since 4.0.6 */ export interface Transport { readonly [TransportTypeId]: typeof TransportTypeId; readonly protocol: McpProtocol.ProtocolAdapter; /** Sends a request and waits for its response. `tool` supplies header routing for tool calls. */ readonly request: (message: McpSchema.JsonRpcRequest, tool?: McpSchema.Tool) => Effect.Effect; /** Sends a notification without waiting for a reply. */ readonly notify: (message: McpSchema.JsonRpcNotification) => Effect.Effect; /** Returns whether the transport can route a call to the tool. */ readonly isCallable: (tool: McpSchema.Tool) => boolean; } /** * Starts a scoped subprocess using newline-delimited JSON-RPC. * * @stability experimental * @category constructors * @since 4.0.6 */ export declare const stdio: (options: { readonly command: ChildProcess.Command; readonly protocol: McpProtocol.ProtocolAdapter; readonly maxMessageBytes?: ByteSize.Input | undefined; }) => Effect.Effect; /** * Provides a connected MCP client over stdio using the child process spawner. * * **Details** * * The layer scope owns the client and subprocess. The options are those of * {@link make} and {@link stdio}. * * @see {@link layerHttp} * @stability experimental * @category layers * @since 4.0.6 */ export declare const layerStdio: (options: { readonly name: string; readonly version: string; readonly title?: string | undefined; readonly description?: string | undefined; readonly websiteUrl?: string | undefined; readonly icons?: ReadonlyArray | undefined; readonly timeout?: Duration.Input | undefined; readonly command: ChildProcess.Command; readonly protocol: McpProtocol.ProtocolAdapter; readonly maxMessageBytes?: ByteSize.Input | undefined; }) => Layer.Layer; /** * Creates a Streamable HTTP transport with request-owned JSON or SSE responses. * * @stability experimental * @category constructors * @since 4.0.6 */ export declare const http: (options: { readonly url: string | URL; readonly protocol: McpProtocol.ProtocolAdapter; readonly headers?: Readonly> | undefined; readonly maxMessageBytes?: ByteSize.Input | undefined; }) => Effect.Effect; /** * Provides a connected MCP client over Streamable HTTP using the HTTP client. * * **Details** * * The layer scope owns the client and connection. The options are those of * {@link make} and {@link http}. * * **Example** (Providing an HTTP client connection) * * ```ts import.meta.vitest * import { Layer } from "effect" * import { McpClient, McpProtocol } from "effect/ai" * import { FetchHttpClient } from "effect/http" * * const ClientLayer = McpClient.layerHttp({ * name: "report-workflow", * version: "1.0.0", * protocol: McpProtocol.v2026_07_28, * url: "http://localhost:3000/mcp" * }).pipe(Layer.provide(FetchHttpClient.layer)) * ``` * * @see {@link layerStdio} * @stability experimental * @category layers * @since 4.0.6 */ export declare const layerHttp: (options: { readonly name: string; readonly version: string; readonly title?: string | undefined; readonly description?: string | undefined; readonly websiteUrl?: string | undefined; readonly icons?: ReadonlyArray | undefined; readonly timeout?: Duration.Input | undefined; readonly url: string | URL; readonly protocol: McpProtocol.ProtocolAdapter; readonly headers?: Readonly> | undefined; readonly maxMessageBytes?: ByteSize.Input | undefined; }) => Layer.Layer; declare const TypeId: "~effect/ai/McpClient"; declare const TransportTypeId: "~effect/ai/McpClient/Transport"; export {}; //# sourceMappingURL=McpClient.d.ts.map