McpServer.layerHttp: bound the number of HTTP sessions kept in memory

Đang mở
#10,947 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
35/100
Loại issue
Tính năng
Độ 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

The proposal identifies McpServer, mcpRuntime, and mcpStatefulRuntime as the affected areas, but does not name file paths or tests. Start by reading the existing layerHttp session lifecycle and the tests for stateful HTTP requests. Done means enforcing the optional session bound without changing behavior when it is unset, and covering busy sessions, concurrent initialization, interruption, and session termination.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Note: everything below was written by an AI agent working on the author's behalf and may not have been reviewed by a human.

This is AI-generated; I don't have strong opinions on the API or developer experience and am glad to take whatever shape you prefer, but I do need the functionality.

Problem

McpServer.layerHttp keeps every stateful session in memory for the server's life. A session goes away only when its client sends DELETE and the server allows it (allowSessionTermination, #8773). Many clients never send DELETE, and some open a new session for every call. On a long-running server the session map therefore only grows.

Proposal

Two options on layerHttp:

  • maxSessions: the most sessions kept in memory. Past it, the least recently used session that owns no work is forgotten; its client gets 404 and initializes again, as the 2025-11-25 transport prescribes for a terminated session.
  • heldSession: (sessionId) => boolean: whether the application holds work that only this session can reach (for example a paused operation its client will resume). Such a session is never the one forgotten.

The details I found necessary:

  • A session owns work while one of its POSTs runs, until its response has been sent (stream included), or while heldSession says so. Forgetting it then would strand a pending reply or cancellation.
  • When every session owns work, a new initialize is refused with 503, Retry-After: 1 and a JSON-RPC error, rather than forgetting a busy session.
  • Admitting an initialize takes its session's place in the same synchronous step as the check, so initialize requests admitted together cannot pass the bound. A request that ends before its session opens gives the place back. The place and a request's hold on its session are taken with interruption masked until their release is installed, so a client that disconnects in between strands neither.
  • Without maxSessions, nothing changes.

I carry this as a patch, with tests, in McpServer, mcpRuntime and mcpStatefulRuntime. It pairs with a session store (my comment on #6752): with both, a forgotten session can still be restored from the store on its next request.

Questions

  1. Would you take a bound on HTTP sessions in layerHttp, or should applications put this in front of the server?
  2. Least recently used with a hold for busy sessions, or a time-based expiry (idle timeout) instead? I chose a count because memory is what runs out; an idle timeout would also work for me.
  3. Is 503 with Retry-After the right answer when every session is busy?

I'm happy to open a PR in whatever shape you prefer.

Ngôn ngữ chính
TypeScript
Star
16.7k
Fork
808
Merge trung bình
21 giờ 22 phút
Pull request đã merge (30 ngày)
486

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Effect-TS/effect

Tất cả issue của Effect-TS/effect

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.