modelcontextprotocol / modelcontextprotocol/servers
everything: subscriptions map never drops a disconnected session
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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