Skip to content

Commit 9cb5441

Browse files
committed
test and ruff
1 parent 86cc5a3 commit 9cb5441

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/mcp/server/fastmcp/server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,7 @@ async def get_prompt(self, name: str, arguments: dict[str, Any] | None = None) -
969969
logger.exception(f"Error getting prompt {name}")
970970
raise ValueError(str(e))
971971

972+
972973
class StreamableHTTPASGIApp:
973974
"""
974975
ASGI application for Streamable HTTP server transport.
@@ -980,6 +981,7 @@ def __init__(self, session_manager: StreamableHTTPSessionManager):
980981
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
981982
await self.session_manager.handle_request(scope, receive, send)
982983

984+
983985
class Context(BaseModel, Generic[ServerSessionT, LifespanContextT, RequestT]):
984986
"""Context object providing access to MCP capabilities.
985987

tests/server/fastmcp/test_server.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,3 +1072,15 @@ def prompt_fn(name: str) -> str:
10721072
async with client_session(mcp._mcp_server) as client:
10731073
with pytest.raises(McpError, match="Missing required arguments"):
10741074
await client.get_prompt("prompt_fn")
1075+
1076+
def test_streamable_http_no_redirect(self):
1077+
"""Test that /mcp endpoint does not cause 307 redirect (PR #1115)."""
1078+
from starlette.testclient import TestClient
1079+
1080+
mcp = FastMCP("test-redirect")
1081+
app = mcp.streamable_http_app()
1082+
1083+
with TestClient(app, raise_server_exceptions=False) as client:
1084+
# Test POST to /mcp - should NOT redirect
1085+
response = client.post("/mcp", json={"test": "data"}, follow_redirects=False)
1086+
assert response.status_code != 307

0 commit comments

Comments
 (0)