modelcontextprotocol / modelcontextprotocol/python-sdk
STDIO hangs forever when the using multiprocessing in tools
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 24.3k
- Forks
- 4k
- Ø Merge
- 1 T. 1 Std.
- Gemergte PRs (30 T.)
- 31
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Führe zunächst test_client.py mit test_mcp.py aus und reproduziere das Hängenbleiben, nachdem CallToolRequest protokolliert wurde. Verfolge die Interaktion zwischen dem multiprocessing-Pool im sum-Tool und den stdio-Client-/Server-Einstiegspunkten. Als erledigt gilt die Aufgabe, wenn das Beispiel abgeschlossen wird und das Tool-Ergebnis zurückgibt, statt hängen zu bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100