Skip to content

Conversation

@sydney-runkle
Copy link
Collaborator

@sydney-runkle sydney-runkle commented Sep 25, 2025

Introduces a callback system for monitoring MCP server events during tool execution.

Callbacks contain context with server name and tool name and are applied to all servers for a given client.

New API:

from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_mcp_adapters.callbacks import Callbacks

async def on_progress(progress, total, message, context):
    print(f"[{context.server_name}:{context.tool_name}] {progress}/{total}")

client = MultiServerMCPClient(connections={...}, callbacks=Callbacks(on_progress=on_progress))

Callbacks has the potential to be extended quite broadly to support a variety of notification hooks. We simply match signatures from mcp + add a final context arg which is easily extensible as well.

What's Added:

  • CallbackContext - provides server/tool context to callbacks
  • Callbacks - main configuration class
  • LoggingMessageCallback & ProgressCallback - callback protocols w/ context
  • Optional callbacks parameter on MultiServerMCPClient

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, otherwise LGTM

def __init__(self, connections: dict[str, Connection] | None = None) -> None:
def __init__(
self,
connections: dict[str, Connection] | None = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is called mcpServers in JS, do we want to align here? Happy to move to connections and deprecated mcpServer (but keep functionality alive)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to leave as is for now based on offline disc

@sydney-runkle sydney-runkle merged commit 219b60c into main Sep 25, 2025
4 of 6 checks passed
@sydney-runkle sydney-runkle deleted the sr/just-callbacks branch September 25, 2025 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants