Add mcp_server_name to tool metadata in convert_mcp_tool_to_langchain_tool#488
Open
RobinBaldeo wants to merge 2 commits intolangchain-ai:mainfrom
Open
Add mcp_server_name to tool metadata in convert_mcp_tool_to_langchain_tool#488RobinBaldeo wants to merge 2 commits intolangchain-ai:mainfrom
RobinBaldeo wants to merge 2 commits intolangchain-ai:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #484.
When
MultiServerMCPClient.get_tools()aggregates tools from multiple MCP servers, the server identity is currently only recoverable by parsing the prefix string fromtool.name(and only whentool_name_prefix=True). Iftool_name_prefix=False, the server identity is lost entirely after the aggregate list is returned.This PR writes
tool.metadata["mcp_server_name"]at the point where each tool is constructed inconvert_mcp_tool_to_langchain_tool. Theserver_nameis already threaded end-to-end through the call chain (get_tools→load_mcp_tools→convert_mcp_tool_to_langchain_tool), so this is an additive change with no signature impact.This change is purely additive — it adds a new top-level key (
mcp_server_name) totool.metadata. Existing keys and consumers reading them are unaffected.Use case: building a framework where MCP tools from multiple servers need attribution for telemetry and UI rendering. Parsing
tool.name.split("__")[0]is fragile and doesn't work whentool_name_prefix=False.Collision behavior: if an MCP server's
annotationsfield contains a key namedmcp_server_name, it will be overwritten by the client-configured server key (the key inself.connections). This is intentional — the metadata tag reflects client-side configuration, not a server self-declaration, so the value is consistent regardless of server behavior.Tests:
test_get_tools_metadata_has_server_namecovering bothtool_name_prefix=Trueandtool_name_prefix=False.test_load_mcp_tools_with_annotationsto include the new key in its expected dict.63 passed, 2 skippedlocally.