langchain-ai/langchain-mcp-adapters
LangChain 🔌 MCP
LangChain MCP Adapters
What it is – A small Python package that bridges the Model Context Protocol (MCP) with the LangChain ecosystem. It lets you expose functions ("tools") from any MCP‑compatible server as LangChain/LangGraph tools, so large‑language‑model agents can call them just like native @tool functions.
Key capabilities
- Tool conversion –
load_mcp_toolsturns MCP‑described tools intolangchain.tools.Toolobjects. - Multi‑server client –
MultiServerMCPClientcan keep connections to several MCP servers (via stdio, HTTP, SSE, or the new streamable‑HTTP transport) and aggregate all their tools. - Header support – Custom HTTP/SSE headers (e.g., auth tokens) can be supplied per‑server.
- Error handling options – Choose whether MCP execution errors are returned to the model as a
ToolMessage(default) or raised as exceptions. - LangGraph integration – Works with LangGraph’s
StateGraph,ToolNode, and the LangGraph API server, enabling state‑ful agent workflows that call remote MCP tools.
Typical workflow
- Run an MCP server – any Python process that registers tools with
FastMCP(e.g., a simple math service or a weather service). - Create a client – instantiate
MultiServerMCPClientwith the server specs (command + args for stdio, or URL for HTTP). - Load tools –
await client.get_tools()(orload_mcp_tools(session)) returns a list of LangChain tool objects. - Build an agent –
create_agent("openai:gpt-4.1", tools)and invoke it; the model can now call the remote functions.
Installation
pip install langchain-mcp-adapters
Example (single stdio server)
# math_server.py – defines add & multiply
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Math")
@mcp.tool()
def add(a: int, b: int) -> int: return a + b
@mcp.tool()
def multiply(a: int, b: int) -> int: return a * b
if __name__ == "__main__":
mcp.run(transport="stdio")
# client side
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
from langchain_mcp_adapters.tools import load_mcp_tools
from langchain.agents import create_agent
params = StdioServerParameters(command="python", args=["/path/to/math_server.py"])
async with stdio_client(params) as (r, w):
async with ClientSession(r, w) as sess:
await sess.initialize()
tools = await load_mcp_tools(sess)
agent = create_agent("openai:gpt-4.1", tools)
resp = await agent.ainvoke({"messages": "what's (3 + 5) x 12?"})
print(resp)
Multiple servers – the same client can point to a stdio‑based math server and an HTTP‑based weather server, automatically merging their tools.
Status – The repository is archived; MCP support has moved into the main LangChain codebase under langchain.mcp. The adapters are still usable, but new development should target langchain[mcp].
Bottom line – If you have existing MCP services (or want to experiment with the protocol) and you’re building LangChain or LangGraph agents, langchain-mcp-adapters gives you a ready‑made bridge so those remote tools appear as first‑class LangChain tools.
Related
- Dispatch
- Project
- Project
- Project
- Project