What you get
Released Sep 1, 2026 in langchain v1.4.0: MCP support now ships inside LangChain as langchain.mcp (built on FastMCP), replacing the separate langchain-mcp-adapters package.
Prerequisites
- Python 3.10+ and
langchain[mcp]>=1.4.0
- An Anthropic API key (for the example model)
- Note:
langchain.mcp is in beta and emits a LangChainBetaWarning on import
Steps
- Install with the
mcp extra plus a model integration:
pip install "langchain[mcp]" langchain-anthropic
export ANTHROPIC_API_KEY="your-api-key"
- Point
MCPAdapter at any MCP server URL. This example uses LangChain's public docs server (no key needed):
import asyncio
from langchain.agents import create_agent
from langchain.mcp import MCPAdapter
async def main():
async with MCPAdapter("https://docs.langchain.com/mcp") as adapter:
tools = await adapter.list_tools()
agent = create_agent("claude-sonnet-5", tools)
return await agent.ainvoke(
{
"messages": [
{
"role": "user",
"content": "How do I add short-term memory to a LangChain agent?",
}
]
}
)
result = asyncio.run(main())
print(result["messages"][-1].content)
- Migrating from
langchain-mcp-adapters? MultiServerMCPClient is replaced by MCPAdapter; pass an {"mcpServers": {...}} config dict to connect several servers behind one adapter.
Test it
Run the script. The agent should call the search_docs_by_lang_chain tool and answer with a summary of the short-term memory docs.