While connecting my LibreChat MCP client via the streamable-http transport always fails immediately after session creation with the following warning:
Failed to validate request: Context is not available outside of a request
The HTTP layer itself is healthy — every POST /mcp/ returns 200 OK and a new session ID is created by StreamableHTTP session manager. The failure occurs in the background task immediately after, before any tool call is ever made.
Steps to Reproduce
- Enable Context Agent in Nextcloud
- Configure an external MCP client (in my case LibreChat) using
streamable-http transport pointing to:
https://<nextcloud>/index.php/apps/app_api/proxy/context_agent/mcp/
- Send a valid
initialize JSON-RPC request with Authorization: Bearer <app-password>
- Observe the log
Logs
INFO - Created new transport with session ID: 3ff000a886594d35ba3f46e00510a786
INFO - "POST /mcp/ HTTP/1.0" 200 OK
WARNING - Failed to validate request: Context is not available outside of a request
This repeats identically on every connection attempt regardless of the authentication method used.
Root Cause
In my point of view the streamable-http transport processes incoming MCP JSON-RPC messages asynchronously in a background task, outside of the original FastAPI request lifecycle. Seems the request validation relies on FastAPI context variables (e.g. request object) to identify the calling user. Because these context variables are not propagated into the background task, the validation crashes with a ValueError and the session is dropped immediately.
Expected Behaviour
The MCP session should initialize successfully and the tools should be available to the external client.
While connecting my LibreChat MCP client via the
streamable-httptransport always fails immediately after session creation with the following warning:Failed to validate request: Context is not available outside of a request
The HTTP layer itself is healthy — every
POST /mcp/returns200 OKand a new session ID is created byStreamableHTTP session manager. The failure occurs in the background task immediately after, before any tool call is ever made.Steps to Reproduce
streamable-httptransport pointing to:https://<nextcloud>/index.php/apps/app_api/proxy/context_agent/mcp/initializeJSON-RPC request withAuthorization: Bearer <app-password>Logs
Root Cause
In my point of view the
streamable-httptransport processes incoming MCP JSON-RPC messages asynchronously in a background task, outside of the original FastAPI request lifecycle. Seems the request validation relies on FastAPI context variables (e.g.requestobject) to identify the calling user. Because these context variables are not propagated into the background task, the validation crashes with aValueErrorand the session is dropped immediately.Expected Behaviour
The MCP session should initialize successfully and the tools should be available to the external client.