Let Claude AI to self reconnect to the mcp
I have the playwright mcp, each time it closed the browser, I must self reconnect it. How to let the AI to overcome and reconnect by itself or any mechanism to auto reconnect?
https://github.com/anthropics/claude-code/issues/605
Hey, I don't work for Anthropic, but from what I've gathered by digging through the docs and changelogs, here's what's likely happening.
The core issue is that the Playwright MCP server is a separate process that Claude Code launches. It sounds like the Playwright server is designed to exit its process once the browser it's controlling is closed. When that process dies, the connection from Claude Code is permanently broken for that session.
The AI itself doesn't have a tool to "re-launch an MCP server"; it can only use the tools the server provides while it's running.
The good news is that Claude Code does have an auto-reconnect mechanism, but it's specifically for remote sse (Server-Sent Events) servers. I found this in the changelog:
1.0.18
- ...
- Added auto-reconnection for MCP SSE connections on disconnect
This implies that for local stdio servers (which the Playwright one almost certainly is), this functionality doesn't exist. Once the process is gone, it's gone.
Possible Workarounds
Here are a couple of approaches you could try:
-
Treat it as a Single Session: The easiest workaround is to change how you prompt Claude. Instead of closing the browser and then asking it to do more, try to keep the browser open for the entire duration of your task.
- Start your task.
- Have Claude do everything it needs to do with Playwright.
- Only at the very end of the entire workflow, ask it to close the browser.
-
Create a Wrapper Script (More Advanced): You could create a simple shell script that automatically restarts the Playwright MCP server in a loop.
For example, create a file named
run-playwright-mcp.sh:#!/bin/bash echo "Starting persistent Playwright MCP server..." while true do # Run the actual npx command for the server npx -y @playwright/mcp@latest echo "Playwright MCP server exited. Restarting in 2 seconds..." sleep 2 doneMake it executable:
chmod +x run-playwright-mcp.sh.Then, remove your old MCP config and add a new one pointing to this script:
# First, remove the old one claude mcp remove playwright # Then add it back using your new wrapper script claude mcp add playwright -- ./run-playwright-mcp.shThis way, even if the Playwright server exits after the browser closes, your script will immediately restart it, and Claude Code should be able to keep communicating with it. It's a bit of a hack, but it might give you that "always-on" feel you're looking for.
Hope this helps explain the behavior! It seems less like a bug and more like a design choice in how stdio servers work vs. remote sse servers.
I don't think that will work as I have an active mcp server that I do dev work on and restart often (so its up), but claude currently does not periodically poll to establish the connection again. Intuitively I say this would be a simple fix for anthropic, but I have seen people complaining about this since its inception of mcp...so is there more to this?
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.