Skip to content

feat: add native McpClient - #8862

Merged
tim-smart merged 30 commits into
Effect-TS:mainfrom
lloydrichards:feat/mcp-client
Oct 22, 2026
Merged

tim-smart merged 30 commits into
Effect-TS:mainfrom
lloydrichards:feat/mcp-client

Conversation

@lloydrichards

@lloydrichards lloydrichards commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Type

  • Feature

Description

Add an experimental, Effect-native McpClient (with failures in the new McpClientError module) so applications can use remote MCP tools, prompts, and resources through Effect schemas, services, and scopes. This first reasonably simple implementation includes stdio and Streamable HTTP, explicit 2025-11-25 and 2026-07-28 adapters, bounded discovery, direct calls, and Toolkit integration. The broader issue remains open for follow-ups.

Applications can call tools directly or expose discovered tools to a model through the existing Tool and Toolkit APIs. Prompts and resources reuse the McpSchema types already used by McpServer and would need to be consumed as part of the Prompt.Prompt API.

The main layers are the setting up the McpClient.layer which configures the client and the McpClient.layerHttp which configure the transport:

import { Effect, Layer, Schema } from "effect"
import { LanguageModel, McpClient, McpProtocol } from "effect/ai"
import { FetchHttpClient } from "effect/http"

// Provide a .layerStdio or .layerHttp depending on the transport type
const ClientLayer = McpClient.layerHttp({
  name: "calculator-app",
  version: "1.0.0",
  url: "http://localhost:3000/mcp",
  protocol: McpProtocol.v2026_07_28
}).pipe(
  Layer.provide(FetchHttpClient.layer)
)

For example, a server exposing the calculator tool, a prompt, and a resource:

//       ┏━ Effect.Effect<{...}, McpClientError.McpClientError, never>
const workflow = Effect.gen(function*() {
  const client = yield* McpClient.McpClient
  //      ┏━ ReadonlyArray<McpSchema.Tool>
  const tools = yield* client.listTools()
  //       ┏━ ReadonlyArray<McpSchema.Prompt>
  const prompts = yield* client.listPrompts()
  //       ┏━ ReadonlyArray<McpSchema.Resource>
  const resources = yield* client.listResources()
  const tool = tools.find((tool) => tool.name === "add")
  const prompt = prompts.find((prompt) => prompt.name === "explain_sum")
  const resource = resources.find((resource) => resource.uri === "demo://calculator/guide")
  if (tool === undefined || prompt === undefined || resource === undefined) {
    return yield* Effect.die("The server must expose the example descriptors")
  }

  //     ┏━ McpSchema.CallToolResult
  const raw = yield* client.callTool({
    tool,
    arguments: { a: 20, b: 22 }
  })

  //       ┏━ { readonly total: number }
  const decoded = yield* client.callTool({
    tool,
    arguments: { a: 20, b: 22 },
    schema: Schema.Struct({ total: Schema.Number })
  }, { timeout: "2 seconds" })

  //       ┏━ McpSchema.GetPromptResult
  const messages = yield* client.getPrompt({
    prompt,
    arguments: { total: String(decoded.total) }
  })

  //       ┏━ McpSchema.ReadResourceResult
  const contents = yield* client.readResource({ uri: resource.uri })
  return { raw, decoded, messages, contents }
}).pipe(Effect.provide(ClientLayer))

Raw tool calls retain content, structured output, metadata, and isError. Supplying a schema decodes structured output and turns tool-reported errors into ToolError, retaining the original result. A possibly absent schema produces a union of the decoded value and full result.

Each list returns a complete snapshot within one deadline (60 seconds by default, configurable with timeout), capped at 100 pages and 10,000 entries. Tool calls, prompts and resource reads have no deadline unless the operation's timeout option is supplied.

With a LanguageModel provided:

//       ┏━ Effect.Effect<Array<Response.ToolResultPart<string>>, AiError.AiError | McpClientError.McpClientError, LanguageModel.LanguageModel>
const modelWorkflow = Effect.gen(function*() {
  const client = yield* McpClient.McpClient
  const toolkit = yield* McpClient.toolkit(client, "calculator__")

  const response = yield* LanguageModel.generateText({
    prompt: "Use calculator__add to calculate 20 + 22.",
    toolkit,
    toolChoice: "required"
  })

  return response.toolResults
}).pipe(Effect.provide(ClientLayer))

The adapter supplies discovered input schemas and bound handlers to the standard Toolkit. Its MVP output is text; rich binary model output needs application conversion.

Related

@changeset-bot

changeset-bot Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ff70459

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 33 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-cloudflare Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/ai-typesafe Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/graphql-generator Patch
@effect/openapi-generator Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@effect-janitor effect-janitor Bot added the 4.0 label Oct 6, 2026
@lloydrichards lloydrichards changed the title feat: add native mcp client feat: add native McpClient Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.13 KB 39.13 KB 0.00 KB (0.00%)
basic.ts 7.04 KB 7.04 KB 0.00 KB (0.00%)
batching.ts 10.91 KB 10.91 KB 0.00 KB (0.00%)
brand.ts 6.71 KB 6.71 KB 0.00 KB (0.00%)
cache.ts 11.35 KB 11.35 KB 0.00 KB (0.00%)
config.ts 22.51 KB 22.51 KB 0.00 KB (0.00%)
differ.ts 21.66 KB 21.66 KB 0.00 KB (0.00%)
http-client.ts 26.06 KB 26.06 KB 0.00 KB (0.00%)
http-router.ts 35.72 KB 35.72 KB 0.00 KB (0.00%)
logger.ts 11.72 KB 11.72 KB 0.00 KB (0.00%)
metric.ts 9.27 KB 9.27 KB 0.00 KB (0.00%)
optic.ts 6.93 KB 6.93 KB 0.00 KB (0.00%)
pubsub.ts 15.78 KB 15.78 KB 0.00 KB (0.00%)
queue.ts 12.60 KB 12.60 KB 0.00 KB (0.00%)
schedule.ts 11.60 KB 11.60 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 13.84 KB 13.84 KB 0.00 KB (0.00%)
schema-binary.ts 40.57 KB 40.57 KB 0.00 KB (0.00%)
schema-class.ts 21.36 KB 21.36 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 32.34 KB 32.34 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 27.54 KB 27.54 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.09 KB 15.09 KB 0.00 KB (0.00%)
schema-string.ts 12.10 KB 12.10 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.02 KB 16.02 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 38.65 KB 38.65 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 25.75 KB 25.75 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 20.60 KB 20.60 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 20.77 KB 20.77 KB 0.00 KB (0.00%)
schema-toFormatter.ts 20.88 KB 20.88 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 25.47 KB 25.47 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 20.87 KB 20.87 KB 0.00 KB (0.00%)
schema.ts 20.54 KB 20.54 KB 0.00 KB (0.00%)
stm.ts 13.91 KB 13.91 KB 0.00 KB (0.00%)
stream.ts 10.15 KB 10.15 KB 0.00 KB (0.00%)

@lloydrichards
lloydrichards force-pushed the feat/mcp-client branch 2 times, most recently from 02d1720 to 0ece300 Compare October 8, 2026 15:23
Comment thread packages/effect/src/ai/McpClient.ts Outdated
* @category models
* @since 4.0.6
*/
export interface McpClient extends Pipeable {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need Pipeable

Comment thread packages/effect/src/ai/McpClient.ts Outdated
) => Effect.Effect<ReadonlyArray<McpSchema.Prompt>, McpClientError>
/** Gets the messages for a discovered prompt. Unbounded unless `timeout` is supplied. */
readonly getPrompt: (
params: GetPromptParams,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline the param types instead of hiding then behind interfaces

@guillempuche

Copy link
Copy Markdown

Amazing!

This branch had an error being deployed

1 failed deployment
fork — ff704598 Deployed Oct 22, 2026 by tim-smart via approval-gate #22533
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add Effect-native McpClient

5 participants