Markdown书籍工具

一个支持DI/SOA架构和MCP服务器集成的Markdown书籍阅读与编写工具,适用于技术文档管理和AI助手集成。

  • by bobmatnyc
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 bobmatnyc/md-book

使用说明

MD图书工具

一个具有DI/SOA架构和MCP服务器支持Claude Code集成的markdown阅读器和作家。

特性

  • 多格式支持:mdBook、GitBook、Leanpub、Bookdown和自动检测
  • YAML前端编辑器:提取元数据(标题、作者、日期、草稿状态)
  • 交互式阅读器:带章节跳转的终端导航
  • 书籍写作:初始化项目、添加章节、生成TOC
  • MCP 服务器:将图书操作作为人工智能助手的工具

建筑

mdbook/
├── domain/           # Core entities (Book, Chapter, ChapterMetadata)
├── services/         # Business logic with interface protocols
│   ├── interfaces.py # IBookService, IReaderService, IWriterService, IStructureService
│   ├── book_service.py
│   ├── reader_service.py
│   ├── writer_service.py
│   └── structure_service.py
├── repositories/     # Data access layer
│   ├── interfaces.py # IFileRepository, IConfigRepository
│   ├── file_repository.py
│   └── config_repository.py
├── infrastructure/   # DI container and composition root
│   └── container.py  # ServiceContainer with lazy singleton resolution
├── mcp/              # Model Context Protocol server
│   └── server.py     # Exposes book operations as MCP tools
└── cli.py            # Unified Click-based CLI

安装

使用紫外线(推荐)

cd book-reader
uv pip install -e .

使用pip

cd book-reader
pip install -e .

这将安装单 mdbook 命令及其所有子命令。

快速开始

# Read a book (pass book path as argument)
mdbook read /path/to/book

# Or use --book/-b global option
mdbook --book /path/to/book read

# Show book info
mdbook info /path/to/book

# Create a new book
mdbook init ./my-book -t "My Book Title" -a "Author Name"

# Add a chapter
mdbook new-chapter ./my-book -t "Introduction"

# Regenerate table of contents
mdbook toc ./my-book

# Start MCP server for a specific book
mdbook serve-mcp /path/to/book

# Auto-configure Claude Code MCP integration
mdbook setup /path/to/book

命令参考

mdbook [OPTIONS] COMMAND [ARGS]

Commands:
  read         Read a markdown book interactively
  info         Show book information
  init         Initialize a new book project
  new-chapter  Add a new chapter to a book
  toc          Regenerate table of contents
  serve-mcp    Start MCP server for Claude Code
  setup        Auto-configure Claude Code MCP integration

Global Options:
  -b, --book PATH  Book directory (used by all commands)
  --version        Show version and exit
  --help           Show help message and exit

读

mdbook read [BOOK] [OPTIONS]

Arguments:
  BOOK         Book directory (or use global --book option)

Options:
  -c, --chapter NUM    Start at specific chapter

初始化

mdbook init PATH [OPTIONS]

Arguments:
  PATH         Directory to create book in

Options:
  -t, --title TEXT     Book title (required)
  -a, --author TEXT    Author name (required)

新篇章

mdbook new-chapter [BOOK] [OPTIONS]

Arguments:
  BOOK         Book directory (or use global --book option)

Options:
  -t, --title TEXT     Chapter title (required)
  -d, --draft          Mark as draft

设置

mdbook setup [BOOK]

Arguments:
  BOOK         Book directory (or use global --book option)

Auto-configures Claude Code MCP integration by updating .mcp.json
in the project directory. Creates the file if it doesn't exist or
adds/updates the mdbook server configuration.

MCP服务器集成

MCP服务器将图书操作作为Claude Code和其他人工智能助手的工具公开。

可用的MCP工具

工具 说明
book_info 获取图书元数据和章节列表
read_chapter 按编号阅读章节内容
list_chapters 列出所有包含元数据的章节
create_book 创建新书项目
add_chapter 在书中添加一章
update_toc 重新生成摘要.md

Claude代码配置

添加到您的 .mcp.json:

{
  "mcpServers": {
    "mdbook": {
      "command": "mdbook",
      "args": ["serve-mcp"]
    }
  }
}

或者使用紫外线:

{
  "mcpServers": {
    "mdbook": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/book-reader", "mdbook", "serve-mcp"]
    }
  }
}

支持的书籍格式

格式 检测文件
mdBook/GitBook SUMMARY.md
mdbook 的 book.toml
Leanpub Book.txt
预订 _bookdown.yml
自动 目录扫描

需求

  • Python 3.10+
  • 点击、丰富、降价、pyyaml、mcp

许可证

MIT许可证

版本历史记录

  • v1.0.0 -DI/SOA架构的首次公开发布,统一 mdbook CLI、MCP服务器集成、带book参数的多书支持和 --book/-b 全局选项, setup 用于Claude Code MCP自动配置、多格式支持(mdBook、GitBook、Leanpub、Bookdown)和YAML frontmatter解析的命令