Registry / llm-agents / langchain-mcp-adapters

langchain-mcp-adapters

JSON →
library0.3.2pypypi✓ verified 25d ago

This library provides a lightweight wrapper that makes Anthropic Model Context Protocol (MCP) tools compatible with LangChain and LangGraph agents. It automatically converts MCP tools, manages connections to multiple MCP servers, and seamlessly integrates them into LangChain workflows. The current version is 0.2.2 and it appears to have an active development and release cadence, with version 0.2.0 released in December 2025 and ongoing updates.

pip install langchain-mcp-adapters langchain-core
INSTALL
IMPORT
SIG · LANGCHAIN-MCP-ADAP
L
langchain-mcp-adapters
llm-agentspythonv0.3.2
Install
9.8s avg
Import
3239ms
Disk
101MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 12.2s
py 3.11
✓ —
✓ 10s
py 3.12
✓ —
✓ 8.4s
py 3.13
✓ —
✓ 8.5s
py 3.9
✕ build_error
✕ build_error
101MB installed
● package 101MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MultiServerMCPClient
from langchain_mcp_adapters.client import MultiServerMCPClient
load_mcp_tools
from langchain_mcp_adapters.tools import load_mcp_tools
ClientSession
from mcp import ClientSession
from langchain_mcp_adapters.client import ClientSession
MCP's ClientSession is directly from the 'mcp' library, not the adapter.
StdioServerParameters
from mcp import StdioServerParameters
from langchain_mcp_adapters.client import StdioServerParameters
MCP's StdioServerParameters is directly from the 'mcp' library, not the adapter.

This quickstart demonstrates how to set up `MultiServerMCPClient` to connect to multiple (mock) MCP servers and use their tools with a LangChain agent. It shows configuration for both `stdio` (local subprocess) and `http` transports. Remember to replace `/path/to/your/math_server.py` with an actual path to a running MCP math server and ensure your API keys for the chosen LLM are set as environment variables.

import os import asyncio from langchain_mcp_adapters.client import MultiServerMCPClient from langchain.agents import create_agent from langchain_core.messages import HumanMessage # NOTE: For this example to be runnable, you need a running MCP server. # For a 'math' server, you could use fastmcp: # # math_server.py # from fastmcp import FastMCP # mcp = FastMCP("Math") # @mcp.tool() # def add(a: int, b: int) -> int: # """Add two numbers""" # return a + b # if __name__ == "__main__": # mcp.run(transport="stdio") # And start it from your terminal: python /path/to/math_server.py async def main(): # Set your LLM API key as an environment variable # e.g., export OPENAI_API_KEY="your_key_here" # Or, for Anthropic: export ANTHROPIC_API_KEY="your_key_here" if not os.environ.get('OPENAI_API_KEY') and not os.environ.get('ANTHROPIC_API_KEY'): print("Please set OPENAI_API_KEY or ANTHROPIC_API_KEY environment variable.") return client = MultiServerMCPClient( { "math": { "transport": "stdio", # Local subprocess communication "command": "python", # Path to python interpreter "args": ["/path/to/your/math_server.py"], # ABSOLUTE path to your math_server.py }, "weather": { "transport": "http", # HTTP-based remote server "url": "http://localhost:8000/mcp", # Ensure your weather server is running on port 8000 "onConnectionError": "ignore" # Ignore if this server is not running for demo } } ) # Retrieve tools from the connected MCP servers tools = await client.get_tools() print(f"Loaded {len(tools)} tools.") # Example: Create an agent using LangChain's create_agent # Choose your LLM. For example, "openai:gpt-4o" or "anthropic:claude-3-opus-20240229" agent = create_agent("openai:gpt-4o", tools) # Invoke the agent with a message that uses a tool print("\nInvoking agent for math query...") math_response = await agent.ainvoke( {"messages": [HumanMessage(content="what's (3 + 5) x 12?")]} ) print("Math Agent Response:", math_response) print("\nInvoking agent for weather query (may fail if server not running)...") weather_response = await agent.ainvoke( {"messages": [HumanMessage(content="what is the weather in nyc?")]} ) print("Weather Agent Response:", weather_response) await client.close() # Important to close client to terminate subprocesses if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
gotchaConnecting to multiple MCP servers can lead to high token consumption due to all tool schemas being preloaded into the LLM's system prompt. This 'token overhead' can be significant, especially with many verbose tool definitions.
fix
Consider strategies like lazy-loading schemas (if supported by future versions or custom logic), using a gateway for selective loading, or carefully managing the number and verbosity of exposed tools.
affects: All versions
gotchaEach MCP server can have distinct authentication requirements (API keys, OAuth, etc.), leading to 'Auth Fragmentation' and complex credential management across multiple development and production environments.
fix
Implement a centralized authentication mechanism, potentially via a gateway that handles credentials for upstream servers, or leverage `authProvider` options in `MultiServerMCPClient` for OAuth 2.0 (new in v0.4.6 of JS version, check Python equivalent).
affects: All versions
gotchaSchema misalignment between MCP tool input/output JSON schemas and LangChain's expectations, or invalid connection configurations for `MultiServerMCPClient`, can lead to `ZodError` or silent failures.
fix
Carefully validate MCP tool schemas and `MultiServerMCPClient` configurations, paying close attention to required parameters and expected data types for each transport (e.g., `command` for `stdio`, `url` for `http`/`sse`). Enable verbose logging for debugging.
affects: All versions
gotchaManaging different transport protocols (stdio, HTTP, SSE) and handling connection issues (e.g., server startup delays, unreachable servers) can add complexity to setup and debugging.
fix
Utilize `onConnectionError: 'ignore'` for non-critical servers during development. Implement robust error handling and monitoring for production environments. Ensure proper server startup and network connectivity, especially for HTTP/SSE transports.
affects: All versions
gotchaWhen connecting to multiple MCP servers, tools from different servers might have conflicting names, leading to ambiguity or unexpected behavior if not properly handled.
fix
Use the `prefixToolNameWithServerName` option in `MultiServerMCPClient` to automatically add a server-specific prefix to tool names, preventing collisions.
affects: All versions
breakingThe `langchain-mcp-adapters` library requires Python 3.10 or newer. Attempting to install or use it with Python 3.9 or older will result in installation failure.
fix
Ensure your environment is running Python 3.10 or newer before installing `langchain-mcp-adapters`.
affects: All versions (when used with Python < 3.10)
breakingThe library depends on `langchain` (or similar AI framework libraries) which must be installed separately. A `ModuleNotFoundError` indicates that a required dependency is missing.
fix
Ensure all required dependencies, such as `langchain`, are installed in your environment using `pip install langchain` or by including them in your `requirements.txt`.
affects: All versions
Upgrade
Version history
0.3.2latest on PyPI · released Aug 6, 2026
Audit
Dependencies
langchainrequiredPrimary framework for integration.
langchain-corerequiredCore components for LangChain integration, often required alongside `langchain`.
mcprequiredThe underlying Model Context Protocol (MCP) SDK, used for client sessions and server parameters.
fastmcpoptionalOptional: For creating custom MCP servers, if you are building your own tools.
anthropicoptionalOptional: For using Anthropic models with LangChain agents.
openaioptionalOptional: For using OpenAI models with LangChain agents.
Agent activity
25 hits · last 30 days
node
20
OpenAI (training)
1
Resources
langchain-mcp-adapters — pip install langchain-mcp-adapters · libregistry