STDIO hangs forever when the using multiprocessing in tools
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by running test_client.py with test_mcp.py and reproduce the hang after the CallToolRequest is logged. Trace the interaction between the multiprocessing pool in the sum tool and the stdio client/server entry points. Done means the example completes and returns the tool result instead of remaining stuck.
Written by the indexing model from the issue text.
Description
Describe the bug
when multiprocessing in a tool, and start mcp client by STDIO, the mcp server never response.
To Reproduce
Steps to reproduce the behavior:
- write mcp server:
## test_mcp.py
from mcp.server.fastmcp import FastMCP
import multiprocessing as mp
mcp = FastMCP()
@mcp.tool()
def sum() -> int:
"count number"
with mp.Pool(processes=2) as pool:
res = pool.imap(str, range(10))
res = list(res)
return res
if __name__ == '__main__':
mcp.run()
- write mcp client usig stdio
## test_client.py
from mcp import ClientSession, StdioServerParameters, types
from mcp.client.stdio import stdio_client
# Create server parameters for stdio connection
server_params = StdioServerParameters(
command="python", # Executable
args=["test_mcp.py"], # Optional command line arguments
env=None, # Optional environment variables
)
async def run():
async with stdio_client(server_params) as (read, write):
async with ClientSession(
read, write
) as session:
# Initialize the connection
await session.initialize()
resources = await session.list_resources()
# List available tools
tools = await session.list_tools()
print(tools)
result = await session.call_tool(
"sum",
)
print(result)
asyncio.run(run())
- test running
$ python test_client.py
[05/27/25 15:42:13] INFO Processing request of type ListResourcesRequest server.py:551
INFO Processing request of type ListToolsRequest server.py:551
meta=None nextCursor=None tools=[Tool(name='sum', description='count number', inputSchema={'properties': {}, 'title': 'sumArguments', 'type': 'object'}, annotations=None)]
INFO Processing request of type CallToolRequest server.py:551
The program is stuck here and won't continue running
Version
Name: mcp
Version: 1.9.0
Summary: Model Context Protocol SDK
Home-page:
Author: Anthropic, PBC.
Author-email:
License: MIT
Location: /data/software/micromamba/envs/gbi/lib/python3.10/site-packages
Requires: anyio, httpx, httpx-sse, pydantic, pydantic-settings, python-multipart, sse-starlette, starlette, uvicorn
Required-by: camel-ai, cellrank-mcp, fast-agent-mcp, fastmcp, liana-mcp, mcp-server-calculator, scmcp, scmcp-utils, scmcp_shared
- Dominant language
- Python
- Stars
- 24.3k
- Forks
- 4k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 25
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from modelcontextprotocol/python-sdk
-
v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
modelcontextprotocol/python-sdk#3578 · 1 comment ·
-
v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
modelcontextprotocol/python-sdk#3573 · 2 comments ·
-
v2
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
modelcontextprotocol/python-sdk#3566 ·
-
v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
modelcontextprotocol/python-sdk#3546 · 5 comments ·
-
v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
modelcontextprotocol/python-sdk#3545 · 2 comments ·
All issues in modelcontextprotocol/python-sdk
Similar issues
-
area: harness bug status: needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Human-Agent-Society/reef#625 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 1/5 Under an hour Newbie friendliness 80/100
learningequality/kolibri#15351 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Name consistency Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
eellak/triplestore#65 · 1 comment ·