Skip to content

Commit a8bef4a

Browse files
author
Developer
committed
docs: Add documentation for stdio server shutdown behavior
Documents how the stdio server detects parent process termination via stdin EOF and shuts down gracefully to prevent orphan processes.
1 parent ad87b3c commit a8bef4a

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

docs/stdio_server_shutdown.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
```

0 commit comments

Comments
 (0)