Skip to content

vMCP loses stateful backend sessions between tool calls after Serve/core migration #7069

Open

Description

@sym-stiller

Bug description

The current vMCP tool-dispatch path appears to create, initialize, and close a
new backend MCP client for each call, bypassing the persistent backend
connection held by the client session. This loses session-scoped backend state
between consecutive tool calls.

Playwright MCP illustrates the impact: navigation succeeds, but the next
evaluation/snapshot sees about:blank. With --isolated, a new backend session
creates a fresh browser context. The issue is ToolHive's backend-session
lifecycle, not Playwright's isolation setting.

Steps to reproduce

Aggregate a Playwright MCPServer using streamable-http and --isolated in a
VirtualMCPServer. Connect the MCP client to the vMCP endpoint, not directly
to the backend proxy.

Run these tools sequentially without closing the browser or intentionally
reconnecting. Use the corresponding prefixed names advertised by the gateway.
The URL below is an anonymized placeholder; substitute any reachable test page.

  1. Call browser_navigate:

    {"url":"https://example.com"}
  2. Call browser_evaluate:

    {
      "function": "() => ({url: location.href, title: document.title, readyState: document.readyState})"
    }
  3. Call browser_snapshot:

    {"depth":3,"boxes":true}

The same failure was reproduced with navigation, evaluation, and snapshot as
sequential inner calls in one execute_tool_script invocation.

Expected behavior

Consecutive calls within the same client MCP session should reuse the backend
session and preserve its state:

  • Evaluation and snapshot should inspect the page reached by navigation.
  • Tabs, browser history, and DOM state should remain available until the
    session/browser is closed or expires.
  • Sequential calls inside code mode should retain that same backend state.
  • Separate clients should remain isolated; a global shared browser is not
    equivalent to session-scoped connection reuse.

Actual behavior

Navigation reports the successfully loaded page. The subsequent evaluation
returns:

{
  "url": "about:blank",
  "title": "",
  "readyState": "complete"
}

The snapshot is empty and reports Page URL: about:blank. Sequential code-mode
calls produce the same contrast: navigation reaches the site, while
evaluation/snapshot operate on a blank page.

An in-memory synthetic form created in one call is also absent in the next,
demonstrating state loss independently of the test site's UI.

Navigation and inspection do work inside one browser_run_code_unsafe
invocation, but this does not restore composition of separate MCP tools.

Environment (if relevant)

  • ToolHive operator, proxyrunner, and vMCP configured at v0.60.0, deployed
    on Kubernetes with Redis session storage.
  • Backend: @playwright/mcp v0.0.83, streamable-http,
    --isolated.
  • vMCP code mode enabled; reproduced with both separate tool calls and
    sequential code-mode calls.

Additional context

Current source-level call chain

The following path was inspected in both v0.60.0 (the observed deployment) and
v0.63.0 (source inspection):

  1. coreToolHandler
    checks session identity, then calls s.core.CallTool(...).
  2. coreVMCP.CallTool
    calls c.backendClient.CallTool(...).
  3. legacyCallTool
    calls h.clientFactory(...), defers c.Close(), and initializes the newly
    created client before executing the tool.

The retained-connection path still exists in
defaultMultiSession.CallTool,
which retrieves a connection from the session's connection map. The Serve-path
tool handler appears not to use it.

Code mode likewise
re-enters d.VMCP.CallTool for each inner call,
explaining why a single outer script does not preserve the browser state.

Suspected regression point

This history suggests the original session-reuse behavior was implemented but
lost at the dispatch seam.

Related issues:
stacklok/toolhive#3062
was closed as completed;
stacklok/toolhive#2417
remains open and describes backend pooling/state loss.

Suggested regression coverage

A small stateful fake backend should be sufficient: return or increment a
per-backend-session value, make two consecutive calls through the production
vMCP path, and assert the same backend session/state is used. Repeat for
sequential code-mode calls, assert that two client sessions do not share state,
and verify cleanup on termination.

The desired fix is session-scoped execution while preserving current core
admission and identity checks—not disabling Playwright isolation or sharing
one browser across users.

Activity

  1. FOWEPJF255 commented on Nov 7, 2026

    @FOWEPJF255

    I'd like to work on this.

    I confirmed that current main still routes the Serve path through coreToolHandler -> core.CallTool -> httpBackendClient.legacyCallTool, where each call creates, initializes, and closes a backend client. The legacy defaultMultiSession.CallTool path instead reuses the session-owned connection.

    If assigned, I'll start with a focused regression test proving that two sequential tool calls preserve backend session state, then keep the fix scoped to restoring that lifecycle on the Serve/core path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageIssue needs initial triage by a maintainer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions