
LangGraph 代理教程 适应使用 MCP 服务器.
概览
这是使用服务器而不是传统的LangChain工具实施工具的最小功能性实例。 它基于官方的LangGraph教程,被改编为演示如何将MCP服务器集成为工具. 用这个回波作为工具,用MCP工具快速构建出自己的LangGraph代理! * 将LangGraph纳入管理代理状态和信息路由。 * 使用MCP服务器提供工具访问. * 包括用于数学和天气的MCP服务器实例。 * 为与代理人互动提供命令行接口. 2. 利用诗歌安装附属物: 1. 在.env文件中设置 Anthropic API 键. 如果该文件不存在, 您可能需要创建该文件 。 例如: *数学服务器:python src/mcp server/math server.py *天气服务器:python src/mcp server/weather server.py. 2. 运行代理人: 这将以交互模式启动代理 。 然后可以输入提示,代理将使用MCP服务器提供的工具进行响应.
概述(AI 翻译)
这是一个由 LangGraph ** 提供动力的** 代理机的最小功能实例,该代理机使用 ** MCP(模式上下文协议)** 服务器而不是传统的 LangChain 工具来执行。 它基于官方的LangGraph教程,被改编为演示如何将MCP服务器集成为工具.
使用这回波作为skeleton 用MCP工具快速构建出自己的LangGraph代理!
□ 特性
- 将LangGraph纳入管理代理状态和信息路由。
- 使用MCP服务器提供工具访问.
- 包括用于数学和天气的MCP服务器实例。
- 为与代理人互动提供命令行接口.
□ 安装
-
清除储存库:
-
利用诗歌安装附属物:
□ 使用量
-
在 [[T0] 文件内设置 Anthropic API 密钥。 如果该文件不存在, 您可能需要创建该文件 。 例如:
-
启动MCP服务器:
- 数学服务器:
python src/mcp_servers/math_server.py*天气服务器:python src/mcp_servers/weather_server.py
- 运行代理人:
这将以交互模式启动代理 。 然后可以输入提示,代理将使用MCP服务器提供的工具进行响应.
□ 实例
本页由 AI 翻译,技术细节请以原文为准。
README
MCP + LangGraph Agent
This is a minimal, functional example of an agent powered by LangGraph with tools implemented using MCP (Model Context Protocol) servers instead of traditional LangChain tools. It’s based on the official LangGraph tutorial, adapted to demonstrate how to integrate MCP servers as tools.
🧠 Use this repo as a skeleton to quickly build your own LangGraph agent with MCP tools!
Features
flowchart TD
__start__ --> chatbot
chatbot -.-> tools
chatbot -.-> __end__
tools --> chatbot
- Integrates LangGraph for managing agent state and message routing.
- Uses MCP servers to provide access to tools.
- Includes example MCP servers for math and weather.
- Provides a command-line interface for interacting with the agent.
Installation
-
Clone the repository:
git clone -
Install the dependencies using Poetry:
poetry install
Usage
-
Set the Anthropic API key in the
.envfile. You may need to create this file if it doesn’t exist. For example:ANTHROPIC_API_KEY=your_api_key -
Start the MCP servers:
- Math server:
python src/mcp_servers/math_server.py - Weather server:
python src/mcp_servers/weather_server.py
- Math server:
-
Run the agent:
poetry run mainThis will start the agent in interactive mode. You can then enter prompts, and the agent will respond using the tools provided by the MCP servers.
Example
User: What's (3 + 5) x 12?
Assistant: The result of (3 + 5) × 12 = 96
User: What is the weather in New York?
Assistant: It's always sunny in New York.
MCP Server Configuration
The MCP servers are configured in src/main.py. You can modify the configuration to add or remove servers, or to change the transport mechanism.
LLM Configuration
The LLM used by the agent can be changed in src/common.py.
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →