File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Stdio Server Shutdown Behavior
2+
3+ ## Overview
4+
5+ When using the stdio transport, the MCP server monitors stdin for EOF (End of File)
6+ to detect when the parent process has terminated. This ensures the server shuts down
7+ gracefully instead of becoming an orphan process.
8+
9+ ## How It Works
10+
11+ 1 . The server reads from stdin in a loop
12+ 2 . When stdin is closed (EOF), the server detects this condition
13+ 3 . The server signals shutdown by closing the read stream
14+ 4 . All resources are cleaned up properly
15+
16+ ## Parent Process Death
17+
18+ If the parent process (MCP client) dies unexpectedly:
19+ - The server's stdin will be closed by the operating system
20+ - The server detects EOF and initiates graceful shutdown
21+ - No orphan processes remain
22+
23+ ## Configuration
24+
25+ No additional configuration is required. This behavior is automatic when using
26+ the stdio transport.
27+
28+ ## Example
29+
30+ ``` python
31+ from mcp.server.stdio import stdio_server
32+
33+ async def run_server ():
34+ async with stdio_server() as (read_stream, write_stream):
35+ # Server will automatically shut down when stdin closes
36+ await server.run(read_stream, write_stream, init_options)
37+ ```
You can’t perform that action at this time.
0 commit comments