McpServer.layerStdio: two stdio servers in one layer graph share one stdio protocol, so the second never reads its stdin
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- typescript
- Área
- backend-api-design
Línea de trabajo
Start by running the supplied reproduction, then read layerProtocolStdio in packages/effect/src/unstable/rpc/RpcServer.ts and layerStdio in packages/effect/src/unstable/ai/McpServer.ts. Trace how layer memoization behaves within Layer.mergeAll and how it interacts with McpServer.layer. Done means documenting the intended model or agreeing on and validating a change that supports the required composition.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
This may well be intended: a process has one stdin, so one stdio server per process is a natural model. We're reporting it because we hit it in tests, where two servers each get their own Stdio and the result surprised us.
What we observed
We merged two McpServer.layerStdio servers into one layer graph with Layer.mergeAll, each with its own Stdio. Only the first server answers. The second never reads its own stdin. If the same two servers are built separately, each with its own Layer.build, both answer.
Environment: [email protected] (tag [email protected], 14a3f14), on Node 26.10.0 and macOS. From reading the source, layerProtocolStdio is still a module-level constant on main at 3788b63 (packages/effect/src/rpc/RpcServer.ts:1436-1440).
Reproduction
import { Effect, Layer, Sink, Stdio, Stream } from "effect"
import { McpProtocol, McpServer } from "effect/unstable/ai"
const initialize = (id: number) =>
JSON.stringify({
jsonrpc: "2.0",
id,
method: "initialize",
params: { protocolVersion: "2025-11-25", capabilities: {}, clientInfo: { name: "repro", version: "0" } }
}) + "\n"
const makeStdio = (name: string, id: number, out: Array<string>) =>
Stdio.layerTest({
stdin: Stream.make(new TextEncoder().encode(initialize(id))).pipe(Stream.concat(Stream.never)),
stdout: () =>
Sink.forEach((chunk: string | Uint8Array) =>
Effect.sync(() =>
out.push(`${name} stdout: ${typeof chunk === "string" ? chunk : new TextDecoder().decode(chunk)}`.trim())
)
)
})
const server = (name: string) =>
McpServer.layerStdio({ name, version: "0.0.0", protocols: [McpProtocol.v2025_11_25] })
const report = (label: string, outA: Array<string>, outB: Array<string>) =>
Effect.sync(() => {
console.log(`--- ${label}`)
console.log(outA.length ? outA.join("\n").slice(0, 150) : "A stdout: (nothing)")
console.log(outB.length ? outB.join("\n").slice(0, 150) : "B stdout: (nothing)")
})
const outA: Array<string> = []
const outB: Array<string> = []
const program = process.argv[2] === "separate"
? Effect.gen(function*() {
yield* Layer.build(server("A").pipe(Layer.provide(makeStdio("A", 1, outA))))
yield* Layer.build(server("B").pipe(Layer.provide(makeStdio("B", 2, outB))))
yield* Effect.sleep("300 millis")
yield* report("each server in its own Layer.build", outA, outB)
})
: Effect.gen(function*() {
yield* Layer.build(Layer.mergeAll(
server("A").pipe(Layer.provide(makeStdio("A", 1, outA))),
server("B").pipe(Layer.provide(makeStdio("B", 2, outB)))
))
yield* Effect.sleep("300 millis")
yield* report("both servers in one Layer.mergeAll", outA, outB)
})
Effect.runFork(Effect.scoped(program))
We ran node repro.ts separate and node repro.ts merged, and captured the output live:
--- each server in its own Layer.build
A stdout: {"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-11-25","capabilities":{"logging":{},"completions":{}},"serverInfo":{"name":"A","ve
B stdout: {"jsonrpc":"2.0","id":2,"result":{"protocolVersion":"2025-11-25","capabilities":{"logging":{},"completions":{}},"serverInfo":{"name":"B","ve
--- both servers in one Layer.mergeAll
A stdout: {"jsonrpc":"2.0","id":1,"result":{"protocolVersion":"2025-11-25","capabilities":{"logging":{},"completions":{}},"serverInfo":{"name":"A","ve
B stdout: (nothing)
Our reading
No spec is involved here. This is a question about layer design. MCP's stdio transport has the client launch "the MCP server as a subprocess", so one server per process is the normal production shape. We hit this only in tests and tooling that host several servers in one process.
Where it happens
RpcServer.ts:1416-1420:layerProtocolStdiois a module-levelLayer.effect(Protocol, makeProtocolStdio).McpServer.ts:1439-1447: everylayerStdio(...)call provides that same constant. Layers are memoized by reference within one build, so as we read it, both servers resolveProtocolto a single instance built over whicheverStdiowas reached first. That fits what we see: B'sinitialize(id 2) is answered on neither stdout.
How we work around it
We don't have a code fix. In @effected/mcp we document the limitation: give each server a fresh layer memo map, through its own ManagedRuntime, Effect.provide(layer, { local: true }), or its own process.
Is this intended?
If one stdio server per memo map is the intended model, a sentence in the layerStdio / layerProtocolStdio docs would have saved us some time. If it isn't intended, one possible direction is for layerStdio to build its protocol layer per call rather than sharing the module constant. We haven't worked through how that would interact with the shared McpServer.layer.
- Lenguaje dominante
- TypeScript
- Estrellas
- 16.7k
- Forks
- 808
- Merge medio
- 11 h 11 min
- PR fusionados (30 d)
- 840
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de Effect-TS/effect
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
@effect/ai-anthropic: text_editor_20250728 insert decodes `new_str`, but the API sends `insert_text`Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
[email protected]: crypto/KeyFormat declarations require the global JsonWebKey, breaking Node-only type-checksPosiblemente ocupada @effect-bot la tomó hoy. Abierto
Effect-TS/effect#10115 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 4/5 1-2 días Aptitud para principiantes 55/100
Los mantenedores suelen responder en 1 día
-
sql-pg: send several statements in one extended-query Sync (transaction-local context without extra round trips)Posiblemente ocupada @effect-bot la tomó hoy. Abierto
Effect-TS/effect#10113 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de Effect-TS/effect
Issues similares
-
Shell: serve the home app's Cookie Policy on a hard reloadPosiblemente ocupada @2001anshkaushik la tomó hoy. Abiertofeature module:ai
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
rocketride-org/rocketride-server#2899 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
wazuh/wazuh-dashboard-plugins#9551 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
gofish-graphics/gofish-graphics#1252 ·
Los mantenedores suelen responder en 1 día
-
optimization P3 size:XS
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
josephfung/curia#2366 ·
Los mantenedores suelen responder en 1 día
-
stranded-follow-up sweep trusts any issue whose body carries the marker as the tracking issueAbiertotype:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
nightgauge/nightgauge#2688 ·
Los mantenedores suelen responder en 1 día