modelcontextprotocol / modelcontextprotocol/python-sdk
StdioServerParameters exposes no preexec_fn / rlimit / process-group hook for spawned MCP server subprocess
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 24.3k
- Forks
- 4k
- Merge médio
- 1d 1h
- PRs com merge (30d)
- 31
Descrição
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.
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece localizando StdioServerParameters e o gerenciador de contexto stdio_client; em seguida, rastreie como eles criam o subprocess e quais opções de subprocess.Popen são passadas atualmente. Compare as abordagens solicitadas de pre-exec, process-group, resource-limit ou spawn-factory no macOS e no Linux. Considera-se concluído quando a API pública expõe um hook de process-control documentado e seu comportamento é coberto pelos testes relevantes.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend, security
- Tipo de issue
- Funcionalidade
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Ativa
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 52/100