Title: MCP Tool execution hangs indefinitely in stdio mode when calling external Python scripts · Issue #671 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: MCP Tool execution hangs indefinitely in stdio mode when calling external Python scripts · Issue #671 · modelcontextprotocol/python-sdk
X Title: MCP Tool execution hangs indefinitely in stdio mode when calling external Python scripts · Issue #671 · modelcontextprotocol/python-sdk
Description: Describe the bug When using FastMCP in stdio transport mode, any tool that attempts to execute an external Python script will hang indefinitely until timeout, without returning any result or error. The same code works perfectly when usin...
Open Graph Description: Describe the bug When using FastMCP in stdio transport mode, any tool that attempts to execute an external Python script will hang indefinitely until timeout, without returning any result or error....
X Description: Describe the bug When using FastMCP in stdio transport mode, any tool that attempts to execute an external Python script will hang indefinitely until timeout, without returning any result or error....
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/671
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"MCP Tool execution hangs indefinitely in stdio mode when calling external Python scripts","articleBody":"**Describe the bug**\nWhen using FastMCP in stdio transport mode, any tool that attempts to execute an external Python script will hang indefinitely until timeout, without returning any result or error. The same code works perfectly when using SSE transport mode.\n\n**To Reproduce**\nSteps to reproduce the behavior:\n1. Create a minimal external script (minimal_script.py) that simply prints output and exits\n```\nimport sys\n\ndef main():\n print(\"Successfully Call!\")\n return 0\n\nif __name__ == \"__main__\":\n sys.exit(main())\n```\n2. Create an MCP server with a tool that calls this external script\n```\nimport os\nimport sys\nimport asyncio\nimport subprocess\nfrom typing import Dict, Any\n\nfrom mcp.server.fastmcp import FastMCP\n\n# Initialize MCP\nmcp = FastMCP(\"bug_demo\")\n\n@mcp.tool()\nasync def call_external_script() -\u003e Dict[str, Any]:\n \"\"\"Call external script and return result\"\"\"\n # Get script path\n current_dir = os.path.dirname(os.path.abspath(__file__))\n script_path = os.path.join(current_dir, \"minimal_script.py\")\n \n # Build command\n cmd = [sys.executable, script_path]\n \n try:\n # Execute external command\n process = await asyncio.create_subprocess_exec(\n *cmd,\n stdout=subprocess.PIPE,\n stderr=subprocess.PIPE\n )\n \n # Wait for process to complete and get output\n stdout, stderr = await process.communicate()\n \n return {\n \"success\": process.returncode == 0,\n \"stdout\": stdout.decode().strip(),\n \"stderr\": stderr.decode().strip(),\n \"return_code\": process.returncode\n }\n except Exception as e:\n return {\n \"success\": False,\n \"error\": str(e)\n }\n\nif __name__ == \"__main__\":\n mcp.run(transport=\"stdio\")\n # mcp.run(transport=\"sse\")\n```\n3. Run the server in stdio mode\n4. Call the tool (Using MCP Inspector) that executes the external script\n5. Observe that the tool call hangs indefinitely with no response\n\n\n**Expected behavior**\nThe tool should execute the external Python script, capture its output, and return the results promptly, regardless of the transport mode used (stdio or SSE).\n\n**Screenshots**\nWhen using stdio, the tool will hang indefinitely until timeout.\n\n\nHowever, correct results can be obtained by using SSE mode.\n\n\n**Desktop (please complete the following information):**\n - OS: Windows 11 24H2 26100.3775\n - Python 3.10.0\n - mcp 1.7.1\n - asyncio 3.4.3\n\n**Additional context**\n· The issue persists regardless of whether using asyncio.create_subprocess_exec() or subprocess.run().\n· I tried printing something in an external py script and found that when calling the tool in STDIO mode, it would be unresponsive, but after timeout, the external py script would be executed and something would be printed out. This is like the running of a py script being blocked until the tool call times out before it can run\n","author":{"url":"https://github.com/ycycycl","@type":"Person","name":"ycycycl"},"datePublished":"2025-05-09T06:17:05.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/671/python-sdk/issues/671"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e39dc956-297b-5c29-0c2e-46e63c40161f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C0B4:3D4855:8300B0:BDCF03:6A5787C3 |
| html-safe-nonce | eb02022bfab8f77d40df2bb490918c44f4257c048d65313d09ddb7cbdf084481 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMEI0OjNENDg1NTo4MzAwQjA6QkRDRjAzOjZBNTc4N0MzIiwidmlzaXRvcl9pZCI6IjY2MjM0NjMxMDY5NzgyMTk5NzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c2fdf56f8cb51d8171744a90025a7739fd0a29299f2b981dab83eb4d26cce876 |
| hovercard-subject-tag | issue:3051048670 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/671/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d0f71043463364b75157d9bbd03fcb4dd883d4b6bc0ee0b4f44be1c13a7af703/modelcontextprotocol/python-sdk/issues/671 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d0f71043463364b75157d9bbd03fcb4dd883d4b6bc0ee0b4f44be1c13a7af703/modelcontextprotocol/python-sdk/issues/671 |
| og:image:alt | Describe the bug When using FastMCP in stdio transport mode, any tool that attempts to execute an external Python script will hang indefinitely until timeout, without returning any result or error.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ycycycl |
| hostname | github.com |
| expected-hostname | github.com |
| None | c6353e56e94423c9cd5abde7708a859afa36a0c1203c73749055bf6ee6704cd0 |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f59ab1c46b638204e2aea09126d089be5dc773b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width