convert_mcp_tool_to_langchain_tool(
session: ClientSession | None,
tool: MCPTool,
*,
connection: Connection | None| Name | Type | Description |
|---|---|---|
session* | ClientSession | None | MCP client session |
tool* | MCPTool | MCP tool to convert |
connection | Connection | None | Default: NoneOptional connection config to use to create a new session
if a |
callbacks | Callbacks | None | Default: None |
tool_interceptors | list[ToolCallInterceptor] | None | Default: None |
server_name | str | None | Default: None |
tool_name_prefix | bool | Default: False |
handle_tool_errors | bool | Default: True |
Convert an MCP tool to a LangChain tool.
NOTE: this tool can be executed only in a context of an active MCP client session.
Optional callbacks for handling notifications and events
Optional list of interceptors for tool call processing
Name of the server this tool belongs to
If True and server_name is provided, the tool name will be
prefixed w/ server name (e.g., "weather_search" instead of "search")
If True (default), an MCP tool execution error
(CallToolResult(isError=True)) is returned to the model as a
ToolMessage with status="error" so the agent can self-correct
instead of crashing the run. If False, a ToolException is raised
instead (legacy behavior). Transport/session failures and
content-conversion errors (e.g. unsupported audio content) always
raise regardless of this setting; only MCP execution errors
(isError=True) are governed by it.