md-mcp

md-mcp

An MCP server that provides surgical read/write access to individual sections of Markdown files, allowing agents to fetch, edit, or delete specific slices without touching the entire file.

Category
访问服务器

README

md-mcp

An MCP server that gives agents surgical read/write access to individual sections of Markdown files.

Overview

Large Markdown files — documentation, changelogs, wikis — are expensive for agents to work with: reading the entire file just to update one section wastes tokens, and rewriting the whole file risks accidental data loss. md-mcp solves this by exposing each section as an individually addressable unit, so an agent can fetch, edit, or delete exactly the slice it needs without touching anything else.

The server runs over stdio as a local MCP server. Files are addressed by path on disk; sections within a file are addressed by a dot-separated heading path (e.g. "User Guide.Installation.Prerequisites"). Parsed ASTs are cached in memory and invalidated automatically on mtime change, so repeated reads of an unchanged file are fast.

Installation

The package is not yet published to PyPI. Install it in editable mode directly from the repository.

pip

pip install -e .

uv

uv pip install -e .

Connecting to opencode / Claude Desktop

After installation the md-mcp entry-point script is on your PATH. Add it as a local stdio MCP server in your client config.

opencode (opencode.json / opencode.jsonc)

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "md-mcp": {
      "type": "local",
      "command": ["md-mcp", "--allow-root", "/your/docs/dir"]
    }
  }
}

Claude Desktop (claude_desktop_config.json)

Claude Desktop uses the top-level key mcpServers:

{
  "mcpServers": {
    "md-mcp": {
      "command": "md-mcp",
      "args": [],
      "transport": "stdio"
    }
  }
}

Dot-path addressing

Every tool that targets a section takes a path argument — a dot-separated string of heading texts from the document root down to the target section. Given this Markdown file:

# My Project

## Installation

### Prerequisites

## Usage

The available paths are:

Section Path
# My Project My Project
## Installation My Project.Installation
### Prerequisites My Project.Installation.Prerequisites
## Usage My Project.Usage

Matching is case-insensitive, so my project.installation and My Project.Installation resolve to the same section. Ambiguous paths (duplicate heading texts at the same level) resolve to the first match.

Tool reference

Tool Arguments Returns Description
get_index file_path: str dict Returns the full section tree of a file as a nested dict with heading, level, path, and children fields.
get_section file_path: str, path: str, depth: int | None = None str Returns the raw Markdown text of the named section. depth=None (default): full subtree; depth=0: heading + own body only; depth=N: heading + N levels of children.
search_sections file_path: str, query: str, case_sensitive: bool = False list Searches all section bodies for lines matching query (Python regex). Returns a list of {"path", "matches": [{"line", "text"}]} objects in file order. Each section's own body is searched independently — results are never duplicated across parent and child. Heading text is not searched — use get_index to find terms in headings.
add_section file_path: str, heading: str, content: str, under: str | None = None, before: str | None = None, after: str | None = None str Inserts a new section. heading must start with ####### followed by a space. Placement: under (last child), before (immediately before), after (immediately after including its children), or omit all to append. Returns "ok".
replace_section file_path: str, path: str, new_content: str str Replaces the body of the named section, preserving its heading line. Returns "ok".
patch_section file_path: str, path: str, new_content: str str Returns a unified diff of what replace_section would write, without modifying the file. Returns an empty string if there are no changes.
delete_section file_path: str, path: str, include_children: bool = True str Deletes the named section. With include_children=True (default) removes the heading, its body, and all child sections; with False removes only the heading and its direct body, promoting children. Returns "ok".

Examples

A short worked session against a file docs/guide.md whose top-level heading is User Guide:

1. Inspect the structure

get_index("docs/guide.md")

Returns a nested tree:

{
  "sections": [
    {
      "heading": "User Guide",
      "level": 1,
      "path": "User Guide",
      "children": [
        {
          "heading": "Getting Started",
          "level": 2,
          "path": "User Guide.Getting Started",
          "children": []
        },
        {
          "heading": "Configuration",
          "level": 2,
          "path": "User Guide.Configuration",
          "children": []
        }
      ]
    }
  ]
}

2. Read a section

get_section("docs/guide.md", "User Guide.Getting Started")

Returns the raw Markdown text of that section (heading line + body).

3. Preview a change

patch_section("docs/guide.md", "User Guide.Configuration", "Set `debug: true` in `config.yaml`.")

Returns a unified diff showing exactly what would change — nothing is written yet.

4. Apply the change

replace_section("docs/guide.md", "User Guide.Configuration", "Set `debug: true` in `config.yaml`.")

Returns "ok". The file is updated; the heading line is preserved unchanged.

5. Add a new section

add_section("docs/guide.md", "## Troubleshooting", "See the FAQ.", after="User Guide.Configuration")

Returns "ok". The new ## Troubleshooting section is inserted immediately after ## Configuration.

6. Find sections mentioning a term

search_sections("docs/guide.md", "debug")

Returns:

[
  {
    "path": "User Guide.Configuration",
    "matches": [
      {"line": 18, "text": "Set `debug: true` in `config.yaml`."}
    ]
  }
]

Development

Requirements: Python 3.11+

Install the package with dev dependencies:

pip install -e ".[dev]"

Run the test suite:

pytest

Set up and run pre-commit hooks (ruff + mypy):

pre-commit install
pre-commit run --all-files

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选