mcpField
D
DocSlicer

DocSlicer

本地服务
docslicer.ai记忆与知识368 周前更新

关于 DocSlicer

DocSlicer 是面向处理长篇商务文档的开发者和 Agent 的确定性解析与分块工具。它无需调用大模型即可提取 PDF、Word、HTML 和 PowerPoint 的结构,并提供 Python 库及 MCP 服务,供客户端按需读取相关章节。

主要功能

  1. 01解析 PDF、Word、HTML 和 PowerPoint
  2. 02提取标题层级与结构化内容
  3. 03生成按标题组织且不重叠的文本块
  4. 04以多种格式表示表格
  5. 05保留多栏文档的阅读顺序
  6. 06为扫描页面提供可选 OCR

适用场景

  1. 01为 Agent 从长文档中检索章节
  2. 02为传统 RAG 准备结构化文本块
  3. 03批量处理商务文档

MCP 相关

MCP 服务允许客户端查看文档大纲并读取选定章节,以无向量检索方式获取内容,而无需将整份文档载入上下文。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库
安装包
mcpbdocslicer-0.2.5.mcpb0.2.5
pypidocslicer0.2.5

工具

5

收录的工具列表 · 更新于 2 周前

参数类型必填说明
sourcestring是
refreshboolean否
passwordany否

详细介绍

DocSlicer

PyPI Python versions License: AGPL v3 Commercial license available

Install in VS Code Add to Cursor Download .mcpb for Claude Desktop

闪电般快速(每秒处理 31 页)的确定性商业文档解析器和分块工具。无需调用大模型,也不依赖笨重的机器学习模型。

DocSlicer 可将 PDF、Word 文档、HTML 页面和 PowerPoint 文件转换为整洁的文本块、结构化区块、表格、图表、Markdown 和可导航的标题层级。

在 BizDocBench 上得分最高(总体得分 0.88,而次优工具为 0.70)。表格准确率为 0.80,内容忠实度为 0.98,标题识别和层级保留率为 0.85,RAG 检索表现为 0.76。

两种使用方式:

  • 作为 Python 库使用 — 传统 RAG。 感知布局的分块器会生成整洁、互不重叠的文本块,每个文本块都包含完整的标题路径,可直接用于嵌入。跳转到 API ↓
  • 作为 MCP 服务使用 — 无向量 RAG。 适用于希望立即从文档中获取答案的场景。Claude、Cursor 或 VS Code 会提取大纲,选出所需章节,并且只读取该章节——无需嵌入,也不用把 200 页文档放进上下文窗口。跳转到设置 ↓
快速开始
import docslicer

def main():
    result = docslicer.parse_document("annual_report.pdf")

    # Inspect the outline first
    result.hierarchy.to_outline()
    # - PART I — FINANCIAL INFORMATION
    #   - Item 1. Financial Statements
    #     - Notes to Condensed Consolidated Financial Statements
    #       - Note 4 – Financial Instruments
    #         - Derivative Instruments and Hedging
    #           - Foreign Exchange Rate Risk
    #           - Interest Rate Risk
    #         - Accounts Receivable
    #           - Trade Receivables
    #   - Item 2. Management's Discussion and Analysis
    #     - Liquidity and Capital Resources
    # - PART II — OTHER INFORMATION
    #   ...

    # Pull only the chunks you need
    risk_section = result.find_heading("Risk Factors")[0]
    chunks = result.chunks_under(risk_section)

    # Tables come back structured, not as flat text
    for table in result.tables_under(risk_section):
        print(table.markdown)

if __name__ == "__main__":
    main()

功能

  • 不使用 LLM、VLM 或 ML 模型 —— 完全确定性;无需下载模型权重,无需 GPU,也没有冷启动延迟
  • 轻量 —— wheel 约 630 KB,不依赖繁重的 ML 库
  • 适合 Agent —— 减少处理长文档时的 token 消耗:让 Agent 先检查大纲,再仅将相关片段拉取到上下文中,而不是原样输入一份 500 页的文档;非常适合法律文本、技术 SOP、财务申报文件和合规文档
  • 深层级提取 —— 适用于编号标题(1.、1.2.、1.2.3)和自由格式标题;依据字体大小、粗细和文档结构,而非推断;可处理附件分隔符后的重新进入,以及跨页重复的导航标题
  • 结构感知型分块 —— 在标题和段落边界处分割,保留语义连贯性
  • 字符完全不重叠 —— 默认情况下,各分块互不重叠;上下文窗口中不会出现重复 token
  • 统一结果对象 —— chunks、blocks、tables、charts、metadata 和 hierarchy 集中在一处
  • 结构化表格 —— 表格以单元格形式返回,而非纯文本;可导出为 Markdown、JSONL 或融化格式
  • 多种导出格式 —— CSV、Markdown、JSONL、Parquet、JSON、纯文本和 DataFrame
  • 保留阅读顺序 —— 包括多栏 PDF 布局
  • 支持 pdf、docx、pptx 和 html —— 包括通过 Playwright 渲染的 JS 页面
  • 稳健的 URL 获取 —— 始终在真实浏览器中渲染页面,开箱即用地处理 Cookie 横幅和机器人防护;还会保留原始 HTML 中缺失的粗体等样式信号,从而更准确地检测标题并提升分块质量
  • OCR 回退 —— 自动检测扫描页面,并在安装额外组件后回退到 Tesseract

基准测试

使用 BizDocBench 测量——这是一个用于多格式商业文档解析的开放基准。所有分数均为 0–1(越高越好);pages_per_sec_aggregate 表示整个语料库的处理吞吐量。

工具分数覆盖率速度层级结构忠实度表格检索页/秒
docslicer0.87961.00000.88360.84660.98240.80470.760131.27
docling0.70361.00000.38050.49050.89270.74670.71113.46
markitdown0.58381.00000.85130.06040.79720.25840.535727.42
unstructured0.57980.90910.10730.43270.90570.48120.64300.52
opendataloader0.53590.58441.00000.38530.64840.26550.3317117.26
pymupdf4llm0.45190.59740.64920.10890.64560.35510.355211.84
mineru0.41070.59740.13530.42200.61760.30120.39100.70
marker0.37350.59740.15980.19260.61210.30120.37780.87

安装

pip install docslicer

核心安装的依赖很少。还可通过额外组件启用可选功能:

pip install 'docslicer[html]'    # HTML / URL parsing via Playwright
playwright install chromium       # one-time browser install (Chromium only)

pip install 'docslicer[ocr]'     # scanned PDF support via Tesseract + OpenCV
# The tesserocr wheel bundles libtesseract but NOT the language models,
# so install the Tesseract engine to provide them (docslicer auto-detects the path):
# Linux:  apt install tesseract-ocr
# macOS:  brew install tesseract

pip install 'docslicer[mcp]'     # MCP server for LLM clients (Claude, Cursor, …)
pip install 'docslicer[llm]'     # exact token counts via tiktoken (exact_tokens=True)
pip install 'docslicer[crypto]'  # password-protected Office files (msoffcrypto-tool)
pip install 'docslicer[parquet]' # Parquet export support

可以组合使用额外组件:pip install 'docslicer[html,ocr,llm]'。

需要 Python 3.10+


返回内容(ParseResult)

parse_document 返回一个 ParseResult:

result.chunks      # list[Chunk]   — heading-aware text chunks, ready for embedding
result.blocks      # list[Block]   — paragraph/heading/table blocks before chunking
result.tables      # list[Table]   — structured tables with cells, spans, and markdown
result.charts      # list[Chart]   — charts as extracted data points (docx/pptx)
result.metadata    # DocumentMetadata — title, author, language, page count, OCR flag
result.hierarchy   # HierarchyTree — navigable tree of all headings

每个 Chunk 包含:

chunk.text          # str   — chunk text
chunk.path          # list  — full heading breadcrumb from root to nearest heading
chunk.heading       # str   — nearest heading above this chunk
chunk.section       # str   — body | toc | exhibit | header | footer | coverpage | …
chunk.page_number   # int   — 1-based physical page
chunk.page_label    # str   — "A-6", "iv", "F-3" — as printed on the page
chunk.table_ids     # list  — IDs of tables referenced in this chunk
chunk.chart_ids     # list  — IDs of charts referenced in this chunk (docx/pptx)
chunk.link_url      # list  — URLs found in this chunk
chunk.bbox          # BBox  — bounding box (PDF only)

每个分块都包含完整的标题层级路径,无论嵌套有多深。例如,财务申报文件中一个位于第六层的段落:

chunk.path == [
    "# PART I — FINANCIAL INFORMATION",
    "## Item 1. Financial Statements",
    "### Notes to Condensed Consolidated Financial Statements (Unaudited)",
    "#### Note 4 – Financial Instruments",
    "##### Accounts Receivable",
    "###### Trade Receivables",
]

这样,下游代码无需重新解析文档,即可根据层级中的任意层级筛选或分组分块。


支持的格式

格式扩展名说明
PDF.pdf基于文本的 PDF 和扫描件(扫描件需要 OCR extra)
Word.docx完整的样式和大纲层级结构
HTML.html、URLs静态文件和 JS 渲染页面(URL 需要 html extra)
PowerPoint.pptx幻灯片、演讲者备注、图表

不支持:.doc、.ppt(旧版 Office 格式)、.xlsx。


解析

parse_document 会根据文件扩展名或魔数自动检测格式。传入文件路径、URL、原始 bytes 或类文件对象:

result = docslicer.parse_document("contract.docx")
result = docslicer.parse_document("report.pdf")
result = docslicer.parse_document("https://www.sec.gov/Archives/edgar/data/.../10-K.htm")
result = docslicer.parse_document(file_bytes)
解析与内容选项

parse_document(以及特定格式的函数)接受用于控制解析内容和解析方式的选项,这些解析都发生在分块之前。为了统一 API,所有格式专属的开关都可在任何地方使用,但只有相关格式会应用这些开关。

result = docslicer.parse_document(
    "contract.docx",
    password="admin123",           # decrypt password-protected files; .docx and .pptx needs [crypto] extra
    max_workers=4,                 # process-pool width for PDF extraction/OCR (default: auto by CPU cores)
    include_headers_footers=True,  # docx: include header/footer content (default False)
    include_footnotes=True,        # docx: include footnotes (default True)
    include_comments=True,         # docx: include review comments (default False)
    include_speaker_notes=True,    # pptx: include slide speaker notes (default True)
    use_browser=True,              # html/URL: render in a real browser (default True)
)
分块选项
result = docslicer.parse_document(
    "report.pdf",
    max_chunk_size=2000,          # hard cap, default 3200
    optimal_chunk_size=800,       # target size, default 1500
    min_chunk_size=400,           # soft floor, default 700
    chunking=False,               # skip chunking, return blocks only (faster)
    merge_small_chunks=True,      # merge chunks below min_chunk_size (default True)
    table_representation="jsonl", # "markdown" (default) | "jsonl" | "melted"
    exact_tokens=True,            # exact tiktoken (cl100k_base) counts; needs [llm] extra, else char/4 estimate
    extra_fields=["is_bold", "font_size", "font_name"],  # surface internal pipeline columns on each chunk/block via .extra
)
merge_small_chunks 的工作方式

由于 DocSlicer 能识别文档结构,它最初会在每个标题或段落边界处生成一个分块。对于包含许多短小节的文档,这可能会产生大量小分块。启用 merge_small_chunks=True(默认值)时,同一父标题下的同级小节会合并,直到达到 min_chunk_size,但绝不会跨越标题边界,合并到不同的父标题下。

例如,以下五个短小节都位于 ## Products and Services Performance 之下:

### Mac          → "Mac net sales decreased …"            (~120 chars)
### iPad         → "iPad net sales increased …"           (~180 chars)
### Wearables    → "Wearables net sales decreased …"      (~130 chars)
### Services     → "Services net sales increased …"       (~160 chars)

它们不会生成四个很小的分块,而是会合并成一个连贯的分块,同时为每个段落保留正确的 path。如果无论大小都需要每个小节单独生成一个分块,请设置 merge_small_chunks=False。


表格表示格式

table_representation 控制表格如何序列化为分块文本。以下是一个包含多行列标题的财务表格:

"markdown"(默认值) — 保留原始二维布局:

|           | Three Months Ended    | Three Months Ended    |
|           | December 27, 2025     | December 28, 2024     |
|-----------|----------------------:|----------------------:|
| iPhone ®  |              $85,269  |              $69,138  |
| Mac ®     |               8,386   |               8,987   |
| iPad ®    |               8,595   |               8,088   |
| …         |                   …   |                   …   |

"melted" — 每个单元格占一行,标题以 > 连接。适用于稀疏表格或数据透视表,尤其是在需要检索单个单元格时:

iPhone ® | Three Months Ended > December 27, 2025 | $85,269
iPhone ® | Three Months Ended > December 28, 2024 | $69,138
Mac ® | Three Months Ended > December 27, 2025 | 8,386
Mac ® | Three Months Ended > December 28, 2024 | 8,987
iPad ® | Three Months Ended > December 27, 2025 | 8,595
iPad ® | Three Months Ended > December 28, 2024 | 8,088
…

"jsonl" — 每行对应一个 JSON 对象,多行标题以 _ 连接。当分块会输入结构化提取或工具调用工作流时,此格式很有用:

{"Metric": "iPhone ®", "Three Months Ended_December 27, 2025": "$85,269", "Three Months Ended_December 28, 2024": "$69,138"}
{"Metric": "Mac ®", "Three Months Ended_December 27, 2025": "8,386", "Three Months Ended_December 28, 2024": "8,987"}
{"Metric": "iPad ®", "Three Months Ended_December 27, 2025": "8,595", "Three Months Ended_December 28, 2024": "8,088"}
…
批量处理

将文件夹传给 parse_all(或传入路径/URL 列表)。它会生成 (source, result) 对;如果某个文件解析失败,会返回 Exception,而不会中止批处理。任何 parse_document 关键字参数(如分块大小、include_* 等)都会逐个转发给每份文档。

for path, result in docslicer.parse_all("documents/", recursive=True, max_chunk_size=2000):
    if isinstance(result, Exception):
        print(f"Failed {path}: {result}")
    else:
        print(f"{path}: {len(result.chunks)} chunks")
在多份文档间复用配置

DocumentParser 会在多份文档间使用固定的 ParseConfig,并在处理 HTML/URL 输入时复用同一个浏览器(首次解析 HTML 时才会延迟启动)。因此,批量处理 URL 时只会启动一次 Chromium,而不是每份文档启动一次。请将其用作上下文管理器,以确保浏览器始终得到释放:

from docslicer import DocumentParser, ParseConfig

config = ParseConfig(max_chunk_size=1500, optimal_chunk_size=600)

with DocumentParser(config) as parser:
    for path, result in parser.parse_all(paths):   # or parser.parse(path) for one
        ...
两级并行

有两个相互独立且可以组合使用的选项:

  • ParseConfig(max_workers=N) —— 在单个文档内部:通过多个进程并行提取 PDF 单词、构建单元格和执行 OCR(默认:自动设置,数量与 CPU 核心数相匹配)。 适合处理大型文档。
  • DocumentParser(config, workers=N) —— 在多个文档之间:将完整文档分发给 N 个工作进程,每个进程都有自己的配置和浏览器。适合处理大量文档。结果按提交顺序返回(此路径不会按文档惰性处理)。

仅设置 workers 时,每个工作进程的 max_workers 默认值为 1,以免嵌套进程池造成机器超额调度;如果要同时启用两个层级,请显式设置这两个参数。workers 路径无法跨进程传递浏览器会话或 on_stage 回调——需要这些功能时,请不要设置 workers。

保护好入口点。 只要有实际的 CPU 工作需要分发,DocSlicer 就会使用 ProcessPoolExecutor——任何超过约 50 页的 PDF、任何长度的扫描版/OCR PDF,以及上述两个并行选项。这并非可选功能:普通的 docslicer.parse_document("big.pdf") 调用也会触发它。在 macOS 和 Windows 上,Python 会通过从头到尾重新导入脚本来启动工作进程,因此在模块级别运行解析时,每个工作进程都会重新运行解析并再次启动进程——从而引发 RuntimeError: An attempt has been made to start a new process before the current process ... bootstrapping phase。请将解析代码放在函数中,并用 if __name__ == "__main__": 保护:

def main():
    with DocumentParser(config, workers=4) as parser:
        for path, result in parser.parse_all(paths):
            ...

if __name__ == "__main__":
    main()

浏览层级结构

大多数分块库会提供一个扁平的文本片段列表。DocSlicer 还会提供可导航的文档标题结构树,该结构从文档本身以确定性方式提取。

这对处理长文档的 Agent 和检索流水线尤其有用:无需将整份文档放入上下文,Agent 可以先查看大纲以了解结构,判断哪些章节相关,然后仅提取相应分块——使令牌用量与任务规模相匹配。

查看大纲
# Print the full heading tree
result.hierarchy.to_outline()

# Walk all top-level sections and see how much content each contains
for node in result.hierarchy.level(1):
    print(node.text, "→", len(result.chunks_under(node)), "chunks")
深入某个章节

.level(n) 会返回深度为 n 的所有标题。传入 parent 可将范围限定为特定子树——这是 Agent 浏览长文档时的常见模式:

# All top-level headings
l1 = result.hierarchy.level(1)

# Pick one, then list its subsections
section = result.find_heading("Financial Statements")[0]
for node in result.hierarchy.level(2, parent=section):
    print(node.text, f"(p.{node.page_number})")

# Drill one level deeper
subsection = result.hierarchy.level(2, parent=section)[0]
for node in result.hierarchy.level(3, parent=subsection):
    print(node.text)
获取标题下的内容

find_heading 会匹配文本包含搜索词的任意节点(不区分大小写)。 默认情况下,所有检索方法都会递归进入子章节。

node = result.find_heading("Financial Instruments")[0]

chunks = result.chunks_under(node)              # text chunks, ready for embedding or prompting
chunks = result.chunks_under(node, recursive=False)  # direct heading only, no subsections
tables = result.tables_under(node)              # structured tables in this section
charts = result.charts_under(node)              # charts (with extracted data points) in this section
blocks = result.blocks_under(node)              # raw paragraph/heading blocks
按页导航
result.chunks_by_page(14)        # by page number
result.chunks_by_page("F-3")     # by printed page label
result.blocks_by_page(14)
result.tables_by_page(14)
result.charts_by_page(14)
解析一次,多次导航

解析结果是普通数据,因此可以保存并在之后重新加载。当 Agent 针对同一文档提出多个问题时,无需每次提问都重新解析:

from pathlib import Path
import docslicer

cache = Path("annual_report.json")

if cache.exists():
    result = docslicer.ParseResult.load(cache)
else:
    result = docslicer.parse_document("annual_report.pdf")
    result.save(cache)

重新加载的结果支持完整 API——hierarchy、find_heading、 chunks_under、tables——因此,长期运行的 Agent 会话或文档服务可以在多个请求之间保持文档打开状态,无需重新解析。


导出

save() 会根据你提供的路径决定写入什么内容。

# Save the whole result and reload it later — keeps the heading hierarchy
result.save("result.json")                     # same output as result.to_json()
result = docslicer.ParseResult.load("result.json")

# A single collection, in the format you name
result.save("chunks.csv")
result.save("charts.jsonl")       # stems: chunks | blocks | tables | charts | metadata
result.export_chunks_jsonl("chunks.jsonl")

# One file per collection
result.save("output/")
# → output/chunks.parquet, blocks.parquet, tables.parquet, metadata.json
#   (+ charts.parquet when the document has charts)
#   Falls back to .csv unless the [parquet] extra is installed.

# Render as Markdown or plain text
md = result.export_to_markdown(include_tables=True)
txt = result.export_to_text()

# DataFrames
df = result.chunks_df()

只有 result.json 支持往返读写——集合和目录格式会写入不含标题层级结构的扁平行,因此 ParseResult.load() 无法重新读取它们。

调试模式
result = docslicer.parse_document("report.pdf", debug=True)

# result.pipeline_steps is an ordered dict of step name → DataFrame
for name, df in result.pipeline_steps.items():
    print(name, df.shape)
    df.to_csv(f"debug/{name}.csv", index=False)

# PDF steps:        words → shapes → cells → lines → table_cells → blocks → chunks
# DOCX/PPTX steps:  runs → chart_points → paragraphs → lines → table_cells → blocks → chunks

OCR

如果已安装 [ocr] 扩展,parse_document 会自动检测扫描页面,并在需要时回退到 OCR。无需配置——result.metadata.has_ocr 会告知你是否使用了 OCR。

pip install 'docslicer[ocr]'
# tesserocr binds libtesseract directly, so install the Tesseract dev libraries first:
# Linux:  apt install tesseract-ocr libtesseract-dev libleptonica-dev pkg-config
# macOS:  brew install tesseract leptonica

MCP 服务

DocSlicer 附带一个 MCP 服务,因此大模型客户端(Claude Desktop、Claude Code、Cursor、……)可以直接解析和读取文档。

pip install 'docslicer[mcp]'
docslicer-mcp                    # stdio — what desktop clients launch
docslicer-mcp --transport http --port 8000
Claude Desktop / Cowork — 一键安装

从最新版本下载 docslicer-X.Y.Z.mcpb,然后双击它,或将其拖到 Claude Desktop 窗口中。安装期间,你可以选择允许 DocSlicer 读取和写入的文件夹;无需配置文件,也无需自行安装 Python——uv 会配置解释器。

其他客户端

以下客户端都会通过 stdio 启动服务。uvx 无需预先安装任何内容:

{
  "mcpServers": {
    "docslicer": {
      "command": "uvx",
      "args": ["--from", "docslicer[mcp]", "docslicer-mcp"],
      "env": { "DOCSLICER_MCP_ROOT": "/Users/you/Documents" }
    }
  }
}

如果你更愿意一次性安装,以免每次启动时解析依赖,请使用 pip install 'docslicer[mcp]'(或 uv tool install),并设置 "command": "docslicer-mcp",不带 args。

客户端配置文件位置
Claude Codeclaude mcp add docslicer -- uvx --from 'docslicer[mcp]' docslicer-mcp
Cursor~/.cursor/mcp.json,或每个项目中的 .cursor/mcp.json
VS Code.vscode/mcp.json(使用 servers 键,而不是 mcpServers)
Windsurf~/.codeium/windsurf/mcp_config.json
Zedsettings.json 中的 context_servers

对于通过 GUI 启动的客户端,建议使用 .mcpb。 从程序坞启动的应用不会继承 shell 的 PATH——在 macOS 上,/opt/homebrew/bin 不在其中——因此,单独使用 uvx 或 docslicer-mcp 时,可能在终端中正常运行,却在客户端启动它时失败。如果遇到这种情况,请使用绝对路径(which uvx)。使用扩展即可完全避开这个问题。

工作原理

解析后的文档远超模型的上下文窗口大小,因此服务绝不会在一次调用中返回整份文档。parse 会注册文档,并返回一个 doc_id 句柄和标题大纲。其他所有工具都接收该句柄,并返回有大小限制的片段——模型只会载入所需内容。

工具返回内容
parsedoc_id 句柄、标题、页数、标题大纲
get_outline再次返回大纲,以便在大纲超出上下文时查看
read一个或多个大纲中列出的标题下的文本
search可供 read 的标题,按相关性排序,每项附带一个片段
to_markdown将整份文档写入磁盘;返回路径

大纲中的每一行都会显示阅读该部分的预计开销:

- Financial statements  ~48k
  - Note 14 — Segment reporting  ~900
  - Note 15 — Income taxes  ~2.1k

该数值与 read 返回的估算值相同,因此根据大纲制定的预算在实际使用时也能成立。大小是累积计算的——父级的开销绝不会小于其下子级的开销——这样模型就可以在消耗上下文之前决定“继续深入还是直接读取”,而不是之后才作决定。

read 接受的标题文本必须与大纲显示的完全一致。如果某个标题重复出现,可在其前面加上任意一个祖先标题来区分("Notes > Revenue");无需提供完整的层级链。返回的文本中会穿插 [Page X] 标记,使用文档自身的页码标签(S-23、iv),这样引用时就能标注内容实际所在的页,而不是该章节开始的页。

如果大纲无法解决问题,search 可作为备用工具——例如标题没有提供有用信息(Note 14、Item 7A),或某个数据被埋在标题未提及的表格中。它会结合全词匹配和对各文本块进行的 BM25 检索,返回的是位置,而不是答案:每条命中都是一个需要传给 read 的标题。系统还会返回文档中完全没有出现的查询词,这样就能识别出因某个罕见词而得分很高的查询实际上并不合适。

当用户需要的是文档本身,而不是从文档中提取的答案时,可以使用 to_markdown 作为备用方案。它会将文档写入磁盘并返回路径,因此内容不会进入模型的上下文,文档大小也就不再是问题。

解析结果会缓存到磁盘,因此使用相同选项重新解析同一文件无需额外开销。缓存键包含文件大小和 mtime——编辑文档后,下次调用 parse 时会自动重新解析。

配置
变量作用
DOCSLICER_MCP_ROOT将文件来源和写入的输出限制在此目录树中。可指定多个目录,以 : 分隔(Windows 上使用 ;)
DOCSLICER_MCP_ALLOW_CLAUDE_DIR设置为 0,将 Claude 桌面应用自身的目录从允许的根目录中移除(默认值为 1)
DOCSLICER_MCP_ALLOW_URLS设置为 0,拒绝 http(s) 来源
DOCSLICER_MCP_CACHE解析结果的持久化位置(默认值:~/.cache/docslicer-mcp)
DOCSLICER_MCP_CACHE_MAX_MB缓存大小上限,优先清理最旧的内容(默认值:2048;0 表示禁用)

向他人开放服务时,请设置 DOCSLICER_MCP_ROOT——否则,机器上任何可读取的路径都可以被解析,而 to_markdown 可以写入服务进程有权访问的任何位置。

拖入聊天的文档。 将文件附加到 Claude 对话中,并不会将你所知道的文件路径交给服务:应用会先将其复制到自身数据目录下的每个会话工作区中(macOS 上为 ~/Library/Application Support/Claude,Windows 上为 %APPDATA%\Claude),而该位置通常与你原本会选择作为根目录的文件夹相距甚远。因此,除 DOCSLICER_MCP_ROOT 外,还会允许该目录,这样两种方式都能使用——你选择的文件夹,以及拖入聊天的文件。只有在你设置了根目录时,该目录才会被添加进去;如果不设置 DOCSLICER_MCP_ROOT,就意味着完全没有沙盒,而不是仅对该目录设置沙盒。设置 DOCSLICER_MCP_ALLOW_CLAUDE_DIR=0 可选择退出,并仅接受你自己的根目录。

to_markdown 会将输出写入源文档所在目录旁边;但对于拖入聊天的文档,其副本位于你无法浏览到的会话文件夹中,因此 Markdown 文件会写入第一个 DOCSLICER_MCP_ROOT。


命令行

docslicer 将单个文档解析为 JSON 并输出到 stdout——可用于快速查看文件,或将结果传递给 jq。

docslicer report.pdf                   # chunks as JSON
docslicer report.pdf -o chunks.json    # write to a file
docslicer report.pdf --no-chunking     # blocks instead of chunks

它接受与 parse_document 相同的解析和分块选项;运行 docslicer --help 查看完整列表。


特定格式函数

如果你预先知道文件格式,并希望在输入不符合预期时明确报错,请使用特定格式的变体。它们接受与 parse_document 相同的参数:

docslicer.parse_pdf("report.pdf")
docslicer.parse_docx("contract.docx")
docslicer.parse_pptx("deck.pptx")
docslicer.parse_html("filing.html")

隐私政策

完整政策:https://docslicer.ai/privacy

收集哪些信息。 不收集任何信息。DocSlicer 不包含遥测、分析、崩溃报告或使用情况跟踪,也不需要账户、许可证密钥或注册。

如何使用您的文档。 解析完全在您自己的设备上以本地进程运行。文档内容仅用于生成您请求的大纲、文本片段、搜索结果和 Markdown,并且仅返回给调用方。文档绝不会上传到 DocSlicer 或任何第三方。作为 MCP 服务运行时,DOCSLICER_MCP_ROOT 会限制可读取和写入的目录树。

数据存储位置及保留时长。 解析结果会缓存在您自己的磁盘上——默认位置为 ~/.cache/docslicer-mcp,可通过 DOCSLICER_MCP_CACHE 配置。缓存会被清理至大小上限(DOCSLICER_MCP_CACHE_MAX_MB,默认 2048 MB);否则会一直保留,直到您将其删除。删除该目录即可永久移除缓存,不会在其他位置保留副本。除缓存目录和您指定的任何输出路径外,不会写入任何内容。

网络访问和第三方。 对本地文件不会发起网络请求。只有当您传入 http(s) 源时,请求才会离开您的设备:该 URL 会直接从您指定的主机获取;对于 HTML 页面,Playwright 可能会加载该页面引用的子资源,行为与浏览器完全相同。向 sec.gov 发出的请求会发送用于标识客户端的 User-Agent 标头,这是 SEC 公平访问政策的要求。这些主机是由您而非 DocSlicer 选择的第三方,它们各自的政策决定会记录哪些信息。设置 DOCSLICER_MCP_ALLOW_URLS=0 可完全拒绝远程源。

第三方客户端。 DocSlicer 作为 MCP 服务运行时,客户端(Claude、Cursor、……)会根据其自身的隐私政策处理对话。DocSlicer 不参与其中,也不会收到任何对话内容。

联系。 隐私问题:[email protected] · 问题反馈: https://github.com/DocSlicer/DocSlicer/issues


许可证

DocSlicer 采用双重许可:

  • AGPL-3.0 — 可免费使用、修改和分发,但须遵守 AGPL 条款,包括向使用 DocSlicer 的任何应用的用户提供该应用的完整源代码(包括通过网络提供)。
  • 商业许可证 — 适用于将 DocSlicer 嵌入闭源或专有产品,或将其作为托管服务/SaaS 服务的一部分提供且不公开源代码的情况。

详情请参阅 LICENSE-COMMERCIAL.md,或联系我们洽谈商业许可证。


mcp-name: io.github.DocSlicer/docslicer

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。