纳米网MCP服务器
一种MCP(模型上下文协议)服务器,它公开了Nanonets OCR功能,用于将图像转换为结构化标记。
特性
- 高级OCR:使用Nanonets-OCR-s(3.75B参数模型)将文档转换为结构化markdown
- 多格式支持:处理图像、PDF、Word文档和Excel电子表格
- 图像:PNG、JPEG、BMP、TIFF、WEBP - 文件:PDF、DOCX、XLSX
- PDF处理:通过逐页OCR完成多页PDF文档处理
- Office文档处理:从Word和Excel文件中直接提取文本
- 智能识别:检测并转换:
- 文本和段落 - 具有结构保护的桌子 - LaTeX方程 - 带有描述的图像 - 签名和水印 - 复选框 - 复杂的布局 - 具有适当页面分隔的多页文档 - Word文档标题和格式 - Excel工作表和数据表
安装
选项1:Docker(建议搭配GPU)
# Clone the repository
git clone
cd nanonets_mcp
# Build and run with Docker Compose (requires NVIDIA Docker runtime)
docker-compose up --buildGPU支持的先决条件:
- 支持CUDA的NVIDIA GPU
- 安装
- Docker Compose v3.8+
选项2:本地安装
# Clone the repository
git clone
cd nanonets_mcp
# Install dependencies with uv
uv pip install -e .用法
运行服务器
使用Docker:
# Start with Docker Compose
docker-compose up
# Or run directly with Docker
docker run --gpus all -p 8000:8000 nanonets-mcp:latest本地安装:
# Start the MCP server
nanonets-mcp
# Or run directly
python -m nanonets_mcp.server可用工具
ocr_image_to_markdown
将图像转换为结构化markdown格式。
参数:
image_data(string):图像数据为base64字符串、数据URL或文件路径image_format(可选字符串):格式提示(png、jpg等)
退货: 文档的结构化标记表示
ocr_pdf_to_markdown
将整个PDF文档转换为结构化markdown格式。
参数:
pdf_data(string):PDF数据为base64字符串、数据URL或文件路径
退货: 整个PDF文档的结构化标记表示,带有页面分隔符
process_word_to_markdown
将Word文档(.docx)转换为结构化markdown格式。
参数:
docx_data(string):以base64字符串、数据URL或文件路径表示的Word文档数据
退货: 带有标题和表格的Word文档的结构化标记表示
process_excel_to_markdown
将Excel文件(.xlsx)转换为结构化markdown格式。
参数:
excel_data(string):Excel文件数据为base64字符串、数据URL或文件路径
退货: Excel工作簿中所有工作表的结构化标记表示
get_supported_formats
获取有关支持的格式和功能的信息。
退货: 支持格式、输入法、功能和处理选项的词典
可用资源
nanonets://model-info
提供有关Nanonets OCR模型的详细信息,包括功能和规格。
例子
OCR基本用法
图像处理
# Using file path
result = await ocr_image_to_markdown("/path/to/document.png")
# Using base64 data
with open("document.jpg", "rb") as f:
image_b64 = base64.b64encode(f.read()).decode()
result = await ocr_image_to_markdown(image_b64)
# Using data URL
data_url = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
result = await ocr_image_to_markdown(data_url)PDF处理
# Process entire PDF document
result = await ocr_pdf_to_markdown("/path/to/document.pdf")
# Using base64 PDF data
with open("document.pdf", "rb") as f:
pdf_b64 = base64.b64encode(f.read()).decode()
result = await ocr_pdf_to_markdown(pdf_b64)
# Result includes all pages with separators
# Example output:
# # PDF Document
# *Total pages: 3*
#
# ---
# # Page 1
# [Content of page 1]
#
# ---
# # Page 2
# [Content of page 2]
# ...Word文档处理
# Process Word document
result = await process_word_to_markdown("/path/to/document.docx")
# Using base64 Word document data
with open("document.docx", "rb") as f:
docx_b64 = base64.b64encode(f.read()).decode()
result = await process_word_to_markdown(docx_b64)
# Result includes text, headings, and tables
# Example output:
# # Word Document
#
# # Main Title
#
# This is a paragraph of text.
#
# ## Section Header
#
# More content here.
#
# | Name | Age | City |
# | --- | --- | --- |
# | John | 30 | NYC |Excel电子表格处理
# Process Excel file
result = await process_excel_to_markdown("/path/to/spreadsheet.xlsx")
# Using base64 Excel data
with open("spreadsheet.xlsx", "rb") as f:
excel_b64 = base64.b64encode(f.read()).decode()
result = await process_excel_to_markdown(excel_b64)
# Result includes all worksheets as tables
# Example output:
# # Excel Workbook
#
# ## Sheet: Employee Data
#
# | Name | Department | Salary |
# | --- | --- | --- |
# | Alice | Engineering | 75000 |
# | Bob | Marketing | 65000 |
#
# ## Sheet: Financial Data
#
# | Quarter | Revenue | Expenses |
# | --- | --- | --- |
# | Q1 | 150000 | 120000 |与Claude Desktop集成
添加到您的Claude Desktop配置中:
{
"mcpServers": {
"nanonets-ocr": {
"command": "nanonets-mcp"
}
}
}模型信息
- 模型:纳米网/纳米网-OCR-s
- 参数:3.75B(基于Qwen2.5-VL-3B指令)
- 输入:图像高达2048x2048像素(推荐)和PDF文档
- 输出:带语义标记的结构化标记
- PDF处理:200 DPI转换,所有页面按顺序处理
需求
核心依赖关系
- Python≥3.10
- PyTorch≥2.0.0
- 变压器=4.53.0
- PIL/枕头≥10.0.0
- MCP≥1.0.0
可选依赖关系
- pdf2image≥1.16.0(用于PDF支持)
- PyMuPDF≥1.23.0(用于PDF支持)
- python docx≥0.8.11(用于Word文档支持)
- openpyxl≥3.1.0(用于Excel支持)
- pandas≥2.0.0(用于Excel支持)
发展
测试
Docker测试:
# Test Docker build
docker-compose build
# Run health check
docker-compose up -d
docker-compose ps
# View logs
docker-compose logs -f nanonets-mcp
# Stop services
docker-compose down本地测试:
# Test with MCP Inspector
mcp dev nanonets_mcp/server.py
# Install for development
uv pip install -e .Docker管理
# Rebuild image after changes
docker-compose build --no-cache
# View resource usage
docker stats nanonets-mcp-server
# Access container shell
docker-compose exec nanonets-mcp bash
# Clean up volumes and images
docker-compose down -v
docker image prune -f许可证
\[在此处添加您的许可证信息\]
