@langchain/mcp-adapters library.
Quickstart
Install the@langchain/mcp-adapters library:
@langchain/mcp-adapters enables agents to use tools defined across one or more MCP servers.
MultiServerMCPClient is stateless by default. Each tool invocation creates a fresh MCP ClientSession, executes the tool, and then cleans up.Accessing multiple MCP servers
Example: Query LangChain docs
Example: Query LangChain docs
The LangChain docs MCP server is a public HTTP endpoint at The server exposes these tools:
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.
Custom servers
To create your own MCP servers, you can use the@modelcontextprotocol/sdk library. This library provides a simple way to define tools and run them as servers.
Math server (stdio transport)
Weather server (SSE transport)
Transports
MCP supports different transport mechanisms for client-server communication.HTTP
Thehttp transport (also referred to as streamable-http) uses HTTP requests for client-server communication. See the MCP HTTP transport specification for more details.
Use a local URL for servers you run yourself, or a hosted URL such as the LangChain docs MCP server (https://docs.langchain.com/mcp), which is public and does not require an API key.
Passing headers
When connecting to MCP servers over HTTP, you can include custom headers (for example, for authentication or tracing) using theheaders field in the connection configuration. This example uses the LangChain docs MCP server; replace the header values for a server that requires authentication:
Passing headers with MultiServerMCPClient
Authentication
The@langchain/mcp-adapters library uses the official MCP TypeScript SDK under the hood, which allows you to provide a custom authentication mechanism by implementing the OAuthClientProvider interface.
stdio
Client launches server as a subprocess and communicates via standard input/output. Best for local tools and simple setups.Core features
Tools
Tools allow MCP servers to expose executable functions that LLMs can invoke to perform actions—such as querying databases, calling APIs, or interacting with external systems. LangChain converts MCP tools into LangChain tools, making them directly usable in any LangChain agent or workflow.Loading tools
Useclient.getTools() to retrieve tools from MCP servers and pass them to your agent:
CallToolResult with isError: true), @langchain/mcp-adapters raises a ToolException. Wrap tool calls in a try/catch to handle these errors. Unlike the Python adapter, the TypeScript adapter does not return the error to the model as a failed tool message.
Structured content
MCP tools can return structured content alongside the human-readable text response. This is useful when a tool needs to return machine-parseable data (like JSON) in addition to text that gets shown to the model. When an MCP tool returnsstructuredContent, the adapter adds an mcp_structured_content entry to the tool message artifact array. You can also use tool interceptors to process or transform structured content automatically.
Extracting structured content from artifact
After invoking your agent, you can access the structured content from tool messages in the response:
Multimodal tool content
MCP tools can return multimodal content (images, text, etc.) in their responses. When an MCP server returns content with multiple parts (e.g., text and images), the adapter converts them to LangChain’s standard content blocks. You can access the standardized representation via thecontentBlocks property on the ToolMessage:
Resources
Resources allow MCP servers to expose data—such as files, database records, or API responses—that can be read by clients.Loading resources
Useclient.listResources() to discover resources and client.readResource() to read their contents:
Advanced features
Tool interceptors
MCP servers run as separate processes—they cannot access LangGraph runtime information like the store, context, or agent state. UsebeforeToolCall and afterToolCall hooks on MultiServerMCPClient to modify tool arguments, headers, or results:
- beforeToolCall: Can return
{ args?, headers? }. Headers are supported for HTTP and SSE transports. Stdio connections do not support custom headers. - afterToolCall: Can return
{ result }whereresultis a[content, artifact]tuple, aToolMessage, a LangGraphCommand, or the original result.
Progress notifications
Subscribe to progress updates for long-running tool executions withonProgress:
Logging
The MCP protocol supports logging notifications from servers. Subscribe withonMessage:
client.setLoggingLevel("debug") or client.setLoggingLevel("server_name", "debug").
Additional resources
Connect these docs to Claude, VSCode, and more via MCP for real-time answers.

