langchain-mcp-adapters

This repository provides a lightweight wrapper for using Anthropic Model Context Protocol (MCP) tools with LangChain and LangGraph, enabling the creation of agents that can access and utilize MCP-defined functionalities.

1,594
58

LangChain MCP Adapters

This library provides a lightweight wrapper to integrate Anthropic Model Context Protocol (MCP) tools with LangChain and LangGraph.

MCP

Features

  • Convert MCP tools into LangChain tools for use with LangGraph agents.
  • A client implementation to connect to multiple MCP servers and load tools.

Installation

pip install langchain-mcp-adapters

Quickstart

The library facilitates the creation of MCP servers with tools (e.g., add, multiply in math_server.py) and their integration into LangGraph agents. The client connects to these servers using stdio_client and ClientSession, loads the tools using load_mcp_tools, and then uses them within a LangGraph agent created with create_react_agent.

Multiple MCP Servers

The library supports connecting to multiple MCP servers, demonstrated with math_server.py and weather_server.py. The MultiServerMCPClient manages connections to different servers (e.g., via stdio and SSE), retrieves tools, and integrates them into a LangGraph agent.

Using with LangGraph API Server

To run a LangGraph agent with MCP tools in a LangGraph API server, define a make_graph function that initializes the MultiServerMCPClient and creates the agent. Configure the langgraph.json file to specify make_graph as the graph entrypoint.

Repository

LA
langchain-ai

langchain-ai/langchain-mcp-adapters

Created

February 7, 2025

Updated

March 28, 2025

Language

Python

Category

AI