[v2] Allow MCPServer to disable subscriptions/listen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 68/100
- Issue-Typ
- Feature
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- python
- Bereich
- api, backend-api-design
Rechercherichtung
Beginne mit dem MCPServer-Konstruktor und seiner Registrierung von on_subscriptions_listen=ListenHandler(self._subscriptions), und untersuche anschließend _lowlevel_server.get_capabilities sowie den Request-Pfad für subscriptions/listen. Definiere den öffentlichen Opt-out, wobei das aktuelle Standardverhalten erhalten bleibt. Fertig ist es, wenn deaktivierte Server den Handler weglassen, die relevanten Capabilities als false ankündigen und bei nicht angeforderten subscriptions/listen-Aufrufen Method not found zurückgeben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Initial Checks
- I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Release line
2.x (current stable)
Description
What happened?
MCPServer always installs a subscriptions/listen handler:
on_subscriptions_listen=ListenHandler(self._subscriptions)
The constructor exposes subscriptions: SubscriptionBus | None = None, but None creates an InMemorySubscriptionBus; it does not disable subscriptions.
This causes server/discover to advertise:
{
"tools": {"listChanged": true},
"prompts": {"listChanged": true},
"resources": {"listChanged": true, "subscribe": true}
}
Our MCP server has a static catalog and never publishes change notifications. It runs as a stateless Streamable HTTP server on AWS Lambda.
Claude Code 2.1.235 automatically opened four subscriptions/listen streams during discovery. Each request followed the long-lived SSE path and held a Lambda invocation until timeout.
We currently reject these requests in ASGI middleware. This prevents the timeout, but the server still advertises subscription support, so clients continue attempting the requests.
The low-level Server supports disabling this correctly through:
Server(..., on_subscriptions_listen=None)
The high-level MCPServer has no equivalent public option. Removing the handler through _lowlevel_server._request_handlers works, but relies on private internals.
What did you expect?
MCPServer should provide a supported opt-out, for example:
MCPServer(..., subscriptions=False)
or:
MCPServer(..., enable_subscriptions=False)
When disabled:
subscriptions/listenshould not be registered.- server/discover should advertise the relevant change and subscription capabilities as false.
- An unsolicited subscriptions/listen call should return Method not found.
- Existing behavior should remain the default for compatibility.
This matches SEP-2575’s stateless-first, “pay as you go” design. Long-lived streams should only be enabled when the server uses them.
Area
Server
References
AI assistance disclosure: I used an AI coding assistant to inspect the SDK source and help draft this report. I reviewed and verified the contents.
Example Code
from mcp.server import MCPServer
server = MCPServer("static-server")
capabilities = server._lowlevel_server.get_capabilities(
protocol_version="2026-07-28"
)
print(capabilities.model_dump(by_alias=True, exclude_none=True))
Python & MCP Python SDK
Python 3.11
mcp 2.0.0
AWS Lambda
Streamable HTTP
json_response=True
stateless_http=True
- Vorherrschende Sprache
- Python
- Sterne
- 24.3k
- Forks
- 4k
- Ø Merge
- 1 T. 19 Min.
- Gemergte PRs (30 T.)
- 29
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus modelcontextprotocol/python-sdk
-
v1 v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 85/100
modelcontextprotocol/python-sdk#3546 · 5 Kommentare ·
-
v1 v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
modelcontextprotocol/python-sdk#3545 · 1 Kommentar ·
-
v1 v2
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 91/100
modelcontextprotocol/python-sdk#3508 · 2 Kommentare ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 64/100
modelcontextprotocol/python-sdk#3504 ·
-
v1 v2
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
modelcontextprotocol/python-sdk#3492 · 1 Kommentar ·
Alle Issues in modelcontextprotocol/python-sdk
Ähnliche Issues
-
documentation help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 90/100
simonw/sqlite-utils#872 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 88/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100