Alumx MCP服务器
用于农业智能的模型上下文协议(MCP)服务器,通过语义搜索提供害虫/疾病查找、政府方案发现和SME知识检索的工具。
______________________________________________________________________
特性
- 病虫害 --基于RAG的作物病虫害信息查找
- 政府计划 --RAG按类型和州搜索与农业相关的政府计划
- 中小企业部 --Pinecone知识库(SME-Divesh命名空间)上的语义搜索
- MCP+休息 --双接口:MCP协议(通过FastMCP)和纯REST(
/callTool)
______________________________________________________________________
需求
- Python 3.9+
- 依赖关系(通过安装
pip install -r requirements.txt):
fastmcp
pinecone
sentence-transformers
python-dotenv
uvicorn
httpx
fastapi______________________________________________________________________
环境变量
创建一个 .env 项目根目录中的文件,包含以下变量:
| 变量 | 必填 | 描述 |
|---|---|---|
PESTS_DISEASES_RAG_URL | ✅ | 病虫害RAG服务的基本URL |
GOVT_SCHEMES_RAG_URL | ✅ | 政府计划RAG服务的基本URL |
PINECONE_API_KEY | ✅ | Pinecone的API密钥 |
PINECONE_INDEX | ✅ | 要查询的松果索引的名称 |
RAG_TIMEOUT | ❌ | RAG调用的HTTP超时(秒)(默认值: 30) |
示例 .env:
PESTS_DISEASES_RAG_URL= ___URL__
GOVT_SCHEMES_RAG_URL= __URL__
PINECONE_API_KEY=your-pinecone-api-key
PINECONE_INDEX=your-index-name
RAG_TIMEOUT=30______________________________________________________________________
运行服务器
python alumnx_mcp_server.py服务器启动于 端口9000 默认情况下。
| 端点 | 描述 |
|---|---|
/mcp | MCP协议端点(FastMCP) |
/callTool | REST工具调用端点 |
/list-tools | 列出所有可用工具 |
/health | 健康检查 |
______________________________________________________________________
MCP工具
pests_and_diseases
查询RAG系统,了解影响作物的病虫害信息。
| 参数 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
pest_name | string | ✅ | — | 病虫害名称 |
crop | string | ❌ | "General" | 受虫害或病害影响的作物 |
示例响应:
{
"status": "success",
"information": "...",
"sources": ["..."]
}______________________________________________________________________
govt_schemes
查询RAG系统中与农业相关的政府方案。
| 参数 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
scheme_type | string | ✅ | — | 方案的类型或主题 |
state | string | ❌ | "All India" | 检索方案的州 |
示例响应:
{
"status": "success",
"information": "...",
"sources": ["..."]
}______________________________________________________________________
sme_divesh
使用以下方法对SME Divesh Pinecone命名空间进行语义搜索 all-MiniLM-L6-v2 嵌入。
| 参数 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
query | string | ✅ | — | 搜索查询 |
top_k | 整数 | ❌ | 5 | 要返回的顶级结果数 |
示例响应:
{
"status": "success",
"query": "crop irrigation techniques",
"results": [
{
"score": 0.91,
"text": "...",
"source": "...",
"chunk_index": 2
}
]
}______________________________________________________________________
REST API使用
所有工具也可以通过调用 /callTool POST端点:
curl -X POST http://localhost:9000/callTool \
-H "Content-Type: application/json" \
-d '{
"name": "pests_and_diseases",
"arguments": {
"pest_name": "aphids",
"crop": "wheat"
}
}'______________________________________________________________________
建筑
┌─────────────────────────────────────────┐
│ Alumnx MCP Server │
│ │
│ FastAPI App │
│ ├── /mcp ← FastMCP (MCP) │
│ ├── /callTool ← REST interface │
│ ├── /list-tools ← Tool discovery │
│ └── /health ← Health check │
│ │
│ Tools │
│ ├── pests_and_diseases → RAG HTTP call │
│ ├── govt_schemes → RAG HTTP call │
│ └── sme_divesh → Pinecone │
└─────────────────────────────────────────┘______________________________________________________________________
