hermes - 💡(How to fix) Fix [Bug]: ERROR tools.mcp_tool: MCP tool playwright/browser_run_code call failed: Session terminated - From Gateway sessions [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#18790Fetched 2026-05-03 04:54:19
View on GitHub
Comments
1
Participants
1
Timeline
5
Reactions
0
Author
Participants
Timeline (top)
labeled ×4commented ×1

Error Message

ERROR tools.mcp_tool: MCP tool playwright/browser_run_code call failed: Session terminated ERROR tools.mcp_tool: MCP tool playwright/browser_run_code call failed: Session terminated

Additional Logs / Traceback (optional)

Root Cause

This is a confirmed upstream issue with @playwright/mcp: microsoft/playwright-mcp#1045

Code Example

==> /opt/data/logs/gateway.log <==
ERROR tools.mcp_tool: MCP tool playwright/browser_run_code call failed: Session terminated

---



---

Call 1: browser_navigate → works, creates page
Call 2: browser_snapshot  → "Session terminated" (new session, no page)

---

_SESSION_EXPIRED_MARKERS: tuple = (
    "invalid or expired session",
    "expired session",
    "session expired",
    "session not found",
    "unknown session",
    "session terminated",  # ← ADD THIS
)
RAW_BUFFERClick to expand / collapse

Bug Description

From a Hermes gateway client: Remote Playwright MCP calls results failed while same from Hermes Cli runs without issues.

Steps to Reproduce

From (Weixin) gateway client: Test remote playwright mcp using de.trip.com. Hermes agent responses:

  • I'll test the MCP Playwright browser by navigating to de.trip.com and taking a screenshot to verify it's working.
  • Let me get a snapshot of the page content:
  • Session terminated. Let me reconnect and navigate again:
  • The MCP Playwright server appears to be terminated/unavailable. Let me check if it can be restarted by looking at the server status:
  • The first navigation actually worked (loaded de.trip.com successfully), but then the session terminated. Let me check the MCP configuration:
  • I can see the MCP Playwright server is configured at http://mcp-playwright.mcp-playwright.svc.cluster.local:8931/mcp. The first navigation actually worked - the page loaded successfully:
  • URL: https://de.trip.com/
  • Title: "Buche günstige Flüge, Hotels, Mietwagen, Zugtickets und mehr | Trip.com"
  • Console: 19 errors, 2 warnings However, the session terminated shortly after. etc etc...

Expected Behavior

Hermes Cli as well as Gateway client expect a successfully response back.

Actual Behavior

==> /opt/data/logs/gateway.log <== ERROR tools.mcp_tool: MCP tool playwright/browser_run_code call failed: Session terminated

Affected Component

Gateway (Telegram/Discord/Slack/WhatsApp)

Messaging Platform (if gateway-related)

No response

Debug Report

==> /opt/data/logs/gateway.log <==
ERROR tools.mcp_tool: MCP tool playwright/browser_run_code call failed: Session terminated

Operating System

Docker

Python Version

No response

Hermes Version

v0.12.0

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

Root Cause Analysis

This is a confirmed upstream issue with @playwright/mcp: microsoft/playwright-mcp#1045

The Problem

When using MCP Playwright via remote HTTP (like your setup), each tool call creates a new session, causing the browser state to be lost between calls:

Call 1: browser_navigate → works, creates page
Call 2: browser_snapshot  → "Session terminated" (new session, no page)

The MCP server uses session IDs to track browser contexts. When the client makes subsequent calls, the MCP server may assign a new session ID, creating a fresh browser context with no pages open.

Why CLI Works

In CLI mode:

  1. You run hermes → starts Python process
  2. First tool call → connects to MCP server, creates session A
  3. Second tool call → reuses the same session A
  4. State persists because the connection never drops

In Gateway mode:

  1. Message arrives → Gateway spawns handler
  2. Tool call → connects to MCP server, creates session A
  3. Response sent → handler ends
  4. Next message → new handler, new connection, session B created
  5. Session A is orphaned/garbage-collected by Playwright MCP

Proposed Fix (optional)

Add "session terminated" to retry markers tools/mcp_tool.py line 1664:

_SESSION_EXPIRED_MARKERS: tuple = (
    "invalid or expired session",
    "expired session",
    "session expired",
    "session not found",
    "unknown session",
    "session terminated",  # ← ADD THIS
)

Are you willing to submit a PR for this?

  • I'd like to fix this myself and submit a PR

extent analysis

TL;DR

The most likely fix is to modify the tools/mcp_tool.py file to add "session terminated" to the retry markers, allowing the system to retry the MCP tool call when a session is terminated.

Guidance

  • Review the proposed fix in tools/mcp_tool.py and apply it to the codebase to add "session terminated" to the _SESSION_EXPIRED_MARKERS tuple.
  • Verify that the MCP server is configured correctly and that the session IDs are being properly tracked and reused between tool calls.
  • Consider implementing a mechanism to persist the session state between handler invocations in Gateway mode to prevent session termination.
  • Test the modified code with the remote Playwright MCP calls to ensure that the session termination issue is resolved.

Example

_SESSION_EXPIRED_MARKERS: tuple = (
    "invalid or expired session",
    "expired session",
    "session expired",
    "session not found",
    "unknown session",
    "session terminated",  # Add this line
)

Notes

The proposed fix assumes that the issue is caused by the session termination and that adding "session terminated" to the retry markers will allow the system to recover from this error. However, the root cause of the issue may be more complex and require additional debugging and testing.

Recommendation

Apply the proposed fix by modifying the tools/mcp_tool.py file to add "session terminated" to the retry markers, as this is a straightforward and targeted solution to the identified issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING