From 379a3b1a01545155922cdad7142629fc2a06ddd7 Mon Sep 17 00:00:00 2001 From: tegwick Date: Wed, 25 Feb 2026 00:21:09 +0100 Subject: [PATCH] Fix MCP server httpx redirect handling Add follow_redirects=True to httpx Client so 307 redirects (FastAPI trailing-slash redirects) are followed transparently. Also add trailing slash normalisation to _get and _patch to match existing _post behaviour, so all three helpers hit the correct URLs on first attempt. Requires Claude Code restart to take effect (MCP server is a subprocess launched at startup). Co-Authored-By: Claude Sonnet 4.6 --- mcp_server/server.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mcp_server/server.py b/mcp_server/server.py index 7971472..d096023 100644 --- a/mcp_server/server.py +++ b/mcp_server/server.py @@ -32,10 +32,12 @@ mcp = FastMCP( # --------------------------------------------------------------------------- def _client() -> httpx.Client: - return httpx.Client(base_url=API_BASE, timeout=30.0) + return httpx.Client(base_url=API_BASE, timeout=30.0, follow_redirects=True) def _get(path: str, params: dict | None = None) -> Any: + if not path.endswith("/"): + path = path + "/" with _client() as c: r = c.get(path, params={k: v for k, v in (params or {}).items() if v is not None}) r.raise_for_status() @@ -52,6 +54,8 @@ def _post(path: str, body: dict) -> Any: def _patch(path: str, body: dict) -> Any: + if not path.endswith("/"): + path = path + "/" with _client() as c: r = c.patch(path, json={k: v for k, v in body.items() if v is not None}) r.raise_for_status()