LLM Lab

MCP tools

The Model Context Protocol is a common plug for agents: any application that speaks it can use any tool server that speaks it.

Where this sits in a LangChain agent
Model→Tools→Agent loop (create_agent)→Middleware→Memory (checkpointer)→Integrations (MCP)→Guardrails

Hosts, clients, servers

The host is the AI application (a chat app, an IDE). For each connected server it runs a client that speaks the protocol: JSON-RPC messages over standard input/output for local servers, or HTTP for remote ones.

toolsstdiohttpLangChain agenthostMCP clientlangchain-mcp-adaptersfiles servertools: read_fileGitHub servertools · resourcesdatabase servertools · prompts
One agent, several MCP servers. The client lists each server’s tools and presents them to the agent as ordinary LangChain tools.

What servers offer

Servers expose tools (functions the model may call), resources (data such as files or records the application can read into context) and prompts (reusable templates). A session starts with a handshake where both sides state what they support; then the client can list and call.

Step through a session with a small notes server in the lab. The messages are trimmed for clarity.

In LangChain

The langchain-mcp-adapters package connects to one or more MCP servers and turns the tools they expose into ordinary LangChain tools, which you pass to create_agent like any other.

from langchain_mcp_adapters.client import MultiServerMCPClient

client = MultiServerMCPClient({
    "files": {"command": "python", "args": ["files_server.py"], "transport": "stdio"},
})
tools = await client.get_tools()          # MCP tools, now LangChain tools
agent = create_agent(model="provider:model-name", tools=tools)
An MCP server written once can serve any host; here LangChain is the host and the agent sees the server’s tools next to its own.

A worked example

A coding assistant (the host) starts an MCP client for a file-system server. The client asks what the server offers and receives a list of tools such as read_file, each with a JSON schema. When the model decides to read a file, the client sends a tools/call request and returns the file’s contents to the model as the tool result.

host app (chat, IDE)→MCP client→MCP server→tools · resources · prompts
The host runs one client per server. Servers describe what they offer in a standard format, so any MCP host can use any MCP server without custom glue code.

In practice

MCP separates writing an integration from using it: a server written once works in every host that speaks the protocol. Servers can run locally or remotely. Treat third-party servers like any dependency: they can see and do what you allow, so grant the least access they need.

Easy to confuse

Check yourself · 1 of 3

What problem does MCP solve?

Check yourself · 2 of 3

Which three kinds of capability can an MCP server offer?

Check yourself · 3 of 3

Who decides whether a tool call actually runs?

Read more in the books

  • LangChain and LangGraph documentation, LangChain: LangChain: Model Context Protocol (MCP).
  • AI Engineering, Chip Huyen: Ch. 6, “RAG and Agents”: tools and tool use.
All books
Labserver explorer
How to read this
  • The stage map lights the current message; Back and Next move through a session.
  • Each card is one JSON-RPC message between the client (inside the host app) and an MCP server: its direction and content.