文档导航器MCP
一个功能强大的文档助手,结合了 模型上下文协议(MCP) 随着 克劳德·艾 为您的文档文件提供智能问答。采用FastMCP和Gradio构建,易于使用的web界面。
✨ 特性
- 🔍 智能文档搜索:在文档文件中进行全文搜索
- 🤖 AI驱动的响应:使用Claude AI根据您的文档提供智能答案
- 📁 多格式支持:与合作
.md,.txt,.rst,.pdf,以及图像文件 - 🔤 OCR功能:使用Tesseract OCR从基于图像的PDF和独立图像中提取文本
- 📄 高级PDF支持:混合PDF处理,扫描文档自动回退到OCR
- 🌐 web界面:基于Gradio的干净聊天界面
- ⚡ MCP集成:利用模型上下文协议实现无缝工具集成
- 🔧 轻松设置:配置和部署简单
🏗️ 建筑
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Gradio UI │───▶│ Client Agent │───▶│ Claude AI │
│ (Chat Interface)│ │ (MCP Client) │ │ (Anthropic) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
▼
┌──────────────────┐
│ MCP Server │
│ (FastMCP) │
└──────────────────┘
│
▼
┌──────────────────┐
│ docs/ folder │
│ (.md, .txt, │
│ .rst files) │
└──────────────────┘🚀 快速开始
先决条件
- Python 3.10或更高版本
- 人类API密钥
- UV包管理器(推荐)或pip
1.克隆和设置
git clone
cd docs-navigator2.安装依赖项
使用紫外线(推荐):
uv sync或者使用pip:
pip install -r requirements.txt3.配置环境
创建一个 .env 文件:
echo "ANTHROPIC_API_KEY=your_api_key_here" > .env4.添加您的文档
将文档文件放在 docs/ 目录:
docs/
├── overview.md
├── setup.md
├── troubleshooting.md
└── your-other-docs.txt5.启动应用程序
# Using UV
uv run app_gradio.py
# Or directly with Python
python app_gradio.py该应用程序将在 http://127.0.0.1:7860
📚 使用示例
应用程序运行后,您可以提出以下问题:
- “如何设置身份验证?”
- “连接问题的故障排除步骤是什么?”
- “在哪里可以找到有关API端点的信息?”
- “总结文档中提到的主要功能”
人工智能将搜索您的文档,并提供与源文件相关的上下文答案。
🛠️ 发展
项目结构
docs-navigator/
├── app_gradio.py # Gradio web interface
├── client_agent.py # MCP client and Claude integration
├── server_docs.py # MCP server with doc tools
├── docs/ # Your documentation files
├── tests/ # Test scripts
│ ├── test_mcp.py # Test MCP server functionality
│ ├── test_anthropic.py # Test Claude API connection
│ └── test_complete.py # End-to-end functionality test
├── .env # Environment variables
├── pyproject.toml # Project configuration
└── requirements.txt # Python dependencies可用的MCP工具
服务器将这些工具暴露给AI:
list_docs():获取所有可用文档文件的列表search_docs(query, max_results):在所有文档中搜索特定内容
测试
运行测试套件:
# Test MCP server functionality
python test_mcp.py
# Test Claude API connection
python test_anthropic.py
# Test complete end-to-end functionality
python test_complete.py🔧 配置
环境变量
| 变量 | 描述 | 必填 |
|---|---|---|
ANTHROPIC_API_KEY | 您的人类克劳德API钥匙 | 是 |
支持的文件格式
- 标记语言:
.md - 文本:
.txt - 重新结构化文本:
.rst - PDF文档:
.pdf(文本提取+OCR用于基于图像的内容) - 图像文件:
.png,.jpg,.jpeg,.tiff,.tif,.bmp,.gif(OCR文本提取)
OCR要求
对于基于图像的PDF和图像文件处理,请安装Tesseract OCR:
窗户:
# Download and install from: https://github.com/UB-Mannheim/tesseract/wiki
# Or install via chocolatey:
choco install tesseractmacOS:
brew install tesseractUbuntu/Debian:
sudo apt-get install tesseract-ocr
sudo apt-get install poppler-utils # For PDF image conversion附加语言包(可选):
- Windows:在Tesseract安装过程中选择
- macOS:
brew install tesseract-lang - Ubuntu:
sudo apt-get install tesseract-ocr-[language_code]
模型配置
该应用程序当前使用 claude-3-haiku-20240307。要更改模型,请在中编辑模型名称 client_agent.py:
model="claude-3-haiku-20240307" # Change to your preferred model🐛 故障排除
常见问题
- “找不到模型”错误:您的API密钥可能无法访问指定的Claude模型。该应用程序将自动测试可用模型。
- MCP连接问题:确保
server_docs.py脚本是可执行的,并且位于正确的位置。
- 未找到文档:确保您的文档文件在
docs/具有支持扩展名的文件夹。
- Gradio界面未加载:检查端口7860是否可用,或在中修改端口
app_gradio.py.
调试模式
通过修改相应文件中的日志记录级别来启用详细日志记录。
🤝 贡献
- 复刻仓库
- 创建功能分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
📄 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
🙏 致谢
- 内置于 FastMCP 用于模型上下文协议集成
- 由...驱动 安thropic克劳德 AI响应
- 使用创建的UI Gradio
- 软件包管理 紫外线
______________________________________________________________________
有关更多详细说明,请参阅 入门指南.
