Skip to main content
Model Context Protocol (MCP) is an open protocol that standardizes how applications provide tools and context to LLMs. LangChain agents can use tools defined on MCP servers using the @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
Trace MCP tool calls alongside your agent’s reasoning steps with LangSmith. Follow the tracing quickstart to get set up.

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.
To test your agent with MCP tool servers, use the following examples:
Math server (stdio transport)
Weather server (SSE transport)

Transports

MCP supports different transport mechanisms for client-server communication.

HTTP

The http transport (also referred to as streamable-http) uses HTTP requests for client-server communication. See the MCP HTTP transport specification for more details.

Passing headers

Authentication

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

Use client.getTools() to retrieve tools from MCP servers and pass them to your agent:
When an MCP tool execution fails (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.

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 the contentBlocks property on the ToolMessage:
This allows you to handle multimodal tool responses in a provider-agnostic way, regardless of how the underlying MCP server formats its content.

Additional resources