Skip to content

MCP tools with a parameter named "config" silently broken by LangChain's RunnableConfig injection #532

Description

Bug

When an MCP tool has an input parameter named config, convert_mcp_tool_to_langchain_tool produces a StructuredTool that silently replaces the user's config value with LangChain's internal RunnableConfig dict at invocation time.

Reproduction

from mcp.types import Tool as MCPTool
from langchain_mcp_adapters.tools import convert_mcp_tool_to_langchain_tool

tool = MCPTool(
    name="my_tool",
    description="A tool with a config param",
    inputSchema={
        "type": "object",
        "properties": {
            "config": {"type": "string", "description": "User config value"},
            "query": {"type": "string"},
        },
        "required": ["config", "query"],
    },
)

lc_tool = convert_mcp_tool_to_langchain_tool(session, tool)
# When invoked with {"config": "my_value", "query": "hello"},
# the coroutine receives config={"callbacks": ..., "tags": ..., ...} (a RunnableConfig)
# instead of "my_value"

Root cause

The execution path in BaseTool.arun (langchain-core):

  1. _to_args_and_kwargs unpacks the tool input dict into tool_kwargs — so tool_kwargs["config"] = "my_value"
  2. Then LangChain checks _get_runnable_config_param(func_to_check) against StructuredTool._arun, which has config: RunnableConfig in its signature
  3. This returns "config", and the code does tool_kwargs["config"] = configoverwriting the user's value with the internal RunnableConfig

The same applies to run_manager and callbacks (via FILTERED_ARGS).

Version

  • langchain-mcp-adapters: 0.2.2
  • langchain-core: 0.3.x

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions