Repository navigation
Description
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.
-
Call
browser_navigate:{"url":"https://example.com"} -
Call
browser_evaluate:{ "function": "() => ({url: location.href, title: document.title, readyState: document.readyState})" } -
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/mcpv0.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):
coreToolHandler
checks session identity, then callss.core.CallTool(...).coreVMCP.CallTool
callsc.backendClient.CallTool(...).legacyCallTool
callsh.clientFactory(...), defersc.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
- stacklok/toolhive#3906
introduced session-scoped tool handlers. This architecture was enabled by
default in
stacklok/toolhive#4091. - Before the production Serve/core switch,
GetAdaptedToolsdelegated tocapturedSess.CallTool. - stacklok/toolhive#5556,
commitee29dffe, merged on 2026-06-23, routed productionserver.New
throughcore.New + Serve. Git/tag inspection places this change in
v0.30.1; v0.30.0 still uses the earlier production route. - Its
integration-test diff
replaced the assertion that the mock session'sCallToolwas invoked with
an assertion on a mockedBackendClient.CallToolresult. The
current test comment
explicitly states that the factory session'sCallToolis bypassed.
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
FOWEPJF255 commentedon Nov 7, 2026
I'd like to work on this.
I confirmed that current
mainstill routes the Serve path throughcoreToolHandler -> core.CallTool -> httpBackendClient.legacyCallTool, where each call creates, initializes, and closes a backend client. The legacydefaultMultiSession.CallToolpath 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.