Skip to main content
Model Context Protocol (MCP) 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 createAgent.
This guide requires @langchain/mcp-adapters 2.0 or later. If you use 1.x, see the 1.x docs or the migration guide.

Install

Install the @langchain/mcp-adapters package and its peer dependencies:
Add @modelcontextprotocol/client too if you import SDK types or transports.

Quickstart

Connect an agent to the LangChain docs MCP server to search the documentation. This example requires langchain, @langchain/anthropic, and an Anthropic API key. See the LangChain quickstart for setup. Keep the adapter open while the agent runs, then close it in finally:
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:MCPAdapter exposes these tools with the server-name prefix, for example docs__search_docs_by_lang_chain.

Transports

MCPAdapter accepts a map of named server definitions. It selects the transport from each definition, so one adapter can connect to local stdio servers and remote HTTP servers at the same time:
Each server definition can use one of these transports:
  • stdio: Provide command and args. The adapter starts the command as a child process and communicates over standard input and output.
  • Streamable HTTP: Provide url. This is the default transport for URL-based servers, so transport: "http" is optional.
  • SSE: Provide url and set transport: "sse". Use this transport only for legacy servers that expose an SSE endpoint.
Transport selection and protocol negotiation are separate. The optional mode setting controls which MCP protocol era the client accepts. See Protocol eras.
For new remote servers, omit both transport and mode. The adapter uses Streamable HTTP with automatic protocol negotiation. Specify these settings only when connecting to a server with known legacy requirements.

Next steps

Tools

Load MCP tools into agents, control their execution, and handle their outputs.

Connections

Connection lifecycle, multiple servers, protocol eras, and caching.

Authentication

Bearer tokens, OAuth 2.1, and per-user server auth.