langchain-ai/deepagents · error · RuntimeError
Cannot reconfigure MCP session manager after sessions are ac
Error message
Cannot reconfigure MCP session manager after sessions are active
What it means
Once sessions exist, configure() only accepts connections whose signature (_connections_signature) matches the existing ones. A different signature would strand live sessions, so it raises RuntimeError.
Source
Thrown at libs/code/deepagents_code/mcp_tools.py:680
connections: Connection configs keyed by server name.
Raises:
RuntimeError: If the manager is closed or reconfigured
incompatibly after sessions already exist.
"""
if self._closed:
msg = "Cannot configure a closed MCP session manager"
raise RuntimeError(msg)
if not self._entries:
self._connections = dict(connections)
return
if _connections_signature(self._connections) != _connections_signature(
connections,
):
msg = "Cannot reconfigure MCP session manager after sessions are active"
raise RuntimeError(msg)
self._connections = dict(connections)
async def get_session(self, server_name: str) -> ClientSession:
"""Return a cached session for `server_name`, creating it lazily."""
entry = self._entries.get(server_name)
if entry is not None:
return entry.session
lock = self._get_lock(server_name)
async with lock:
entry = self._entries.get(server_name)
if entry is not None:
return entry.session
entry = await self._create_entry(server_name)
self._entries[server_name] = entry
return entry.session
View on GitHub (pinned to a1af029e6e)
Solutions
- Close the manager and create a new one with the new connections before opening sessions
- Apply all config changes before the first get_session() call
- Ensure the reconfiguration is signature-equivalent (same connections, different object identity) if that is the intent
Example fix
// before
await manager.configure(old_conns)
await manager.get_session('fs')
await manager.configure(new_conns) # raises
// after
await manager.configure(new_conns) # configure first
await manager.get_session('fs') Defensive patterns
Strategy: validation
Validate before calling
from mcp_tools import _connections_signature # or compare your own canonical form
unchanged = _connections_signature(current) == _connections_signature(proposed)
if not unchanged:
await manager.close(); manager = MCPSessionManager() Try / catch
try:
await manager.configure(new_connections)
except RuntimeError as e:
if 'reconfigure' in str(e):
await manager.close()
manager = MCPSessionManager()
await manager.configure(new_connections)
else:
raise Prevention
- Apply all config changes before the first get_session call
- Treat the manager as immutable after sessions open; recreate for changes
- Cache the connections signature to detect real changes cheaply
When it happens
Trigger: Calling configure() with a changed set of server connections while active sessions exist; passing semantically equivalent configs is allowed, differing ones (added/removed/changed servers) are not.
Common situations: Hot-reloading an MCP config file after sessions opened; adding a new MCP server at runtime without recreating the manager.
Related errors
- Invalid MCP server name {server_name!r}: token storage names
- Server '{server_name}' uses {transport!r} transport; OAuth l
- MCPServerInfo {self.name!r}: status={self.status!r} cannot c
- Cannot configure a closed MCP session manager
- Cannot create an MCP session after cleanup
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/6fec500a35843752.
Report an issue: GitHub.