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

オープン
#3,457 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
52/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
backend, security

調査の方向性

まず StdioServerParameters と stdio_client コンテキストマネージャーを見つけ、次にそれらがどのように subprocess を作成し、現在どの subprocess.Popen オプションが渡されているかを追跡します。macOS と Linux で、要求されている pre-exec、process-group、resource-limit、spawn-factory の各アプローチを比較します。公開 API が文書化された process-control フックを公開し、その動作が関連するテストでカバーされていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 19分
マージ済み PR(30日)
29

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/python-sdk のほかの issue

modelcontextprotocol/python-sdk の issue をすべて見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。