AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

LangChain MCP Adapter Lacks Support For Server-Sent Notifications And Progress

The Python LangChain MCP adapter does not expose handlers for MCP server notifications (e.g., tool list changes) or progress updates, contrary to the JavaScript SDK. This prevents dynamic tool updates and progress visibility in MCP-based agents.

mediumConfidence 85%LangchainMemoryChat Models

Origin Analysis

In `langchain_mcp_adapters/client.py`, `MultiServerMCPClient` creates `ClientSession` instances without passing the `message_handler` and `progress_handler` parameters. Consequently, incoming server notifications and progress messages are silently discarded by the underlying MCP client.
1. Start an MCP server that emits `notifications/tools/list_changed` or progress notifications. 2. Connect to it using `MultiServerMCPClient`. 3. Trigger a tool list change on the server. 4. Observe that the client's cached tool list does not update and no progress callbacks are invoked.

Fixing Code Block

# In langchain_mcp_adapters/client.py from typing import Any, Callable, Dict, Optional from mcp import ClientSession from mcp.types import ProgressNotification, ServerNotification class MultiServerMCPClient: def __init__( self, connections: Optional[Dict[str, Any]] = None, notification_handler: Optional[Callable[[ServerNotification], None]] = None, progress_handler: Optional[Callable[[ProgressNotification], None]] = None, ): self.connections = connections or {} self.notification_handler = notification_handler self.progress_handler = progress_handler self.servers: Dict[str, ClientSession] = {} self._tools_by_server: Dict[str, list] = {} async def __aenter__(self): for name, config in self.connections.items(): transport = create_transport(config.transport, config.url, config.headers) read_stream, write_stream = await transport.connect() session = ClientSession( read_stream, write_stream, message_handler=self.notification_handler, progress_handler=self.progress_handler, ) await session.initialize() self.servers[name] = session self._tools_by_server[name] = await session.list_tools() return self
Add optional `notification_handler` and `progress_handler` parameters to `MultiServerMCPClient` and pass them to the underlying `ClientSession`. This allows users to supply callbacks that are invoked for every server notification and progress update. The default value `None` preserves backward compatibility.

Edge Case Audit

Passing handler functions with incorrect signatures will raise runtime errors during message processing. Third-party MCP servers may flood the client with notifications, potentially overwhelming the callback; users should debounce refresh operations. Rollback: revert the constructor to its original signature and remove the two new arguments; existing installations will continue to work unchanged because the new parameters default to `None`.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state