π The fast, Pythonic way to build MCP servers and clients.
Exclude content-type header from get_http_headers() to prevent HTTP 415 errors (#3104)
Jeremiah Lowind12d46b04976
diff --git a/src/fastmcp/server/dependencies.py b/src/fastmcp/server/dependencies.pyindex ce964fd31..ffef2561b 100644--- a/src/fastmcp/server/dependencies.py+++ b/src/fastmcp/server/dependencies.py@@ -441,6 +441,7 @@ def get_http_headers(include_all: bool = False) -> dict[str, str]:exclude_headers = {"host","content-length",+ "content-type","connection","transfer-encoding","upgrade",diff --git a/tests/server/http/test_http_dependencies.py b/tests/server/http/test_http_dependencies.pyindex e379f5e83..e637af269 100644--- a/tests/server/http/test_http_dependencies.py+++ b/tests/server/http/test_http_dependencies.py@@ -126,3 +126,43 @@ async def test_http_headers_prompt_sse(sse_server: str):json_result = json.loads(result.messages[0].content.text)assert "x-demo-header" in json_resultassert json_result["x-demo-header"] == "ABC"+++async def test_get_http_headers_excludes_content_type(sse_server: str):+ """Test that get_http_headers() excludes content-type header (issue #3097).++ This prevents HTTP 415 errors when forwarding headers to downstream APIs+ that require specific Content-Type headers (e.g., application/vnd.api+json).+ """+ from fastmcp.server.dependencies import get_http_headers++ server = FastMCP()++ @server.tool+ def check_excluded_headers() -> dict[str, str]:+ """Check that problematic headers are excluded from get_http_headers()."""+ return get_http_headers()++ async with run_server_async(server, transport="sse") as url:+ async with Client(+ transport=SSETransport(+ url,+ headers={+ "Content-Type": "application/json",+ "Accept": "application/json",+ "X-Custom-Header": "should-be-included",+ },+ )+ ) as client:+ result = await client.call_tool("check_excluded_headers")+ headers = result.data++ # These headers should be excluded+ assert "content-type" not in headers+ assert "accept" not in headers+ assert "host" not in headers+ assert "content-length" not in headers++ # Custom headers should be included+ assert "x-custom-header" in headers+ assert headers["x-custom-header"] == "should-be-included"