Skip to main content

MongoDB生物入侵研究MCP服务器 - 自然语言查询工具

Project description

MongoDB 生物入侵研究 MCP 服务器

一个基于 Model Context Protocol (MCP) 的 MongoDB 自然语言查询服务器,专门用于生物入侵研究数据的智能检索和分析。

🚀 功能特性

  • 自然语言查询: 使用向量搜索技术实现自然语言到 MongoDB 查询的转换
  • 智能重排序: 集成 BGE 重排序模型提升搜索结果相关性
  • AI 增强: 可选 DeepSeek API 对查询结果进行智能解释和增强
  • MCP 标准兼容: 遵循 MCP 1.13.1 规范,可与各种 MCP 客户端集成

📦 安装依赖

# 使用 uv 包管理器安装
uv sync

# 或者使用 pip
pip install -e .

⚙️ 环境配置

创建 .env 文件并配置以下环境变量:

# MongoDB 配置
MONGO_URI=mongodb://localhost:27017/
MONGO_DB_NAME=中国生物入侵研究
MONGO_COLLECTION=生物入侵研究

# 模型配置
EMBEDDING_MODEL=dengcao/Qwen3-Embedding-8B:Q5_K_M
RERANKER_MODEL=BAAI/bge-reranker-large

# DeepSeek API 配置(可选)
DEEPSEEK_API_KEY=your_deepseek_api_key_here
DEEPSEEK_API_URL=https://api.deepseek.com/v1/chat/completions

🛠️ 可用工具

1. text_to_vector

将文本转换为 768 维嵌入向量

参数:

  • text (string, 必需): 需要转换的文本(建议 ≤512 字符)

示例:

{
  "text": "生物入侵对生态系统的影响"
}

2. query_mongo_nl

自然语言查询 MongoDB 数据库

参数:

  • query_text (string, 必需): 自然语言查询语句
  • limit (int, 可选, 默认=5): 返回结果数量(1-20)
  • use_reranker (bool, 可选, 默认=true): 是否使用 BGE 模型重排序
  • enhance (bool, 可选, 默认=false): 是否用 DeepSeek 增强结果

示例:

{
  "query_text": "查找关于外来物种入侵的研究",
  "limit": 10,
  "use_reranker": true,
  "enhance": true
}

3. list_tools

查看所有可用工具列表及参数说明

🚀 启动服务器

# 使用 uv 运行
uv run python mcp_mongodb_server.py

# 或者直接运行
python mcp_mongodb_server.py

服务器启动后将通过 stdio 与 MCP 客户端通信。

📊 数据结构要求

MongoDB 集合需要包含以下字段以支持向量搜索:

{
  "_id": ObjectId,
  "content": "文档内容文本",
  "embedding": [0.1, 0.2, 0.3, ...], // 768 维向量
  // 其他相关字段...
}

需要创建向量索引:

db.collection.createIndex({
  "embedding": "vector"
}, {
  "name": "vector_index",
  "type": "vector",
  "dimension": 768,
  "similarity": "cosine"
})

🔧 技术栈

  • MCP Server: mcp[cli]>=1.13.1
  • 数据库: pymongo>=4.6.0
  • 机器学习: transformers>=4.37.0, torch>=2.1.0
  • HTTP 请求: requests>=2.31.0
  • 环境管理: python-dotenv>=1.0.0

🎯 使用场景

  1. 科研人员: 快速检索生物入侵相关研究文献
  2. 政策制定者: 分析入侵物种的影响和应对策略
  3. 教育工作者: 获取教学案例和研究资料
  4. 环保组织: 监测和评估生物入侵状况

🤝 贡献指南

  1. Fork 本项目
  2. 创建特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启 Pull Request

📄 许可证

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情

🙏 致谢

📞 支持

如有问题或建议,请提交 Issue 或联系开发团队。


注意: 使用前请确保 MongoDB 服务器正常运行,并已配置正确的向量索引。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_mongodb_bio_invasion-0.1.1.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_mongodb_bio_invasion-0.1.1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file mcp_mongodb_bio_invasion-0.1.1.tar.gz.

File metadata

File hashes

Hashes for mcp_mongodb_bio_invasion-0.1.1.tar.gz
Algorithm Hash digest
SHA256 275ae5072fd91763b5db06eae9127dec2e92d820736dbe76353b9de95fa6b591
MD5 ecddc2c79e757f84f100f66a8b760c87
BLAKE2b-256 9809386e82d99190162f3af60953deefd0d8356a6a7cb611fcb4bcd867ea52dc

See more details on using hashes here.

File details

Details for the file mcp_mongodb_bio_invasion-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_mongodb_bio_invasion-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f18dec5b65d4d68d467fe23eff780226fb4cb4f4a88b8466ff9399f6ee66113
MD5 784c4398159236e82d32987f2c1c8013
BLAKE2b-256 667757a94754a0c0aeaae83af660a8dc5302004a146b10050917a2bdfbaa4752

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page