文档解析服务

SoMark MCP Server是一款基于Model Context Protocol的文档解析服务,能够将PDF和图像文件高精度转换为Markdown和JSON格式。

  • by SoMarkAI
  • JavaScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 SoMarkAI/somark_mcp

使用说明

SoMark MCP Server

English | 中文

A Model Context Protocol (MCP) server for SoMark's document parsing API. It parses PDF and image files into Markdown, JSON format with high accuracy.

Quick Start

1. Get your API Key

2. Add the following to your MCP client configuration (Claude Desktop, VS Code, Cursor, etc.):

{
    "mcpServers": {
        "somark": {
            "command": "npx",
            "args": ["-y", "somark-mcp"],
            "env": {
                "SOMARK_API_KEY": "your-api-key-here",
                "SOMARK_API_BASE_URL": "https://somark.cn/api/v1"
            }
        }
    }
}

3. Done! Ask your AI assistant to parse any PDF or image file.

API Base URL Configuration

Set the SOMARK_API_BASE_URL environment variable to choose the server region:

Region SOMARK_API_BASE_URL
Mainland China (default) https://somark.cn/api/v1
Outside mainland China (including Taiwan, China; Hong Kong, China; Macau, China) https://somark.ai/api/v1

The server automatically derives the web, docs, and purchase URLs from SOMARK_API_BASE_URL:

Domain API Base Web Docs Purchase
somark.cn https://somark.cn/api/v1 https://somark.cn https://docs.somark.cn somark.cn/workbench/purchase
somark.ai https://somark.ai/api/v1 https://somark.ai https://docs.somark.ai somark.ai/studio/purchase

Available Tools

check_api_key

Check whether the SoMark API key is configured and ready to use.

set_api_key

Set or update the SoMark API key at runtime (useful when the environment variable is not set).

Parameter Type Required Description
api_key string Yes Your SoMark API key from somark.cn (mainland China) or somark.ai (outside mainland China, including Taiwan, China; Hong Kong, China; Macau, China)

extract_document

Parse PDF or image files (PNG, JPG, JPEG, BMP, TIFF, JP2, DIB, PPM, PGM, PBM, GIF, HEIC, HEIF, WebP, XPM, TGA, DDS, XBM) into markdown, json format.

Parameter Type Required Default Description
file_path string Yes — Absolute path to the PDF or image file
output_formats Array<"json" | "markdown"> No ["json", "markdown"] Output formats. Allowed values: json, markdown. Duplicate values are not allowed.
element_formats object No See below Element rendering formats.
feature_config object No See below Extraction options.

element_formats fields:

  • image: "url" | "base64" | "none", default url
  • formula: "latex" | "mathml" | "ascii", default latex
  • table: "html" | "markdown" | "image", default html
  • cs: "image", default image

feature_config fields:

  • enable_text_cross_page: boolean, default false
  • enable_table_cross_page: boolean, default false
  • enable_title_level_recognition: boolean, default false
  • enable_inline_image: boolean, default true
  • enable_table_image: boolean, default true
  • enable_image_understanding: boolean, default true
  • keep_header_footer: boolean, default false

Supported file formats:

  • PDF (.pdf)
  • PNG (.png)
  • JPEG (.jpg, .jpeg)
  • BMP (.bmp, .dib)
  • TIFF (.tiff, .tif)
  • JPEG 2000 (.jp2)
  • Portable Pixmap (.ppm)
  • Portable Graymap (.pgm)
  • Portable Bitmap (.pbm)
  • GIF (.gif)
  • HEIC (.heic)
  • HEIF (.heif)
  • WebP (.webp)
  • X PixMap (.xpm)
  • Targa (.tga)
  • DirectDraw Surface (.dds)
  • X BitMap (.xbm)

Example usage:

// Parse a PDF to Markdown
{
  "file_path": "/path/to/document.pdf",
  "output_formats": ["markdown"]
}

// Parse an image to JSON
{
  "file_path": "/path/to/image.png",
  "output_formats": ["json"]
}

Development

pnpm install          # Install dependencies
pnpm build            # Build the project
pnpm exec tsc --noEmit  # Type check

Testing

pnpm test             # Full MCP server test
pnpm test:api         # API connection test

Troubleshooting

Problem Solution
"API key not configured" Add SOMARK_API_KEY to your MCP client config, or use the set_api_key tool
Connection issues Check that your API key is valid and somark.cn / somark.ai (depending on region) is accessible. Set SOMARK_API_BASE_URL=https://somark.ai/api/v1 for outside mainland China (including Taiwan, China; Hong Kong, China; Macau, China).
Unsupported file format Supports PDF, PNG, JPG, JPEG, BMP, TIFF, JP2, DIB, PPM, PGM, PBM, GIF, HEIC, HEIF, WebP, XPM, TGA, DDS, XBM formats

License

ISC