Skip to content

Commit 3cbc745

Browse files
MB901claude
andcommitted
fix: switch MCP transport from legacy SSE to Streamable HTTP
The legacy SSE transport in the MCP Python SDK splits a session across two independent HTTP requests (a long-lived GET /sse stream that hands out a session_id, plus separate POST /messages?session_id=... calls) without verifying the GET side finished the initialize handshake before accepting POSTs on that session_id. When a client reopens a second /sse connection (observed from mcp-remote), requests race and land on a session before it's marked initialized, causing every tool call to fail with: Failed to validate request: Received request before initialization was complete Mounts the FastMCP app with transport="http" (Streamable HTTP) instead, still at path="/sse" for backward compatibility so existing client configs keep working unchanged. Streamable HTTP tracks sessions via a single Mcp-Session-Id header instead of two endpoints racing over a query param, which avoids this class of bug entirely. See modelcontextprotocol/python-sdk#423 and modelcontextprotocol/python-sdk#1844 Bumps version to 0.5.2. Co-Authored-By: Claude Sonnet 5 <[email protected]>
1 parent 6afdca2 commit 3cbc745

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

‎homebox-mcp/CHANGELOG.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.5.2] - 2026-08-14
9+
10+
### Fixed
11+
12+
- **`Failed to validate request: Received request before initialization was
13+
complete`, causing every tool call to fail** (even simple reads that had
14+
worked moments earlier). This was a bug in the MCP Python SDK's legacy SSE
15+
transport: a session is split across two independent HTTP requests (a
16+
long-lived `GET /sse` stream that hands out a `session_id`, plus separate
17+
`POST /messages?session_id=...` calls), and the SDK doesn't verify the GET
18+
side has finished the initialize handshake before accepting POSTs on that
19+
session. When a client (re)opens a second `/sse` connection — observed from
20+
mcp-remote — requests can race and land on a session before it's marked
21+
initialized. The server now uses the modern **Streamable HTTP** transport
22+
instead (still mounted at `/sse` for backward compatibility, so no client
23+
reconfiguration is needed), which uses a single endpoint keyed by an
24+
`Mcp-Session-Id` header rather than two endpoints racing over a query
25+
param, avoiding this class of bug entirely. See
26+
[python-sdk#423](https://github.com/modelcontextprotocol/python-sdk/issues/423)
27+
and
28+
[python-sdk#1844](https://github.com/modelcontextprotocol/python-sdk/issues/1844).
29+
830
## [0.5.1] - 2026-08-14
931

1032
### Fixed

‎homebox-mcp/app/server.py‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,24 @@ async def api_status(request):
613613
# When mounting it under a custom Starlette app, that lifespan MUST be passed
614614
# to the parent app, otherwise the first request fails with
615615
# "RuntimeError: Task group is not initialized" (nested lifespans are ignored).
616-
mcp_app = mcp.http_app(transport="sse")
616+
#
617+
# transport="http" (Streamable HTTP) rather than the legacy "sse" transport:
618+
# the old SSE transport splits a session across two independent HTTP requests
619+
# (a long-lived GET stream that hands out a session_id, plus separate POST
620+
# .../messages?session_id=... calls) with no server-side check that the GET
621+
# side has actually finished the initialize handshake before POSTs on that
622+
# session are accepted. If a client (re)opens a second GET/sse connection —
623+
# which mcp-remote can do — requests can race and land on a session before it
624+
# is marked initialized, raising "Received request before initialization was
625+
# complete" and making every tool call fail. Streamable HTTP uses a single
626+
# endpoint keyed by an `Mcp-Session-Id` header instead of two endpoints
627+
# racing over a session_id query param, which avoids this class of bug.
628+
# See https://github.com/modelcontextprotocol/python-sdk/issues/423 and
629+
# https://github.com/modelcontextprotocol/python-sdk/issues/1844.
630+
# `path="/sse"` keeps the existing endpoint URL working (mcp-remote already
631+
# tries Streamable HTTP first against whatever URL it's given before falling
632+
# back to legacy SSE), so no client-side reconfiguration is required.
633+
mcp_app = mcp.http_app(transport="http", path="/sse")
617634

618635
# Create custom Starlette app with MCP mounted and auth middleware
619636
app = Starlette(
@@ -633,7 +650,7 @@ async def api_status(request):
633650
logger.info(f"Starting Homebox MCP Server on {config.server_host}:{config.server_port}")
634651
logger.info(f"Connecting to Homebox at: {config.homebox_url}")
635652
logger.info(f"Dashboard available at: http://{config.server_host}:{config.server_port}/")
636-
logger.info(f"MCP SSE endpoint at: http://{config.server_host}:{config.server_port}/sse")
653+
logger.info(f"MCP endpoint (Streamable HTTP) at: http://{config.server_host}:{config.server_port}/sse")
637654

638655
if config.mcp_auth_enabled:
639656
logger.info("MCP Authentication: ENABLED - Bearer token required")

‎homebox-mcp/config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: "Homebox MCP Server"
33
description: "MCP Server to manage Homebox inventory via AI"
4-
version: "0.5.1"
4+
version: "0.5.2"
55
slug: "homebox-mcp"
66
url: "https://github.com/MB901/homebox-mcp"
77
init: false

0 commit comments

Comments
 (0)