🤖 MCP代理AI(MCP v1.25+Streamlit)
该项目展示了 模型上下文协议(MCP) 基于 代理人工智能系统 使用:
- MCP v1.25.0(Anthropic SDK)
- 自定义MCP工具 (Arxiv,维基百科,数学)
- LLM(Groq-火焰3.1)
- 流式前端
- 基于SSE的MCP客户端-服务器架构
______________________________________________________________________
📁 项目结构
mcp-agentic-ai/
│
├── client/
│ ├── __init__.py
│ ├── agent.py # MCP client (SSE-based)
│ └── llm.py # LLM configuration
│
├── frontend/
│ ├── __init__.py
│ └── app.py # Streamlit UI
│
├── server/
│ ├── __init__.py
│ ├── mcp_server.py # MCP server (SSE ASGI app)
│ └── tools/
│ ├── __init__.py
│ ├── arxiv_tool.py
│ ├── math_tool.py
│ └── wiki_tool.py
│
├── main.py # CLI test runner
├── .env # Environment variables
├── requirements.txt
└── README.md______________________________________________________________________
⚙️ 需求
- python 3.10+ (在Python 3.12上测试)
- 推荐虚拟环境
- Groq API密钥
______________________________________________________________________
📦 再进行
python -m venv .venv
.venv\Scripts\activate # Windows
# source .venv/bin/activate # Linux / Mac
pip install -r requirements.txt______________________________________________________________________
🔐 环境设置
创建一个 .env 项目根目录中的文件:
GROQ_API_KEY=your_groq_api_key_here______________________________________________________________________
🚀 如何运行项目
1.️⃣ 启动MCP服务器(必需)
MCP v1.25使用 上海证券交易所,所以服务器 必须与Uvicorn一起运行
自 项目根目录:
uvicorn server.mcp_server:app --host 127.0.0.1 --port 3333您应该看到:
Uvicorn running on http://127.0.0.1:3333这暴露了:
/sse/tools
______________________________________________________________________
2.️⃣ 启动Streamlit前端
打开A 新终端 (保持MCP服务器运行):
streamlit run frontend/app.py然后在浏览器中打开:
http://localhost:8501______________________________________________________________________
🧪 查询示例
Find research on LLM agents,
explain simply,
and calculate (5 * 6) + 10______________________________________________________________________
🧠 工作原理(高级)
- 流线型UI 发送用户问题
- MCP客户端(SSE) 连接到MCP服务器
- 客户端获取可用工具
- LLM收到:
- 系统提示 - 可用的MCP工具 - 用户提问
- LLM使用工具上下文生成响应
______________________________________________________________________
🛠 可用的MCP工具
| 工具 | 说明 |
|---|---|
search_arxiv | 获取研究论文 |
search_wikipedia | 获取主题解释 |
add, multiply | 数学计算 |
______________________________________________________________________
👤 作者
胡森巴沙 代理人工智能和MCP学习项目
______________________________________________________________________
