LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Browser
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
  • Tools
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Compat
  • Event
  • Llms
  • Openai Completions Stream
  • Profile
  • Stream
  • Structured Output
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Testing
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Gateway
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Standard Schema
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Uuid
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
BrowserUniversalHubNodeLoadSerializableEncoder BackedFile SystemIn MemoryTools
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsCompatEventLlmsOpenai Completions StreamProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingGatewayHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScript@langchain/mcp-adapters

@langchain/mcp-adapters

Description

LangChain.js MCP Adapters

npm version License: MIT

Give your LangChain agents access to tools from Model Context Protocol (MCP) servers. @langchain/mcp-adapters manages connections and converts MCP tools and results into LangChain formats, ready to use with createAgent or a custom LangGraph workflow.

  • Connect your tools: discover tools from multiple local or remote servers.
  • Control tool execution: authenticate connections, customize arguments and results with hooks, and receive progress updates.
  • Choose what the model sees: use text and multimodal results as model input, or keep outputs in artifacts for your application to process.
  • Ask for user input: pause an agent when a modern MCP server requests a form response or a URL visit, then resume with the user's response.

Read the MCP guide for concepts, configuration, and advanced usage.

Install

Requires Node.js 20.10 or later. Install the adapter and its LangChain peers:

npm install @langchain/mcp-adapters @langchain/core @langchain/langgraph

The adapter requires @langchain/core ^1.2.6 and @langchain/langgraph ^1.4.13. It includes the MCP SDK client; install the SDK separately only if your application imports it directly.

Quickstart: give an agent MCP tools

This example connects an agent to the public LangChain docs MCP server so it can look up documentation. You do not need to run a server or configure authentication for this MCP endpoint.

Install LangChain and the model integration used below:

npm install langchain @langchain/openai

Set OPENAI_API_KEY in your environment, then run:

import { createAgent } from "langchain";
import { ChatOpenAI } from "@langchain/openai";
import { MCPAdapter } from "@langchain/mcp-adapters";

const adapter = new MCPAdapter({
  servers: {
    docs: { url: "https://docs.langchain.com/mcp" },
  },
});

try {
  const tools = await adapter.listTools();
  const agent = createAgent({
    model: new ChatOpenAI({ model: "gpt-4.1-mini" }),
    tools,
  });

  const result = await agent.invoke({
    messages: [
      {
        role: "user",
        content: "How do I add short-term memory to a LangChain agent?",
      },
    ],
  });
  console.log(result.messages.at(-1)?.content);
} finally {
  await adapter.close();
}

Keep the adapter open while your agent uses its tools, then call close() when finished. Connections open as needed. listTools() returns executable LangChain tools, which you can also invoke directly without a model or use in a custom LangGraph workflow.

Tools that request user input

MCP tools can ask users to complete a form or visit a URL before continuing. For modern MCP servers, the adapter pauses the agent through a LangGraph interrupt so your application can collect a response and resume the run.

Configure a checkpointer for these workflows. Tools that do not request input can run without one. See the tools guide for handling requests and resuming execution.

Documentation and examples

I want to… Start here
Connect local or remote servers, manage connections, or select tools Connections
Authenticate with tokens or OAuth Authentication
Customize tool calls, handle results, or collect user input Tools
Modify tool arguments and results Hooks example
Work with multimodal content and artifacts Content example
Receive server messages and tool progress Notifications example
Run a local example without model credentials Example setup and walkthroughs

If you already manage an MCP SDK client, use loadMcpTools() to adapt its tools without handing connection management to MCPAdapter.

Upgrading from 1.x

Use MCPAdapter, { servers: { ... } }, and listTools() for new code. MultiServerMCPClient, mcpServers, and getTools() remain available as deprecated compatibility APIs.

Version 2 also changes tool-name defaults, configuration, connection behavior, and tool results. Review the migration guide before upgrading, including any approval rules that refer to tool names.

Acknowledgements

Big thanks to @vrknetha, @knacklabs for the initial implementation!

Contributing

Contributions are welcome! See the contributing guidelines.

License

MIT

Classes

Class

MCPAdapter

Client for connecting to multiple MCP servers and loading LangChain-compatible tools.

Class

MCPClientError

An operational failure while connecting to or using an MCP server.

Class

ToolException

Custom error class for tool exceptions

Class

MultiServerMCPClient

Client for connecting to multiple MCP servers and loading LangChain-compatible tools.

Functions

Function

createMCPElicitationResume

Build an answer addressed to the task that raised pending.

Function

loadMcpTools

Load all tools from an MCP client.

Interfaces

Types

Interface

MCPElicitationContext

Type

Connection

Union type for all supported MCP connection transports.

Type

ConnectionErrorHandler

Custom error handler for connection failures.

If the handler throws or rejects, the error is propagated when a caller is waiting for discovery. Returning normally treats the server as ignored.

Type

HTTPConnection

Configuration for a URL-based Streamable HTTP or legacy SSE connection.

Type

LoadMcpToolsOptions

Type

MCPAdapterConfig

Canonical adapter options.

Type

MCPElicitationHandler

Type

MCPElicitationInterrupt

Type

MCPElicitationResponses

Answers to one question set, keyed by the server's input-request keys.

Type

MCPElicitationResume

Resume values, keyed by the graph task whose interrupt they answer.

Type

MCPResource

Represents a resource provided by an MCP server.

Type

MCPResourceContent

Represents the content of a resource retrieved from an MCP server.

Type

MCPResourceTemplate

Represents a resource template provided by an MCP server. Resource templates are used for dynamic resources with parameterized URIs.

Type

OutputHandling

Defines where to place each tool output type in the LangChain ToolMessage.

Can be set to content or artifact to send all tool output into the ToolMessage.content or ToolMessage.artifact array, re

Type

ResolvedConnection

Type for Connection with default values applied.

Type

ResolvedMCPAdapterConfig

Canonical configuration snapshot with defaults applied.

Type

SSEConnection

Legacy SSE transport options. Modern servers use Streamable HTTP.

Type

StdioConnection

Configuration for stdio transport connection

Type

StreamableHTTPConnection

Configuration for streamable HTTP transport connection

Type

ToolDiscoveryOptions

Type

ToolHooks

Hooks preserve native inputs; awaited modifications are parsed at invocation.

Type

ClientConfig

deprecated