MCP tools with MCPAdapter
MCP tools are tools served by a Model Context Protocol server; LangChain's MCPAdapter connects to the server, lists its tools as LangChain tools, and a deep agent takes them like any other tools.
Last updated: 29 Sep, 2026 · Deep Agents 0.7
The video lists MCP support as something Deep Agents and the Claude Agent SDK share. The docs connect MCP servers through langchain.mcp.MCPAdapter, new in LangChain 1.4 and in beta. It takes a URL, a script path, or a FastMCP server object, and works out the transport. This lesson gives the trip planner a weather server, so it can pick an indoor day for the Louvre.
Installing MCP support
pip install "langchain[mcp]==1.4.3"The mcp extra installs FastMCP, which runs both the client and the server.
The MCPAdapter syntax
async with MCPAdapter(target) as adapter: # a URL, a Path to a script, or a FastMCP server
tools = await adapter.list_tools()
agent = create_deep_agent(model=model, tools=tools)A weather MCP server
A FastMCP server with one tool, forecast. Passing the server object itself runs it in the same process, with no subprocess or socket, which the docs call ideal for tests. The forecast is fixed text so the answer can be checked.
import asyncio
from deepagents import create_deep_agent
from fastmcp import FastMCP
from langchain.chat_models import init_chat_model
from langchain.mcp import MCPAdapterweather = FastMCP("weather")
@weather.tool
def forecast(city: str) -> str:
"""Get the weather forecast for the next four days in a city."""
return f"{city}: day 1 sunny 14C, day 2 heavy rain 9C, day 3 cloudy 11C, day 4 sunny 13C"Asking which day suits a museum
MCP clients are asynchronous, so the agent runs inside async def main() with ainvoke.
async def main():
async with MCPAdapter(weather) as adapter: # an in-process MCP server
tools = await adapter.list_tools()
print("tools from the server:", [t.name for t in tools])
agent = create_deep_agent(
model=init_chat_model("groq:openai/gpt-oss-120b", temperature=0, max_retries=6),
tools=tools,
system_prompt="You are a travel planner. Use forecast. Reply in two short sentences.",
)
result = await agent.ainvoke({"messages": [{"role": "user", "content": "Which day of my Paris trip is best for an indoor museum?"}]})
print(result["messages"][-1].text)
asyncio.run(main())tools from the server: ['forecast'] Day 2, with heavy rain, is ideal for visiting an indoor museum. The cooler, wet weather makes indoor activities more comfortable.
What came back from the server
- The adapter listed one tool,
forecast, with its name and description from the server. - The agent called it through MCP and read the four-day forecast.
- Day 2 is the rainy day, so the agent picked it for an indoor museum.
MCP targets compared
| Target | Transport | Use it for |
|---|---|---|
| A FastMCP server object | In-process | Tests and demos |
Path("server.py") | stdio subprocess | A local server script |
"https://.../mcp" | Streamable HTTP | A remote server |
Where MCP tools fit
- Using tools other teams already publish as MCP servers.
- Sharing one tool server between Claude Code, your deep agent and other clients.
- Keeping tool code in a separate process or service.
Path; the adapter rejects plain strings that are not URLs.Related
- Previous: Custom middleware: logging every tool call
- Next: Trip planner: the finished deep agent
- Reference: Deep Agents: Model Context Protocol
- Add a second tool,
sunset(city), to the server and ask which evening suits the Seine cruise. - Save the server in
weather.pywithweather.run()at the bottom and connect withMCPAdapter(Path("weather.py")), afterfrom pathlib import Path. - Give the agent
search_travelas well and ask for a rainy-day plan with prices.
Every expert started right here.