markdown-mcp

markdown-mcp

Splits Markdown documents into hierarchical sections with parent-child and sibling relationships, enabling structured document access for AI assistants.

Category
访问服务器

README

Python License Execute Tests Deploy to Cloud Run Ask DeepWiki

Markdown MCP Server

Learn MCP Development by Example A complete, production-ready Model Context Protocol (MCP) server that demonstrates best practices for building intelligent document processing tools.

What is this?

This is a Model Context Protocol (MCP) server that intelligently splits Markdown documents into hierarchical sections while preserving parent-child relationships and sibling connections. Built with FastMCP and FastAPI, it serves as both a useful tool and an educational resource for developers learning to create their own MCP servers. The project includes automated testing and deployment via GitHub Actions workflows.

Why MCP?

The Model Context Protocol enables AI assistants to access external tools and data sources securely and efficiently. This server demonstrates how to:

  • Build MCP-compliant tools that AI models can use
  • Handle structured document processing
  • Maintain relationships in hierarchical data
  • Integrate with modern Python web frameworks

Features

Core Functionality

  • Hierarchical Splitting: Maintains header relationships (H1 → H2 → H3...)
  • Sibling Detection: Identifies headers at the same level for navigation
  • Code-Aware Processing: Ignores # comments in fenced code blocks
  • Rich Metadata: Includes parent references, sibling lists, and optional token counts

Technical Stack

  • MCP Compliant: Full Model Context Protocol interface support
  • FastAPI Powered: High-performance async server with automatic OpenAPI docs
  • Well Tested: Core splitting functionality covered with pytest
  • Type Safety: Complete type hints with Pydantic models
  • Docker Ready: Containerized deployment support
  • CI/CD: Automated testing and deployment via GitHub Actions

Requirements

  • Python >=3.12, <3.13

Quick Start

This project uses Poetry for dependency management. To get started:

git clone https://github.com/Gal-Gilor/markdown-mcp.git
cd markdown-mcp
python -m venv .venv && source .venv/bin/activate
poetry install
python src/main.py

Usage

To run the MCP server (if the environment is activated):

python src/main.py

If the environment is not activated, you can run using Poetry:

poetry run python src/main.py
  • The server will start on http://0.0.0.0:8080.

  • The MCP server is mounted at /server.

  • The MCP server is accessible at /server/mcp.

  • Available tools:

    • split_text(text: str) -> list[Section]: Splits the input Markdown text into a list of Section objects.

      {
          "section_header": "Getting Started",
          "section_text": "Welcome to the guide...",
          "header_level": 2,
          "metadata": {
              "parents": {"h1": "Introduction"},
              "siblings": ["Advanced Topics", "FAQ"]
          }
      }
      

      Example Request:

      curl -X POST http://localhost:8080/server/mcp/tools/call \
      -H "Content-Type: application/json" \
      -H "Accept: application/json, text/event-stream" \
      -d '{
          "jsonrpc": "2.0",
          "id": 1,
          "method": "tools/call",
          "params": {
          "name": "split_text",
          "arguments": {
              "text": "# Header 1\n\nSome content here.\n\n## Header 2\n\nMore content."
          }
          }
      }'
      

Architecture Overview

Project Structure

src/
├── main.py          # FastAPI app and MCP server setup
├── models.py        # Pydantic data models
└── splitter.py      # Core splitting logic

tests/
├── conftest.py      # Test fixtures
└── test_splitter.py # Splitter functionality tests

Key Components

  • FastMCP Integration: Uses @mcp.tool decorator to expose functions as MCP tools
  • Pydantic Models: Type-safe data structures with validation
  • Hierarchical Processing: Two-pass algorithm for building document structure
  • Code Block Protection: Regex-based approach to ignore comments in code

How It Works

  1. Code Block Processing: Protects # comments in fenced code blocks
  2. Header Detection: Uses regex pattern ^(#+)\s+(.+)$ to find headers
  3. Hierarchy Building: Maintains parent-child relationships using a stack
  4. Sibling Detection: Groups headers at same level with same parent
  5. Section Creation: Converts hierarchical structure to flat list of sections

Development

Setup

python -m venv .venv && source .venv/bin/activate
poetry install

Commands

  • make lint: Run ruff for code formatting and linting
  • make test: Run pytest test suite
  • python src/main.py: Start the development server

Testing

# Run all tests
poetry run pytest

# Run with verbose output
poetry run pytest -v

# Run specific test file
poetry run pytest tests/test_splitter.py

CI/CD

The project includes GitHub Actions workflows for automated testing and deployment:

  • Execute Tests (.github/workflows/execute_main_tests.yaml): Runs pytest test suite on push/PR to main branch
  • Deploy to Cloud Run (.github/workflows/deploy_main.yaml): Automatically deploys to Google Cloud Run on push to main branch

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选