Skip to content

Conversation

@amirejaz
Copy link
Contributor

Problem

Playwright MCP servers were losing session state between tool calls, causing errors like "Session not found" when attempting to use browser context from a previous navigation. This occurred because:

  1. Each tool call created a new backend connection without forwarding the client's MCP session ID
  2. Backend servers couldn't associate requests with existing sessions
  3. Stateful operations (like browser navigation) failed on subsequent calls

Solution

This PR implements session ID propagation from the vMCP server to backend MCP servers:

  • Session ID Context: Added WithSessionID() and SessionIDFromContext() helpers in pkg/vmcp/discovery/context.go to store session ID in request context
  • Middleware Propagation: Updated discovery middleware to propagate session ID into request context for subsequent handlers
  • Backend Client: Added sessionIDPropagatingRoundTripper to extract session ID from context and forward it as Mcp-Session-Id header to backend servers
  • Removed Redundant Initialization: Removed initialize() calls from individual tool invocations since session state is now maintained via headers

Changes

  • pkg/vmcp/discovery/context.go: Added session ID context helpers
  • pkg/vmcp/discovery/middleware.go: Propagate session ID to context
  • pkg/vmcp/client/client.go: Forward session ID to backend servers via RoundTripper

Testing

  • Verified Playwright MCP server maintains browser context across multiple tool calls
  • Confirmed session ID is correctly forwarded in HTTP headers
  • Tested with multiple sequential tool calls (navigate → snapshot → click)

@amirejaz amirejaz marked this pull request as draft December 15, 2025 12:08
@github-actions github-actions bot added the size/XS Extra small PR: < 100 lines changed label Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Extra small PR: < 100 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants