AI代理框架

一个基于模型上下文协议(MCP)的综合AI代理框架,具有多个专用服务器和LangChain集成,适用于智能代理开发和任务自动化。

  • by BharathiThanikonda
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 bharathithanikonda/mcp-ai-agent

使用说明

MCP AI代理演示

一个全面的人工智能代理框架,使用模型上下文协议(MCP),具有多个专用服务器和LangChain集成。

🚀 特性

  • 多服务器MCP架构:连接到多个专用MCP服务器
  • 基于LangChain的人工智能代理:使用Groq Qwen模型的智能代理
  • 数学运算服务器:基本算术运算
  • 气象信息服务器:基于位置的天气数据
  • web界面:基于FastAPI的web服务器,便于交互
  • CLI接口:用于快速操作的命令行工具
  • 增强的错误处理:强大的错误管理和日志记录
  • 配置管理:基于环境的配置

📋 先决条件

  • Python 3.13+
  • Groq API 密钥
  • 天气数据的互联网连接

🛠️ 安装

  1. 克隆存储库:
git clone <your-repo-url>
cd mcp-ai-agent-demo
  1. 安装依赖项:
pip install -e .
  1. 设置环境变量:
cp .env.example .env
# Edit .env and add your GROQ_API_KEY

🎯 用法

1.基本客户端使用

python client.py

2.Web界面

python web_interface.py

然后访问 http://localhost:8000

3.CLI工具

python cli_tool.py --help
python cli_tool.py math "What is 15 * 23?"
python cli_tool.py weather "New York"

4.独立服务器

# Math server
python mathserver.py

# Weather server
python weatherserver.py

🏗️ 建筑

┌─────────────────┐    ┌─────────────────┐    ┌─────────────────┐
│   Web Interface │    │   CLI Tool      │    │   Client.py     │
└─────────┬───────┘    └─────────┬───────┘    └─────────┬───────┘
          │                      │                      │
          └──────────────────────┼──────────────────────┘
                                 │
                    ┌─────────────┴─────────────┐
                    │    MultiServerMCPClient   │
                    └─────────────┬─────────────┘
                                  │
                    ┌─────────────┴─────────────┐
                    │                          │
            ┌───────▼──────┐        ┌─────────▼─────────┐
            │ Math Server  │        │ Weather Server    │
            │ (stdio)      │        │ (http)            │
            └──────────────┘        └───────────────────┘

🔧 配置

创建一个 .env 文件包含:

GROQ_API_KEY=your_groq_api_key_here
WEATHER_API_KEY=your_weather_api_key_here  # Optional

📁 项目结构

mcp-ai-agent-demo/
├── client.py              # Main client with AI agent
├── web_interface.py       # FastAPI web server
├── cli_tool.py           # Command-line interface
├── mathserver.py         # Math operations MCP server
├── weatherserver.py      # Weather data MCP server
├── config.py             # Configuration management
├── utils.py              # Utility functions
├── pyproject.toml        # Project dependencies
└── README.md            # This file

🤝 贡献

  1. 分叉存储库
  2. 创建要素分支
  3. 进行更改
  4. 如果适用,添加测试
  5. 提交拉取请求

📄 许可证

MIT许可证-有关详细信息,请参阅许可证文件

🙏 致谢

  • AI框架的LangChain
  • 语言模型的Groq
  • 协议规范的MCP