Skip to content

Commit e010fe0

Browse files
committed
Update stateless stdio support with example test script and test fixes
1 parent ea35b7d commit e010fe0

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/mcp/server/fastmcp/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ async def run_stdio_async(self) -> None:
600600
read_stream,
601601
write_stream,
602602
self._mcp_server.create_initialization_options(),
603-
stateless=self.settings.stateless_stdio
603+
stateless=self.settings.stateless_stdio,
604604
)
605605

606606
async def run_sse_async(self, mount_path: str | None = None) -> None:

test_stateless.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from mcp.server.fastmcp import FastMCP
2+
3+
# Create FastMCP server
4+
mcp = FastMCP("StatelessTest")
5+
6+
7+
# Register a simple echo tool
8+
@mcp.tool()
9+
def echo(message: str) -> str:
10+
"""Echo a message back to the client."""
11+
return f"Echo: {message}"
12+
13+
14+
if __name__ == "__main__":
15+
# Run in STDIO mode
16+
mcp.run()

tests/server/test_session.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ async def test_server_session_stateless_mode():
295295
await server_session._received_request(responder)
296296
except RuntimeError as e:
297297
if "initialization" in str(e).lower():
298-
pytest.fail(f"Unexpected initialization error in stateless mode: {e}")
298+
msg = f"Unexpected initialization error in stateless mode: {e}"
299+
pytest.fail(msg)
299300
finally:
300301
# Clean up the streams to prevent ResourceWarning
301302
await server_to_client_send.aclose()

tests/server/test_stdio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ async def test_stateless_stdio():
7979
"""Test that stateless stdio mode allows tool calls without initialization."""
8080
with tempfile.TemporaryDirectory() as temp_dir:
8181
server_path = Path(temp_dir) / "server.py"
82-
82+
8383
with open(server_path, "w") as f:
8484
f.write("""
8585
from mcp.server.fastmcp import FastMCP

0 commit comments

Comments
 (0)