Skip to main content

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 服务器正常运行,并已配置正确的向量索引。

Metadata

Release files for mcp-mongodb-bio-invasion 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-mongodb-bio-invasion 0.1.1
File Size Uploaded Provenance
mcp_mongodb_bio_invasion-0.1.1.tar.gz 10.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-mongodb-bio-invasion 0.1.1
File Interpreter ABI Platform
mcp_mongodb_bio_invasion-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.0 kB

Release files / mcp_mongodb_bio_invasion-0.1.1.tar.gz

Download URL mcp_mongodb_bio_invasion-0.1.1.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
275ae5072fd91763b5db06eae9127dec2e92d820736dbe76353b9de95fa6b591
BLAKE2b-256 checksum
How to use checksums
9809386e82d99190162f3af60953deefd0d8356a6a7cb611fcb4bcd867ea52dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.16

Release files / mcp_mongodb_bio_invasion-0.1.1-py3-none-any.whl

Download URL mcp_mongodb_bio_invasion-0.1.1-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f18dec5b65d4d68d467fe23eff780226fb4cb4f4a88b8466ff9399f6ee66113
BLAKE2b-256 checksum
How to use checksums
667757a94754a0c0aeaae83af660a8dc5302004a146b10050917a2bdfbaa4752
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.16

Security for mcp-mongodb-bio-invasion 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page