内容
# LangGraph ReAct MCP 聊天



[](https://langgraph-studio.vercel.app/templates/open?githubUrl=https://github.com/langchain-ai/react-agent)
## 项目概述

`LangGraph ReAct MCP 聊天`是一个基于 Model Context Protocol(MCP)的项目,它实现了 ReAct 代理,可以访问各种外部工具和数据源。该项目基于 LangGraph,提供了一个易于添加和配置 MCP 工具的接口。
### 使用案例



### 主要功能
* **LangGraph ReAct 代理**:基于 LangGraph 的 ReAct 代理
* **工具管理**:轻松添加、删除和配置 MCP 工具(支持 Smithery JSON 格式)
* **流式响应**:实时查看代理的响应和工具调用
* **对话记录**:跟踪和管理与代理的对话内容
## 架构

## 安装方法
1. 克隆仓库
```bash
git clone https://github.com/teddynote-lab/langgraph-react-mcp-chat.git
cd langgraph-react-mcp-chat
```
2. 使用 uv 创建虚拟环境并安装依赖
```bash
uv venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
uv pip install -r requirements.txt
```
3. 配置 `.env` 文件
将 `.env.example` 文件复制为 `.env` 文件,并添加必要的 API 密钥:
```bash
cp .env.example .env
```
以下是必要的 API 密钥列表:
```
ANTHROPIC_API_KEY=your_anthropic_api_key
OPENAI_API_KEY=your_openai_api_key
LANGSMITH_TRACING=true
LANGSMITH_ENDPOINT=https://api.smith.langchain.com
LANGSMITH_API_KEY=your_langsmith_api_key
LANGSMITH_PROJECT=your_langsmith_project
```
4. 配置 MCP 工具
将示例文件 `mcp_config_sample.json` 重命名为 `mcp_config.json` 文件。
以下是一个示例配置:
```json
{
"mcpServers": {
"desktop-commander": {
"command": "npx",
"args": [
"-y",
"@smithery/cli@latest",
"run",
"@wonderwhy-er/desktop-commander",
"--key",
"Smithery API_KEY"
]
},
"perplexity-search": {
"command": "npx",
"args": [
"-y",
"@smithery/cli@latest",
"run",
"@arjunkmrm/perplexity-search",
"--config",
"{\"perplexityApiKey\":\"Perplexity API_KEY\"}"
]
},
"hyperbrowser": {
"command": "npx",
"args": [
"-y",
"@smithery/cli@latest",
"run",
"@hyperbrowserai/mcp",
"--key",
"Smithery API_KEY"
]
},
"todoist-mcp": {
"command": "npx",
"args": [
"-y",
"@smithery/cli@latest",
"run",
"@miottid/todoist-mcp",
"--key",
"Smithery API_KEY"
]
}
}
}
```
从 [Smithery](https://smithery.ai/) 获取 MCP 工具的 JSON 配置,并添加到 `mcp_config.json` 文件中。
1. 访问 [Smithery](https://smithery.io) 网站,选择要使用的工具。
2. 在工具页面上,点击右上角的“COPY”按钮复制 JSON 配置。
3. 打开 `mcp_config.json` 文件并添加复制的 JSON。
**重要**:文件名称必须为 `mcp_config.json`。如果使用其他名称,程序可能无法正常运行。
## 运行应用程序
完成所有配置后,可以使用以下命令启动 LangGraph 开发服务器:
```bash
langgraph dev
```
如果服务器启动成功,可以在网页浏览器中通过本地地址(通常为 http://localhost:3000)访问应用程序。
## 连接到 teddyflow.com
1. 在终端中运行 `langgraph dev` 命令启动开发服务器。
2. 在 teddyflow.com 上注册账户。
注册时,在“Beta 密钥”中输入 `teddynote-youtube`,即可无需批准直接注册。

3. 登录后,点击“连接新应用”按钮。

4. 输入应用名称,点击“连接”按钮。
5. 在选项卡中选择“LangGraph”,并输入以下信息:
- 端点:`http://localhost:2024`
- 图表:`agent`

6. 完成连接设置后,点击“保存”按钮。
7. 点击“连接应用”按钮保存。
## 公司/社区徽标和品牌定制
我们为公司/社区推出了定制功能。

如果您有兴趣采用此功能,请发送电子邮件至 service@brain-crew.com,我们将为您提供帮助。
## 许可证
Apache License 2.0 ([LICENSE](LICENSE))