Model Context Protocol (MCP)
import McpQuickstartPy from '/snippets/code-samples/mcp-quickstart-py.mdx'; import McpQuickstartJs from '/snippets/code-samples/mcp-quickstart-js.mdx'; import McpDocsServerPy from '/snippets/code-samples/mcp-docs-server-py.mdx'; import McpDocsServerJs from '/snippets/code-samples/mcp-docs-server-js.mdx'; import McpTransportsPy from '/snippets/code-samples/mcp-transports-py.mdx'; import McpTransportsJs from '/snippets/code-samples/mcp-transports-js.mdx';
Model Context Protocol (MCP) (opens in a new tab) is an open protocol that standardizes how applications provide tools and context to language models. LangChain agents call tools defined on MCP servers through @[MCPAdapter], which discovers a server's tools and adapts them into LangChain tools you can pass straight to @[create_agent].
@[MCPAdapter] is built on FastMCP (opens in a new tab), which handles transport inference, protocol negotiation, connection management, and authentication. This section covers the LangChain-specific layer and links out to the FastMCP client documentation for the connection details underneath.
The
langchain.mcpnamespace requireslangchain[mcp]>=1.4.0and is in beta. Importing from it raises aLangChainBetaWarningonce per process. The API may change.If you used MCP before v1.4.0, see Migrate from
langchain-mcp-adapters(opens in a new tab).
Install
Install LangChain with the mcp extra, which pulls in FastMCP:
pip install "langchain[mcp]"uv add "langchain[mcp]"Quickstart
Open an @[MCPAdapter], discover the server's tools with list_tools(), and build the agent inside the context. The tools hold the client, so the agent stays usable after the context exits:
LangChain docs MCP server
The LangChain docs MCP server is a public HTTP endpoint at https://docs.langchain.com/mcp.
Connect an agent to it to search and read documentation without writing custom tools:
The docs MCP server is public and does not require an API key. For IDE and coding-agent setup (Claude Code, Cursor, and others), see Use docs programmatically.
The server exposes these tools:
| Tool | Description |
|---|---|
search_docs_by_lang_chain | Search docs for relevant guides, how-tos, and examples. |
query_docs_filesystem_docs_by_lang_chain | Read or search docs through a virtual filesystem (rg, head, cat, and related commands). |
submit_feedback | Report a problem with a documentation page. |
Transports
@[MCPAdapter] infers the transport from the target you provide. The target is the only difference between an in-process server, a local script over stdio, and a remote URL:
A target can be any of the following:
- An
http/httpsURL (str): reached over Streamable HTTP. - A script path (
Path): launched as a subprocess over stdio. - A transport object (
StreamableTransport): a preconfigured transport object. See Client Transports (opens in a new tab). - An in-process
FastMCPserver: connected in memory, without a subprocess or socket. - An
MCPConfigdict ({"mcpServers": {...}}): several servers behind one adapter. See Connections (opens in a new tab). - A prebuilt
fastmcp.Client: for full control over transport, caching (opens in a new tab), and protocol negotiation (opens in a new tab).
A
strtarget must be anhttporhttpsURL. FastMCP resolves a string by testing it as a filesystem path before testing it as a URL, so a string naming an existing.pyor.jsfile would launch that file as a subprocess. Because strings are the form a target most often arrives in from configuration or from a model, @[MCPAdapter] rejects strings that do not match the shape of a URL.
Next steps
- Tools (opens in a new tab):Load MCP tools into agents, control their execution, and handle their outputs.
- Connections (opens in a new tab):Connection lifecycle, multiple servers, protocol eras, and caching.
- Authentication (opens in a new tab):Bearer tokens, OAuth 2.1, and per-user server auth.