Doc Extract Mcp

io.github.koraynar由 GitHub 账号 koraynar 发布v0.1.0更新于 Oct 27, 2026

Document tooling for AI agents: PDF/text reading, chunking, schema-validated JSON output.

已验证STDIO仅桌面文件与存储数据与分析

概览

AI 生成的概览

本地 MCP 服务器,为助手提供确定性的文档工具:列出、读取与切分 PDF 和文本文件,按 JSON Schema 校验结果并保存输出。

可以做什么
  • 在允许的根目录下列出文件,支持递归 glob 模式
  • 读取 PDF(带页码标记与页码范围)、文本、Markdown、JSON 和 CSV 的正文
  • 查看元数据,如类型、大小、页数和行数
  • 把长文档切分为带重叠和页码提示的有序分块
  • 按 JSON Schema 校验 JSON,并用 JSON Pointer 路径报告全部错误
  • 在允许的根目录内把提取结果写成 JSON 或 CSV,并返回行数与字节数
适用场景
适合需要把发票、采购单、报告等杂乱 PDF 转成符合 schema 的 JSON 的场景,并希望文件访问被限制在单一目录、由服务器完成确定性的切分与校验,而不是让模型自行读取文件。
运行要求
以 stdio 方式在本机运行;需要 Python 3.11+ 与 uv,并从项目仓库安装。环境变量 DOC_EXTRACT_ROOT 指定唯一可读写的目录,未设置时默认为服务器的工作目录。仅支持桌面版 MCP 客户端。
安装前请注意
该服务器会写文件:save_structured 会在允许的根目录内生成 JSON 或 CSV,因此应把 DOC_EXTRACT_ROOT 指向专用目录而非敏感目录。作者说明项目较新、尚无生产使用经验,除测试和路径限制保护外未做进一步加固。仅支持文本型 PDF,扫描件会得到空文本且没有 OCR。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Doc Extract Mcp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

doc-extract-mcp

An MCP (Model Context Protocol) server that gives an LLM deterministic document tooling for structured-data extraction workflows. The LLM does the reading and extraction reasoning; this server provides the parts that should never be left to a language model: reliable file access, parsing, chunking, JSON Schema validation, and guarded file output.

Built by Koray Nar as a portfolio project for the AI document-automation workflows he is building — the target use case is turning messy PDFs (purchase orders, invoices, reports) into schema-validated JSON. Published as part of a public portfolio. Pairs with Claude Code and Claude Desktop, and with any other MCP client.

Why

An extraction agent fails in predictable places: it hallucinates file contents, loses track of long documents, silently produces JSON that almost matches the target schema, and writes output wherever it likes. This server removes those failure modes:

  • File access is confined to one allowed root (DOC_EXTRACT_ROOT).
  • PDF text arrives with explicit --- page N --- markers, so citations of "page 3" mean page 3.
  • Long documents are chunked deterministically with overlap and page hints.
  • Extracted JSON is checked against a JSON Schema (Draft 2020-12) and every error is reported with a JSON Pointer path — not just the first — so the model can fix all mistakes in one pass.
  • Output is written by the server (JSON or CSV), inside the same root, with a verifiable row/byte count.

Tools

ToolArgumentsWhat it does
list_documentsdirectory, glob_pattern='*'List files under a directory inside the allowed root, with size and modified time. Supports recursive globs like **/*.pdf. Patterns must be relative and free of ..; matches resolving outside the root are dropped.
read_documentpath, pages=''Return a document's text. .pdf via pypdf with --- page N --- markers and optional 1-indexed page selection ('3', '1-5', '1-3,7'); .txt/.md/.json read directly; .csv rendered as an aligned text table. Clear error for unsupported types.
document_infopathMetadata without full content: type, size, modified time; page count and PDF metadata for PDFs; line count for text files.
chunk_documentpath, max_chars=4000, overlap=200Split a document into ordered overlapping chunks, each with an index, start offset, and (for PDFs) a page hint.
validate_jsondata, json_schemaValidate a JSON string against a JSON Schema (Draft 2020-12). Returns every validation error with a JSON Pointer path via Draft202012Validator.iter_errors.
save_structuredpath, data, format='json'|'csv'Write extracted data inside the allowed root. CSV expects a JSON array of flat objects. Returns written path, row count, and byte count.

All path arguments are resolved and refused if they escape the allowed root (path traversal guard). The glob_pattern argument is confined the same way: absolute patterns and patterns containing .. are rejected, and any match that resolves outside the root (for example through a symlink) is silently dropped from the listing. Guard failures are raised as MCP tool errors, so the calling model sees the actual reason, not a masked generic error.

Quickstart

Requires Python 3.11+ and uv.

bash
git clone https://github.com/koraynar/doc-extract-mcp.gitcd doc-extract-mcpuv venvuv pip install -e .

Run standalone (stdio transport):

bash
DOC_EXTRACT_ROOT=/path/to/your/documents uv run doc-extract-mcp

Claude Code

bash
claude mcp add doc-extract --env DOC_EXTRACT_ROOT=/path/to/your/documents \  -- uv run --directory /absolute/path/to/doc-extract-mcp doc-extract-mcp

Claude Desktop

Add to claude_desktop_config.json:

json
{  "mcpServers": {    "doc-extract": {      "command": "uv",      "args": [        "run",        "--directory",        "/absolute/path/to/doc-extract-mcp",        "doc-extract-mcp"      ],      "env": {        "DOC_EXTRACT_ROOT": "/path/to/your/documents"      }    }  }}

DOC_EXTRACT_ROOT defaults to the server's working directory if unset. Set it to the folder your documents live in; nothing outside it can be read or written.

Typical workflow

  1. list_documents(".", "*.pdf") — find the invoices.
  2. document_info("invoice.pdf") — check the page count.
  3. read_document("invoice.pdf", "1-3") or chunk_document(...) — get text.
  4. The LLM extracts fields into JSON.
  5. validate_json(data, json_schema) — fix every reported error, revalidate.
  6. save_structured("out/invoice.json", data, "json") — write the result.

Limitations (honest ones)

  • Text-based PDFs only. Extraction uses pypdf; scanned/image-only PDFs yield empty text. There is no OCR.
  • Extraction quality varies with how the PDF was produced. Complex layouts (multi-column, heavy tables) may come out with imperfect reading order — that is a pypdf characteristic this server inherits.
  • No .docx / .xlsx support. Supported types are .pdf, .txt, .md, .csv, .json.
  • The server does no extraction reasoning. It will not find your invoice total; it makes sure the model that does is working from real text and that the result matches your schema.
  • This is a working tool, built for the AI-automation work I'm building up and published as part of my portfolio — it is new and has no production mileage yet. It has tests and a path-confinement guard, but it has not been hardened beyond that — review before pointing it at sensitive directories.

Development

bash
uv venvuv pip install -e '.[dev]'uv run pytest

The test suite builds a small two-page PDF fixture in-memory (a minimal hand-constructed PDF, no extra dependencies) and covers all six tools, the path-traversal guard, glob-pattern confinement (including symlink escapes), page-range errors, multi-error schema validation, a CSV round-trip, and tool registration plus error propagation through the MCP server object.

License

MIT © 2026 Koray Nar

来源:README.md,提交 409da2e

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.0最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分