OCR文本提取服务

一个基于Mistral OCR API的MCP服务器,提供从PDF和图像中提取文本内容的功能,适用于文档处理和笔记整理。

  • by lemopian
  • Python
  • 本地部署
  • 8 星标
  • 更新于
在 GitHub 查看 lemopian/mistral-ocr-mcp

使用说明

Mistral OCR MCP服务器

一种模型上下文协议(MCP)服务器,使用Mistral的OCR API提供OCR(光学字符识别)功能。此服务器允许您通过兼容MCP的客户端(如Cursor和Claude Desktop)从PDF文件和图像中提取文本内容。

📖 有关更多上下文和实际使用示例,请阅读相关文章: 我如何使用Mistral Document AI整合我的笔记

使用示例流程图

特性

  • 从PDF文件和图像(JPG、JPEG、PNG、TIFF、BMP)中提取文本
  • 返回具有逐页细分的结构化内容
  • 与MCP客户端无缝集成
  • 采用FastMCP构建,实现最佳性能

先决条件

安装

  1. 克隆存储库:

    git clone https://github.com/lemopian/mistral-ocr-mcp.git
    cd mistral-ocr-mcp
    
  2. 使用uv安装依赖项:

    uv sync
    
  3. 设置环境变量: 创建一个 .env 项目根目录中的文件:

    echo "MISTRAL_API_KEY=your_mistral_api_key_here" > .env
    

MCP客户端的配置

将以下配置添加到MCP客户端配置文件中:

{
  "mcpServers": {
    "mistral-ocr": {
      "command": "/Users/yourusername/.local/bin/uv",
      "args": [
        "--directory",
        "/path/to/mistral-ocr-mcp",
        "run",
        "main.py"
      ]
    }
  }
}

重要提示: 替换 /path/to/mistral-ocr-mcp 使用克隆存储库的实际路径。

用法

配置后,服务器提供以下工具:

extract_file_content

从PDF文件和图像中提取文本内容。

参数:

  • file_path (string):PDF或图像文件的本地路径

退货:

  • 以字符串形式提取文本内容

支持的格式:

  • PDF文件(.pdf)
  • 图像文件(.jpg, .jpeg, .png, .tiff, .bmp)

示例用法:

Please extract the text from this document: /path/to/your/document.pdf

发展

直接运行服务器

uv run main.py

项目结构

mistral-ocr-mcp/
├── mistral_ocr/          # Package directory
│   ├── __init__.py       # Package initialization
│   └── extractor.py      # Mistral OCR functionality
├── docs/                 # Documentation
│   └── flowchart.png     # Architecture flowchart
├── main.py               # MCP server implementation
├── pyproject.toml        # Project dependencies and configuration
├── uv.lock              # Dependency lock file
├── .env                 # Environment variables (create this)
├── .gitignore           # Git ignore rules
└── README.md            # This file

环境变量

  • MISTRAL_API_KEY:您的Mistral API密钥(必需)

故障排除

  1. “必须设置MISTRAL_API_KEY”错误:

    • 确保您已创建 .env 使用Mistral API密钥文件
    • 验证API密钥是否有效
  2. “找不到文件”错误:

    • 检查文件路径是否正确且可访问
    • 确保支持该文件格式
  3. MCP连接问题:

    • 验证路径 uv MCP配置正确
    • 确保存储库路径绝对正确
    • 检查所有依赖项是否已安装 uv sync