modelcontextprotocol / modelcontextprotocol/python-sdk

FastMCP.run(transport="stdio") produces noisy traceback on KeyboardInterrupt instead of clean exit

未關閉
#2,663 3 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

bug fix proposed P3 ready for work
主要語言
Python
星號
24.3k
分支
4k
平均合併
1 天 1 小時
30 天內合併 PR
31

描述

Initial Checks
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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 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

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。