modelcontextprotocol / modelcontextprotocol/python-sdk
FastMCP.run(transport="stdio") produces noisy traceback on KeyboardInterrupt instead of clean exit
還沒有人認領這個 Issue。
- 主要語言
- Python
- 星號
- 24.3k
- 分支
- 4k
- 平均合併
- 1 天 1 小時
- 30 天內合併 PR
- 31
描述
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
Description
Running a FastMCP stdio server from the terminal and interrupting with Ctrl-C produces a multi-frame traceback through anyio.run() → asyncio.runners → mcp.server.lowlevel.server.run → anyio.streams.memory.receive. The server is correctly waiting on stdin in an async loop; the trace surfaces because anyio/asyncio don't suppress the cancellation chain. Suggested fix: catch KeyboardInterrupt (or asyncio.CancelledError at the outer boundary) inside FastMCP.run and exit cleanly. Cosmetic but reduces user confusion when testing MCP servers from the terminal.
Example Code
Python & MCP Python SDK
Python 3.13.5
MCP Python SDK 1.27.1
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先重現 FastMCP stdio 伺服器的 Ctrl-C 行為,接著追蹤 FastMCP.run 經過 mcp.server.lowlevel.server.run 以及 anyio 記憶體接收路徑的流程。修正完成的條件是:中斷伺服器時能夠乾淨地結束且不出現 traceback,同時正常的關閉行為維持不變。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- backend, cli
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 64/100