modelcontextprotocol / modelcontextprotocol/python-sdk

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

Open
#2,663 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug fix proposed P3 ready for work
Dominant language
Python
Stars
24.3k
Forks
4k
Avg merge
1d 1h
Merged PRs (30d)
31

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the Ctrl-C behavior for a FastMCP stdio server, then trace FastMCP.run through mcp.server.lowlevel.server.run and the anyio memory receive path. The fix is done when interrupting the server exits cleanly without a traceback while normal shutdown behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.