McpServer.layerStdio: two stdio servers in one layer graph share one stdio protocol, so the second never reads its stdin
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 16.7k
- Fork
- 808
- Merge trung bình
- 10 giờ 49 phút
- Pull request đã merge (30 ngày)
- 846
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Effect-TS/effect
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
add first-class support for skills extension in McpServerCó thể đã có người làm @effect-bot đã nhận hôm nay. Đang mởenhancement
Effect-TS/effect#10016 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SqlEventJournal: remote catch-up exceeds SQLite's bind-variable limitCó thể đã có người làm @effect-bot đã nhận hôm nay. Đang mở
Effect-TS/effect#10012 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
AI providers drop the cause of a transport failure from `NetworkError`Có thể đã có người làm @effect-bot đã nhận 1 ngày trước. Đang mở
Effect-TS/effect#9983 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Effect-TS/effect
Issue tương tự
-
Plugin: sheet music can't be scrolled by hand before playbackCó thể đã có người làm @snakajima đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
receptron/jinglescript#51 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 9 ngày
-
clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openclaw/openclaw#186424 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
chore(worker): five module header comments describe the code from before later issues changed itĐang mởarea:dev U2-later
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
bentleypark/aiwatch#1824 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Pal-AI-Lab/Coopanion#469 ·
Maintainer thường phản hồi trong vòng 1 ngày