md-chunk-lite

io.github.tidybytetools由 GitHub 帳號 tidybytetools 發布v1.0.0更新於 Nov 5, 2026

Split Markdown into chunks by heading. Each chunk keeps its heading path and line numbers.

已驗證STDIO僅桌面檔案與儲存知識與記憶

概覽

AI 產生的概覽

依標題把 Markdown 檔案或文字切成區塊,每個區塊保留標題路徑與行號,方便用於 RAG、向量化與搜尋索引。

可以做什麼
  • 依標題把 Markdown 檔案或文字切成區塊,每個區塊帶有標題路徑、錨點與行號
  • 列出文件中的所有標題,包含層級、路徑、錨點、行號與大小
  • 依標題名稱或錨點回傳單一章節的內容
  • 把 Markdown 檔案的切分結果存成 JSONL 檔,每行一個區塊
適用情境
適合在為 AI 搜尋、向量化或向量資料庫準備 Markdown 文件、筆記或 README 時使用,也適合讓助理只讀長文件中的某一節而不必讀完整份。它不使用 AI,結果固定,同一個檔案每次切分都相同。
執行需求
以本機 stdio 程序執行,透過 uvx 啟動(需先安裝 uv);套件發佈於 PyPI,需要 Python 3.10 以上版本。不需要帳號、API 金鑰或網路連線。
安裝前請注意
save_chunks_jsonl 會寫出一個 .jsonl 檔,若檔案已存在會被覆寫,請指定可被覆寫的路徑。區塊大小以字元而非 token 計算,且只讀取 Markdown 與純文字,不讀取 PDF、Word 或 HTML。README 提到其他格式需改用另一個付費產品。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 md-chunk-lite,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

[Tidy Byte Tools]

md-chunk-lite

[License: MIT] [Python 3.10+] [MCP server] [Tests] [Action test]

Free tool that splits Markdown into chunks by heading. Every chunk knows its heading path and the line numbers it came from. Need PDF, Word or web page files turned into chunks (with page numbers for PDFs), or whole folders? The paid doc2md does that: doc2md on Gumroad

Good for AI search (RAG), embeddings, and docs bots. Plain code, not AI, so the same file always gives the same chunks. Runs on your own computer. MIT license. Python 3.10 or newer, on Windows, Mac and Linux.

Install

pip install md-chunk-lite

Or use pipx, which keeps it in its own space:

pipx install md-chunk-lite

Want the newest code from GitHub instead?

pip install git+https://github.com/tidybytetools/md-chunk-lite

Use it

md-chunk-lite guide.md                     # writes guide.chunks.jsonlmd-chunk-lite docs/*.md -o all.jsonl       # many files into one filemd-chunk-lite guide.md -o -                # print the chunks on screenmd-chunk-lite guide.md --max-chars 800     # smaller chunksmd-chunk-lite guide.md --outline           # just show the headingscat guide.md | md-chunk-lite -             # read from stdin

Example run:

Saved: guide.chunks.jsonl  (7 chunks, biggest 151 chars)

Each line of the .jsonl file is one chunk:

json
{  "id": "guide.md#3",  "source": "guide.md",  "index": 3,  "heading_path": ["Garden Guide", "Planting", "Tomatoes"],  "heading_level": 3,  "anchor": "tomatoes",  "start_line": 16,  "end_line": 24,  "part": 1,  "parts": 1,  "chars": 151,  "text": "### Tomatoes\n\nPlant tomatoes after the last frost. Give them sun.\n\n```python\n..."}
  • heading_path: all the headings above this chunk, from the top.
  • anchor: the #link GitHub makes for that heading, so you can link straight to it.
  • start_line and end_line: where the chunk is in the file (the first line is 1).
  • part and parts: a big section is split into parts. part 2, parts 3 means the 2nd of 3.
  • chars: how long text is.

--outline prints the headings:

Garden Guide  [line 8, #garden-guide, 14 chars]  Tools  [line 10, #tools, 47 chars]  Planting  [line 14, #planting, 11 chars]    Tomatoes  [line 16, #tomatoes, 151 chars]

When you run it in a terminal it ends with one short line about the paid doc2md. --quiet turns it off, and it never shows when output is piped or redirected.

How it splits

  1. Each heading starts a new section. A chunk never mixes two sections, so every chunk has one clear heading path.
  2. A small section becomes one chunk. Its text is copied straight from your file, so the line numbers match.
  3. A big section is split at blank lines. Lists, tables and code blocks stay whole when they fit.
  4. A table that is too big is split by rows, and each part gets the header row again.
  5. A code block that is too big is split by lines, and each part gets its own ``` fence again, with the same language.
  6. A very long line is cut at the end of a sentence, then at a space if it has to be.
  7. A heading with no text of its own (just more headings under it) does not get its own chunk, but it still shows in the heading_path of the chunks under it.

It knows # headings and underlined headings (=== and ---). It skips headings inside code blocks and YAML front matter (the --- block at the very top).

Options:

  • --max-chars N: biggest chunk, in characters (default 1500, smallest 200). About 4 characters make 1 token in English.
  • --overlap-chars N: when a section is split, start each part with up to N characters from the end of the part before it (default 0). It is never added inside a code block or table, and never between two different sections.
  • --prefix-path: start each chunk's text with its heading path, like Garden Guide > Planting > Tomatoes. This often helps search. It counts toward --max-chars.
  • --json: print one JSON object for scripts and AI agents instead of saving a file.

Known limits

  • Sizes are characters, not tokens. It does not load a tokenizer.
  • Markdown and plain text only. PDF, Word and HTML are not read. The paid doc2md turns those into chunks (with page numbers for PDFs).
  • No folders. Give it files (your shell can expand docs/*.md). The paid doc2md walks whole folders.
  • Not a full Markdown parser. A heading inside an HTML block, or an underlined heading that spans more than one line, may be handled wrong.
  • Overlap uses whole words from the part before, so it can be a little shorter than you asked for.

Lite vs paid

md-chunk-lite (free)doc2md (paid)
ReadsMarkdown and text filesPDF, Word (.docx) and HTML
Chunks with the heading pathyesyes
Line numbers and anchorsyesno (page numbers for PDFs instead)
Rough token count on each chunknoyes
Whole folders, sub-folders toonoyes
MCP serveryesno

Other good free tools

Pick what fits you. If you already use LangChain, its MarkdownHeaderTextSplitter also splits by heading. Chonkie and semchunk split any text by token count. md-chunk-lite is small, MIT, has no AI or tokenizer parts, gives you line numbers and anchors, and has an MCP server built in.

Use it from Claude Desktop or Cursor (MCP)

There is a small free MCP server built in. It needs uv.

Run it by hand to check it starts (it waits quietly for an app to talk to it):

uvx md-chunk-lite mcp

Claude Desktop (claude_desktop_config.json) or Cursor (~/.cursor/mcp.json):

json
{  "mcpServers": {    "md-chunk-lite": {      "command": "uvx",      "args": ["md-chunk-lite", "mcp"]    }  }}

uvx --from md-chunk-lite md-chunk-lite-mcp starts the same server.

Tools (each one takes a file path or Markdown text):

ToolWhat it doesChanges files?
chunk_markdownSplits into chunks. Returns 100 at a time; use start for more.No
outline_markdownLists the headings with line numbers and anchors.No
get_sectionGets one section by heading or anchor.No
save_chunks_jsonlSaves the chunks to a .jsonl file.Writes one .jsonl file (replaces it if it is there)

None of them use the internet.

Use it in GitHub Actions

Chunk your docs on every push, so your AI search or docs bot always gets fresh chunks. It also warns you when a section is too big for one chunk, right on the line in the pull request.

yaml
name: Docs chunkson: [push, pull_request]permissions:  contents: readjobs:  chunks:    runs-on: ubuntu-latest    steps:      - uses: actions/checkout@v7      - uses: tidybytetools/md-chunk-lite@v1        with:          files: docs/**/*.md          max-chars: "1500"          artifact-name: docs-chunks   # download the JSONL from the run page

Want a big section to fail the check instead of just warn? Add fail-on-split: "true".

It runs the code in the same tag you pick, with only Python's standard library. No API key, no account, and nothing is sent outside GitHub. It works on Linux, Windows and Mac runners.

Inputs

InputDefaultWhat it does
files**/*.mdWhich files to read. Glob patterns, one per line or split by commas.
excludenode_modules/**, **/node_modules/**, vendor/**Patterns to skip.
max-chars1500Biggest chunk, in characters (200 or more).
overlap-chars0Characters from the part before to repeat at the start of the next part.
prefix-pathfalseStart each chunk's text with its heading path.
outputmd-chunks.jsonlWhere to save the chunks.
fail-on-splitfalseFail when a section is too big for one chunk.
fail-if-no-filestrueFail when no files match.
artifact-name(empty)If set, upload the JSONL as an artifact with this name.
python-version(empty)Python to set up. Empty uses the runner's Python (3.10 or newer).

Outputs

OutputWhat it is
filesHow many files were read.
chunksHow many chunks were made.
biggestSize of the biggest chunk, in characters.
split-sectionsHow many sections were too big and got split.
outputPath of the JSONL file.

The run page also gets a short report: chunks per file, and a list of every section that got split, with its line number.

For AI agents

  • Use when: you have a Markdown or text file (docs, notes, a README) and need chunks with heading paths and line numbers for search, embeddings or citing sources. Use outline_markdown and get_section to read just one part of a long file.
  • Don't use when: the file is PDF, Word or HTML (convert it first), or you need token-exact sizes.
  • Input: a file path or Markdown text, plus max_chars (default 1500), overlap_chars (default 0) and prefix_path (default false).
  • Output: chunks with id, source, index, heading_path, heading_level, anchor, start_line, end_line, part, parts, chars, text.
  • CLI exit code is 0 on success and 1 on error (message on stderr, or {"ok": false, "error": ...} with --json). See also llms.txt.

Python

python
from md_chunk_lite import chunk_file, chunk_markdown, outline, get_section
chunks = chunk_file("guide.md", max_chars=1000)for c in chunks:    print(c["heading_path"], c["start_line"], c["end_line"])
install = get_section(open("README.md").read(), heading="Install")

The chunker file uses only Python's standard library. Installing with pip also adds the mcp package for the MCP server.

Tests

pip install "mcp>=1.10,<2"python3 -m unittest discover -s tests

The MCP tests are skipped if mcp is not installed.

License

MIT. See LICENSE.

來源:README.md,提交 908b1b6

工具

4

chunk_markdown

Split Markdown into chunks

Split a Markdown file or Markdown text into chunks by heading, for search, embeddings or RAG. Use this when you need a long Markdown document (docs, notes, a README) broken into pieces that each know where they came from. A chunk never mixes two sections. Each chunk has heading_path (like ["Guide", "Install"]), anchor (the GitHub-style #link), start_line and end_line (1-based, in the file), part and parts (when a big section had to be split), chars and text. Code blocks and tables are kept whole when they fit; when they don't, each piece gets the fence or table header again. Plain code, not AI: same input, same chunks. Do not use it for PDF or Word files (convert them to Markdown first), to just see the headings (use outline_markdown), or to read one section (use get_section). Sizes are characters, not tokens. Returns {"source", "total", "start", "chunks": [...], "next_start"}. next_start is null when there are no more chunks.

輸入參數pathtextlimitstartmax_charsprefix_pathoverlap_chars

outline_markdown

List Markdown headings

List every heading in a Markdown file or text, with its level, path, anchor, line number and size. Use this when you want a quick map of a long document before you read or chunk it, or to find the exact heading or anchor to pass to get_section. Headings inside code blocks and YAML front matter are ignored. Both "# Title" and underlined (=== / ---) headings are found. Do not use it to get the text itself (use get_section or chunk_markdown). Returns {"source", "count", "headings": [{"level", "title", "path", "anchor", "line", "end_line", "chars"}]}. chars is the size of that heading's own text, not counting the sections under it.

輸入參數pathtext

get_section

Get one Markdown section

Return the text of one section of a Markdown file or text, found by heading title or anchor. Use this when you only need one part of a long document, like the "Install" section of a README, so you don't have to read the whole file. If two headings have the same title, the first one is returned and "matches" tells you how many there are; use the anchor (from outline_markdown) to pick another. Do not use it to split the whole document (use chunk_markdown). Returns {"title", "heading_path", "level", "anchor", "start_line", "end_line", "chars", "matches", "text"}. If nothing matches, the error lists the headings.

輸入參數pathtextanchorheadinginclude_subsections

save_chunks_jsonl

Save chunks to a JSONL file

Split a Markdown file into chunks and save them as a JSONL file (one chunk per line). Use this when the chunks are going into a search index, vector database or another program, and you want a file instead of a long chat reply. The chunks are the same as chunk_markdown gives. It writes only the one .jsonl file and replaces it if it is already there. It never changes the Markdown file. Do not use it to look at chunks in the chat (use chunk_markdown). Returns {"output_path", "chunks", "bytes", "biggest_chunk_chars"}.

輸入參數path必填max_charsoutput_pathprefix_pathoverlap_chars

版本歷史

1
  1. v1.0.0最新Nov 4, 2026

評分

已滿足適用檢查項的 90%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分
  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分