Description
Hello,
I noticed that when using custom tools locally with LangChain, the RunnableConfig
parameter is automatically injected into the tool function if declared in the signature. This allows easy access to the config within the tool.
However, when using MCP tools via the langchain-mcp-adapters, the RunnableConfig
parameter is not injected or populated automatically in the remote MCP tool execution context. This means MCP tools do not receive the RunnableConfig
object like local tools do.
Is this an expected behavior due to the remote nature of MCP tools? Or is there a recommended way to pass or access RunnableConfig
in MCP tools?
This is my tool code:-
@mcp.tool()
def medical_history_tool(content: str, config: RunnableConfig) -> str:
"""
Retrieves the medical history and symptoms for a patient from DynamoDB.
Args:
content (str): The query or parameters for retrieving medical history
config (RunnableConfig): Configuration containing patient_id.
Returns:
str: A formatted string containing the patient's medical history and symptom information
"""
pass
And this is the error i am getting:-
Name: medical_history_tool
Error: ToolException('Error executing tool medical_history_tool: 1 validation error for medical_history_toolArguments\nconfig\n Field required [type=missing, input_value={\'content\': "Retrieve the... history and symptoms."}, input_type=dict]\n For further information visit https://errors.pydantic.dev/2.11/v/missing')
Please fix your mistakes.
2025-05-24 09:30:56 - ragent.log_utils - INFO - Agent: content='Error: ToolException(\'Error executing tool medical_history_tool: 1 validation error for medical_history_toolArguments\\nconfig\\n Field required [type=missing, input_value={\\\'content\\\': "Retrieve the... history and symptoms."}, input_type=dict]\\n For further information visit https://errors.pydantic.dev/2.11/v/missing\')\n Please fix your mistakes.' name='medical_history_tool' id='e10d6d12-9578-482f-abd1-c3261c84e06a' tool_call_id='call_A2lgzLipSQTQ0vdqm8CPfMVl' status='error'
It would be helpful if the documentation could clarify this difference or provide best practices to handle config passing to MCP tools.
Thanks for your help!