Adapt MCP tools into LangChain tools suitable for create_agent.
Convert one MCP tool into a LangChain tool.
The returned tool calls the MCP tool through client on every invocation.
FastMCP clients are reentrant, so the tool can open the client itself
whether or not a connection is already held elsewhere.
A server that needs input mid-call is answered with a LangGraph
interrupt() when client carries the interrupt-driving sentinel handler
that MCPAdapter installs — so a human answers and the call resumes, see
langchain.mcp.elicitation. A client that carries a different handler (a
caller's own) uses that handler instead, and one with no handler simply
never gets asked. Which path a call takes is read off the client, so the
behavior matches whatever it was armed with.
An MCP tool that runs and reports failure reaches the model as a
ToolMessage with status="error", carrying the server's own error
content, so an agent can correct itself and retry. Transport failures and
unconvertible content propagate instead, since a model cannot act on them.
Adapt an MCP target into LangChain tools.
MCPAdapter uses FastMCP for protocol negotiation and connection management,
then converts discovered MCP tools into asynchronous LangChain tools. The
resulting tools can be passed directly to create_agent.
Transport inference is delegated to fastmcp.Client, so a target may be a URL,
a local script path (launched over stdio), an in-process server, or an already
constructed client.
fastmcp.Client resolves a string by testing it as a filesystem path
before testing it as a URL, so a string naming an existing .py or .js
file launches that file as a subprocess. Because strings are the form a
target most often arrives in from configuration or from a model,
MCPAdapter rejects one that is not an http or https URL rather than
let it select local execution. Reach a local server through Path, a
fastmcp transport, or an MCPConfig, all of which say so explicitly.
A server that needs input mid-call is answered with a LangGraph
interrupt(), so a human answers and the run resumes — see
langchain.mcp.elicitation. This is the default: the adapter arms every
client it builds to advertise the elicitation capability and drives the
interrupt loop on each call. A server that never asks for input is
unaffected, since the loop only runs when the server returns a request.
A pre-built client (or ClientGroup) that already carries its own
elicitation handler is honored rather than overridden: its handler keeps
answering, and the adapter leaves the client as the caller built it. Only a
client with no handler is armed, and it is cloned first so the caller's own
object is never mutated.
Anything MCPAdapter accepts as its target.
Every transport fastmcp.Client accepts, plus a pre-built fastmcp.Client.
A str target is the one member narrowed relative to fastmcp.Client: it must
be an http/https URL. Local servers are reached through Path, an explicit
transport, or MCPConfig — see MCPAdapter.
ClientGroup is the one member fastmcp.Client does not accept at all, since a
group is a peer of Client rather than a transport it could wrap.