modelcontextprotocol / modelcontextprotocol/python-sdk

StdioServerParameters exposes no preexec_fn / rlimit / process-group hook for spawned MCP server subprocess

未关闭
#3,457 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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 between fork and exec.

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:

  1. an optional preexec_fn / process_group / rlimit-style kwarg on StdioServerParameters (or stdio_client), passed through to the underlying subprocess.Popen, or
  2. an injection point for a custom Popen factory / 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.

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先定位 StdioServerParameters 和 stdio_client 上下文管理器,然后跟踪它们如何创建 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

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。