OCR服务

一个基于HunyuanOCR模型的本地OCR服务,支持图片和PDF的文本识别,适用于开发者和桌面应用集成。

  • by sebkrummen
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 beingmyself-tc/mcp-ocr

使用说明

MCP浑源OCR服务器

一种模型上下文协议(MCP)服务器,使用 浑源OCR 模型(1B参数)。

特性

  • 本地处理:完全在您的机器上使用PyTorch运行。
  • 苹果硅技术支持:在Mac上自动使用MPS(金属性能着色器)进行加速。
  • MCP兼容:适用于Claude Desktop、VS Code(通过MCP扩展)和其他MCP客户端。

先决条件

  • Python 3.10+
  • uv (推荐)或 pip
  • poppler (需要PDF支持)
    • macOS: brew install poppler
    • Ubuntu: sudo apt-get install poppler-utils
    • Windows:下载并添加到PATH

安装

  1. 克隆存储库:

    git clone https://github.com/beingmyself-tc/mcp-ocr.git
    cd mcp-ocr
    
  2. 安装依赖项:

    # Using uv (recommended)
    uv sync
    
    # OR using pip
    pip install .
    

用法

运行服务器

您可以直接运行服务器:

# If installed with uv
uv run mcp-ocr

# If installed with pip
python -m mcp_ocr.server

使用Claude Desktop进行配置

将以下内容添加到您的 claude_desktop_config.json:

{
  "mcpServers": {
    "mcp-ocr": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/mcp-ocr",
        "run",
        "mcp-ocr"
      ]
    }
  }
}

使用VS代码进行配置

要将此MCP服务器与VS代码一起使用,请将以下内容添加到全局MCP设置文件中(通常 ~/Library/Application Support/Code/User/mcp.json 在macOS上):

{
  "servers": {
    "mcp-ocr": {
      "type": "stdio",
      "command": "/absolute/path/to/mcp-ocr/.venv/bin/python",
      "args": [
        "-m",
        "mcp_ocr.server"
      ]
    }
  }
}

确保更换 /absolute/path/to/mcp-ocr 使用克隆存储库的实际路径。

工具

ocr_image

对单个图像文件执行OCR。

  • 输入:
    • image_path (string)-图像文件的绝对路径(例如.jpg、.png)。
    • mode (字符串,可选)-处理模式:
      • "ocr" (默认):检测文本并输出坐标。
      • "format":提取Markdown/HTML/LaTeX中的文本/表格/公式。
      • "formula":提取LaTeX中的配方。
      • "table":提取HTML格式的表。
      • "translation":摘录并翻译成英文。
  • 输出:摘录文本。

ocr_pdf

对PDF文件执行OCR。

  • 输入:
    • pdf_path (string)-PDF文件的绝对路径。
    • mode (字符串,可选)-与相同的模式 ocr_image.
  • 输出:提取的文本(连接的页面)。

许可证

麻省理工学院