modelcontextprotocol / modelcontextprotocol/servers

everything: subscriptions map never drops a disconnected session

Open Beginner friendly
#4,710 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

server-everything
Dominant language
TypeScript
Stars
90.5k
Forks
11.7k
Avg merge
2d 2h
Merged PRs (30d)
5

Description

In src/everything/resources/subscriptions.ts, subscriptions is a module-level Map<uri, Set<sessionId>>. A session id is added on resources/subscribe and removed only on resources/unsubscribe. Nothing removes it when the session ends.

Both transports call cleanup(sessionId) from server.server.onclose (transports/streamableHttp.ts, transports/sse.ts). That function (server/index.ts:109) calls stopSimulatedLogging, stopSimulatedResourceUpdates and taskStore.cleanup(), so the interval timers are cleared, but subscriptions is not touched. A client that subscribes and then disconnects without unsubscribing leaves its session id in every Set it joined, for the life of the process.

Until #4104 the else branch of sendSimulatedResourceUpdates carried a comment saying it removed disconnected subscribers. It did not (it deleted from a Set that provably lacked the element), and the branch is now gone, so there is no longer anything that even implies cleanup exists.

Impact is small for a reference server, but it is the example people copy. Suggested fix: export a removeSubscriber(sessionId) from subscriptions.ts that iterates the map, deletes the session from each Set and drops empty entries, and call it from cleanup().

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/everything/resources/subscriptions.ts to inspect the module-level subscriptions map and the subscribe/unsubscribe paths, then read cleanup() at server/index.ts:109 and the close handlers in transports/streamableHttp.ts and transports/sse.ts. Implement the missing disconnected-session cleanup and verify that session IDs disappear from all sets and empty entries are removed after cleanup.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
86/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.