-
Notifications
You must be signed in to change notification settings - Fork 203
vMCP session close fails auth: no identity in termination context #4573
Description
Bug Report
Reported by: Gaston (external user) on Discord, observed on ToolHive operator v0.12.5
Description
When the vMCP session manager terminates a session, the close/DELETE request to backend MCP servers fails with:
ERROR: failed to send close request: Delete "http://mcp-playwright-proxy.mcp.svc.cluster.local:8080/mcp/": authentication failed for backend playwright: no identity found in context
ERROR: failed to send close request: Delete "http://mcp-fetch-proxy.mcp.svc.cluster.local:8080/mcp/": authentication failed for backend fetch: no identity found in context
ERROR: failed to send close request: Delete "http://mcp-mkp-proxy.mcp.svc.cluster.local:8080/mcp/": authentication failed for backend mkp: no identity found in context
These errors appear frequently in vMCP logs. While no visible functionality is broken, backend sessions are likely never properly closed, potentially leaking sessions on backend MCP servers.
Suspected Root Cause (Needs Confirmation)
Manager.Terminate() in pkg/vmcp/server/sessionmanager/session_manager.go appears to create a fresh context from context.Background() with no identity. This empty context would flow through the close chain to the authRoundTripper, where auth strategies (UpstreamInjectStrategy, TokenExchangeStrategy) call auth.IdentityFromContext(ctx) and fail because no identity was set.
Suspected call chain:
Manager.Terminate()→multiSess.Close()→ per-backendconn.Close()mcpSession.Close()→mcp-goSDKClient.Close()→ sends HTTP DELETEauthRoundTripper.RoundTrip()→authStrategy.Authenticate(ctx, req, config)- Auth strategy calls
auth.IdentityFromContext(ctx)→(nil, false)→ error
This needs to be confirmed with reproduction and debugging before implementing a fix.
Impact
- Backend MCP server sessions may not be properly closed
- Potential session/resource leaks on backend servers at scale
- Log noise from repeated errors
Related
- Part of: stacklok/stacklok-epics#262 (Epic: Horizontal Scaling for vMCP)
🤖 Generated with Claude Code