modelcontextprotocol / modelcontextprotocol/python-sdk
[v2] Allow MCPServer to disable subscriptions/listen
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 24.3k
- 派生
- 4k
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 31
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 MCPServer 构造函数及其对 on_subscriptions_listen=ListenHandler(self._subscriptions) 的注册开始,然后检查 _lowlevel_server.get_capabilities 和 subscriptions/listen 请求路径。定义公开的 opt-out,同时保留当前的默认行为。完成的标准是:已禁用的服务器省略该 handler,将相关 capabilities 声明为 false,并对未经请求的 subscriptions/listen 调用返回 Method not found。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api, backend-api-design
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 68/100