modelcontextprotocol / modelcontextprotocol/python-sdk
StdioServerParameters exposes no preexec_fn / rlimit / process-group hook for spawned MCP server subprocess
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 24.3k
- 分支
- 4k
- 平均合併
- 1 天 1 小時
- 30 天內合併 PR
- 31
描述
Context
StdioServerParameters (and the stdio_client context manager that spawns the server subprocess) expose no hook to control the spawned child process's resource limits or process-group assignment at fork time.
Problem
A client that spawns an untrusted or third-party MCP server via stdio cannot, from the SDK public API:
- set CPU / memory / FD / address-space
rlimits on the child, - place the child in its own process group (so a runaway child can be killed as a group without orphaning grandchildren),
- set a
preexec_fn(POSIX) or equivalent to run arbitrary setup betweenforkandexec.
StdioServerParameters signature (command, args, env, cwd, encoding, encoding_error_handler) has no slot for any of these. stdio_client owns the subprocess spawn internally, so a caller cannot inject a custom Popen either.
Impact
Downstream hosts (e.g. inference servers spawning MCP tool servers) cannot enforce hard resource caps or reliable teardown on a hung/misbehaving MCP server subprocess from the client side. The only mitigation available today is a bounded connect timeout around __aenter__, which does not cover a server that accepts the connection then later runs away.
Request
Expose at least one of:
- an optional
preexec_fn/process_group/rlimit-style kwarg onStdioServerParameters(orstdio_client), passed through to the underlyingsubprocess.Popen, or - an injection point for a custom
Popenfactory / spawn callable.
(1) mirrors subprocess.Popen(..., preexec_fn=..., start_new_session=...) and would let hosts enforce resource limits + process-group isolation without forking the SDK.
Environment: mcp python-sdk, macOS / Linux. Filed from fusion-mlx (local MLX inference host) where we need to cap spawned MCP server subprocesses.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先定位 StdioServerParameters 和 stdio_client context manager,接著追蹤它們如何建立 subprocess,以及目前傳入了哪些 subprocess.Popen 選項。比較所要求的 pre-exec、process-group、resource-limit 或 spawn-factory 方法在 macOS 和 Linux 上的情況。完成的標準是公開 API 提供一個有文件說明的 process-control hook,且其行為由相關測試涵蓋。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend, security
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 活躍
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100