Alpha Notice: These docs cover the v1-alpha release. Content is incomplete and subject to change.For the latest stable version, see the v0 LangChain Python or LangChain JavaScript docs.
Model Context Protocol (MCP) is an open protocol that standardizes how applications provide tools and context to LLMs. LangChain agents can use tools defined on MCP servers using the langchain-mcp-adapters library.
You can also expose existing LangChain tools through an MCP server using the to_fastmcp function. This allows you to make your LangChain tools available to any MCP client.
Make LangChain tools available via MCP
Copy
from langchain_core.tools import toolfrom langchain_mcp_adapters.tools import to_fastmcpfrom mcp.server.fastmcp import FastMCP@tooldef add(a: int, b: int) -> int: """Add two numbers""" return a + b@tooldef get_user_info(user_id: str) -> str: """Get information about a user""" return f"User {user_id} is active"# Convert LangChain tools to FastMCPfastmcp_tools = [to_fastmcp(tool) for tool in (add, get_user_info)]# Create server using converted toolsmcp = FastMCP("LangChain Tools", tools=fastmcp_tools)mcp.run(transport="stdio")
For stateful servers that maintain context between tool calls, use client.session() to create a persistent ClientSession.
Using MCP ClientSession for stateful tool usage
Copy
from langchain_mcp_adapters.tools import load_mcp_toolsclient = MultiServerMCPClient({...})async with client.session("math") as session: tools = await load_mcp_tools(session)