LangChain MCP 어댑터는 Anthropic 모델 콘텐츠 프로토콜(MCP) 도구를 LangChain 및 LangGraph 생태계와 원활하게 통합하도록 설계된 경량 래퍼 라이브러리입니다. 이 프로젝트는 서로 다른 AI 도구 프레임워크 간의 호환성 문제를 해결하여 개발자가 LangChain/LangGraph 환경에서 직접 MCP 도구를 사용하여 더욱 강력하고 유연한 AI 에이전트 애플리케이션을 구축할 수 있도록 합니다.
프로젝트 주소: https://github.com/langchain-ai/langchain-mcp-adapters
LangChain/LangGraph Application
↓
LangChain MCP Adapters
↓
MCP Client Implementation
↓
Multiple MCP Servers (Math, Weather, etc.)
# 기본 설치
pip install langchain-mcp-adapters
# 전체 개발 환경
pip install langchain-mcp-adapters langgraph langchain-openai
# OpenAI API 키 설정
export OPENAI_API_KEY=<your_api_key>
# math_server.py
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Math")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
@mcp.tool()
def multiply(a: int, b: int) -> int:
"""Multiply two numbers"""
return a * b
if __name__ == "__main__":
mcp.run(transport="stdio")
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
from langchain_mcp_adapters.tools import load_mcp_tools
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
# 모델 초기화
model = ChatOpenAI(model="gpt-4o")
# 서버 매개변수 구성
server_params = StdioServerParameters(
command="python",
args=["/path/to/math_server.py"],
)
# 에이전트 생성 및 실행
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
# MCP 도구 로드
tools = await load_mcp_tools(session)
# 에이전트 생성
agent = create_react_agent(model, tools)
# 쿼리 실행
response = await agent.ainvoke({
"messages": "what's (3 + 5) x 12?"
})
# weather_server.py
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("Weather")
@mcp.tool()
async def get_weather(location: str) -> str:
"""Get weather for location."""
return f"It's always sunny in {location}"
if __name__ == "__main__":
mcp.run(transport="sse")
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_openai import ChatOpenAI
model = ChatOpenAI(model="gpt-4o")
# 다중 서버 구성
async with MultiServerMCPClient({
"math": {
"command": "python",
"args": ["/path/to/math_server.py"],
"transport": "stdio",
},
"weather": {
"url": "http://localhost:8000/sse",
"transport": "sse",
}
}) as client:
# 에이전트 생성
agent = create_react_agent(model, client.get_tools())
# 수학 연산
math_response = await agent.ainvoke({
"messages": "what's (3 + 5) x 12?"
})
# 날씨 쿼리
weather_response = await agent.ainvoke({
"messages": "what is the weather in NYC?"
})
# graph.py
from contextlib import asynccontextmanager
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(model="claude-3-5-sonnet-latest")
@asynccontextmanager
async def make_graph():
async with MultiServerMCPClient({
"math": {
"command": "python",
"args": ["/path/to/math_server.py"],
"transport": "stdio",
},
"weather": {
"url": "http://localhost:8000/sse",
"transport": "sse",
}
}) as client:
agent = create_react_agent(model, client.get_tools())
yield agent
{
"dependencies": ["."],
"graphs": {
"agent": "./graph.py:make_graph"
}
}
LangChain MCP 어댑터 프로젝트는 AI 도구 생태계의 중요한 인프라로서 MCP 프로토콜과 LangChain 프레임워크 간의 간극을 성공적으로 연결했습니다. 이 어댑터를 통해 개발자는 다음을 수행할 수 있습니다.
AI 에이전트 기술의 빠른 발전과 함께 도구 통합 및 상호 운용성이 점점 더 중요해질 것입니다. LangChain MCP 어댑터는 서로 다른 AI 도구 생태계를 연결하는 다리 역할을 하여 미래의 AI 애플리케이션 개발에서 중요한 역할을 할 것입니다. 현재 개발 프로세스를 단순화할 뿐만 아니라 더욱 지능적이고 기능이 풍부한 AI 에이전트 애플리케이션을 구축하기 위한 견고한 기반을 마련합니다.
AI 애플리케이션 개발자, 기업 기술 의사 결정자 또는 연구원이든 이 프로젝트는 깊이 이해하고 적용할 가치가 있습니다. AI 도구 통합 분야의 모범 사례를 나타내며 더욱 강력하고 유연한 AI 솔루션을 구축하는 데 도움이 될 것입니다.