page2md-mcp
# Page2MD
**Paste a URL, get the page's real content back as clean Markdown** —
headings, links, images, lists, code blocks and tables, with nav and
footer chrome stripped. Built for RAG pipelines and LLM workflows, and
for agents that read documentation: tabbed and collapsible panels are
converted **in full**, not just the visible one, and every result
carries a completeness report so missing or cut content is never
silent.
Pure Python standard library — no dependencies, nothing to pip install.
## MCP server
This repo is a **Model Context Protocol (MCP) server**: `mcp_server.py`
speaks MCP over stdio (JSON-RPC, protocol version 2024-11-05) using only
the Python standard library — no MCP SDK required. It exposes one tool,
implemented on top of the local converter in `converter.py`:
| Tool | Input | Output |
|---|---|---|
| `url_to_markdown` | `{ "url": "https://example.com/docs" }` | `{ url, final_url, title, markdown, chars, mode, completeness }` — the Markdown plus a completeness report (see below) |
Run it directly:
```bash
python3 mcp_server.py
```
Or with Docker (a `Dockerfile` is included, `python:3.12-slim`, no installs):
```bash
docker build -t page2md .
docker run -i page2md
```
Add it to any MCP client (e.g. Claude Desktop `claude_desktop_config.json`):
```json
{
"mcpServers": {
"page2md": {
"command": "python3",
"args": ["/path/to/page2md-mcp/mcp_server.py"],
"env": { "PAGE2MD_RAPIDAPI_KEY": "your_key_here" }
}
}
}
```
The `PAGE2MD_RAPIDAPI_KEY` env var is optional — without it the free
local converter runs; with it, conversions go to the hosted Page2MD API
on RapidAPI (see "Deep mode" below).
## The completeness report
Most converters silently return only the visible tab of a tabbed docs
page — the other panels exist in the HTML but never reach your RAG
index, and nothing tells you they were dropped. Page2MD walks the
whole document regardless of visibility and reports what it found:
```json
"completeness": {
"panels_found": 5,
"panels_included": 5,
"truncated": false,
"notes": ["page contains 5 tabbed/collapsible panel(s); 5 included in full"]
}
```
- `panels_found` / `panels_included` — `role="tabpanel"` elements,
tab-panel classes and `<details>` blocks, and how many of them made
it into the Markdown.
- `truncated` — output is capped at 200,000 characters; if a page
converts to more, the Markdown is cut at a line boundary and this
flag (plus a note) says so. A truncated result never pretends to
be complete.
## What the local converter handles
- Headings, paragraphs, links (relative URLs resolved), images
(alt text + resolved `src`), nested ordered/unordered lists,
blockquotes, inline code, fenced `pre` blocks, simple pipe tables
(pipes in cells escaped), definition lists, `<details>` sections.
- Chrome stripped: `script`, `style`, `nav`, `footer`, forms and
other non-content elements, plus `role="navigation"` /
`"banner"` / `"contentinfo"` / `"search"` containers.
- Lenient parsing: unclosed and mismatched tags do not crash it.
- Plain-text responses are returned as-is.
Known limits: no JavaScript execution (content that only exists
after client-side rendering is not in the HTML and cannot be
converted), tables with merged cells are flattened, and deeply
exotic markup may lose formatting. The completeness report covers
panels and truncation; it cannot detect content that was never in
the served HTML.
## Deep mode (hosted API)
```bash
export PAGE2MD_RAPIDAPI_KEY=your_key_here
python3 mcp_server.py
```
With a key set, `url_to_markdown` POSTs the URL to the hosted
Page2MD API — the same conversion the production backend serves
(`POST /convert` with `{"url": ...}`, returning JSON with
`markdown` / `title` / `url`) — via its RapidAPI gateway:
| Env var | Default | Meaning |
|---|---|---|
| `PAGE2MD_RAPIDAPI_KEY` | *(unset = local mode)* | Your RapidAPI key for the Page2MD listing |
| `PAGE2MD_RAPIDAPI_HOST` | `page2md-url-to-clean-markdown-api.p.rapidapi.com` | Gateway host (the RapidAPI convention for the listing slug `page2md-url-to-clean-markdown-api`); override if your gateway host differs |
| `PAGE2MD_RAPIDAPI_PATH` | `/convert` | Endpoint path |
If the hosted call fails, the tool falls back to the local converter
and says so in the completeness notes — it never returns an empty
shell. Hosted results note that panel-level completeness is
determined by the hosted converter.
Get a key on RapidAPI — the hosted API is the
[Page2MD listing by NewKwLab](https://rapidapi.com/binbin7418/api/page2md-url-to-clean-markdown-api?utm_source=github&utm_medium=referral&utm_campaign=20261205-page2md-mcp).
## Tests
```bash
python3 tests/run_tests.py
```
Runs the converter and the MCP server against local fixtures only
(a localhost stub server and `file://` URLs — no external network):
a tabbed docs page whose hidden panels must all appear, a messy
article with nested lists/tables/code, garbage inputs, a 404, an
oversized page that must report truncation, and full stdio
protocol checks (initialize / tools/list / tools/call).
## Use without MCP
```python
import converter
result = converter.url_to_markdown("https://example.com/docs")
print(result["markdown"])
print(result["completeness"])
```
## License
MIT
TDQS
Scored across 1 tool
There is exactly one tool, so there is no possibility of confusion with a sibling tool. Its purpose (fetch a URL and return clean Markdown) is stated unambiguously in the description.
The single name url_to_markdown is descriptive snake_case and clearly conveys source and output format. With only one tool there is no cross-tool pattern to validate, which caps this slightly below full marks.
One tool is thin in absolute terms, but the server's scope is narrowly and honestly defined as URL-to-Markdown conversion, and the tool packs real capability (panel extraction, completeness reporting, local vs. hosted modes). It is not a trivial stub, so the minimal surface is defensible.
The single tool covers the full pipeline for its domain: fetch, clean, convert, strip chrome, and report completeness. Minor gaps remain—no batch/multi-URL input and no direct file-write or alternate output formats—but an agent can work around these.