{"record":{"id":"6fec500a35843752","repo":"langchain-ai/deepagents","slug":"cannot-reconfigure-mcp-session-manager-after-sessi","errorCode":null,"errorMessage":"Cannot reconfigure MCP session manager after sessions are active","messagePattern":"Cannot reconfigure MCP session manager after sessions are active","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/mcp_tools.py","lineNumber":680,"sourceCode":"            connections: Connection configs keyed by server name.\n\n        Raises:\n            RuntimeError: If the manager is closed or reconfigured\n                incompatibly after sessions already exist.\n        \"\"\"\n        if self._closed:\n            msg = \"Cannot configure a closed MCP session manager\"\n            raise RuntimeError(msg)\n\n        if not self._entries:\n            self._connections = dict(connections)\n            return\n\n        if _connections_signature(self._connections) != _connections_signature(\n            connections,\n        ):\n            msg = \"Cannot reconfigure MCP session manager after sessions are active\"\n            raise RuntimeError(msg)\n        self._connections = dict(connections)\n\n    async def get_session(self, server_name: str) -> ClientSession:\n        \"\"\"Return a cached session for `server_name`, creating it lazily.\"\"\"\n        entry = self._entries.get(server_name)\n        if entry is not None:\n            return entry.session\n\n        lock = self._get_lock(server_name)\n        async with lock:\n            entry = self._entries.get(server_name)\n            if entry is not None:\n                return entry.session\n\n            entry = await self._create_entry(server_name)\n            self._entries[server_name] = entry\n            return entry.session\n","sourceCodeStart":662,"sourceCodeEnd":698,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/mcp_tools.py#L662-L698","documentation":"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.","triggerScenarios":"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.","commonSituations":"Hot-reloading an MCP config file after sessions opened; adding a new MCP server at runtime without recreating the manager.","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"],"exampleFix":"// before\nawait manager.configure(old_conns)\nawait manager.get_session('fs')\nawait manager.configure(new_conns)  # raises\n// after\nawait manager.configure(new_conns)  # configure first\nawait manager.get_session('fs')","handlingStrategy":"validation","validationCode":"from mcp_tools import _connections_signature  # or compare your own canonical form\nunchanged = _connections_signature(current) == _connections_signature(proposed)\nif not unchanged:\n    await manager.close(); manager = MCPSessionManager()","typeGuard":null,"tryCatchPattern":"try:\n    await manager.configure(new_connections)\nexcept RuntimeError as e:\n    if 'reconfigure' in str(e):\n        await manager.close()\n        manager = MCPSessionManager()\n        await manager.configure(new_connections)\n    else:\n        raise","preventionTips":["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"],"tags":["mcp","lifecycle","configuration"],"backgroundTag":"manager-already-closed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}