linuxdo-mcp
# linuxdo-mcp
MCP server for reading two Discourse forums: [linux.do](https://linux.do) and
[idcflare.com](https://idcflare.com). Anonymous by default: no account, no API key,
no cookie to paste.
One process serves one site, chosen at startup, because the two need different
transports and expose different tools. Everything else — the payload model, the
paging rules, the image handling — is shared.
## Choosing the site
```shell
$ uv run linuxdo-mcp # linux.do, the default
$ LINUXDO_SITE=idcflare uv run linuxdo-mcp
```
`LINUXDO_SITE` accepts `linuxdo` or `idcflare`. The site is resolved before any tool
is described, so the tool names, their descriptions, and the server instructions all
match the forum actually being read. A host that wants both runs two MCP entries:
```json
{
"mcpServers": {
"linuxdo": { "command": "uv", "args": ["run", "linuxdo-mcp"] },
"idcflare": {
"command": "uv",
"args": ["run", "linuxdo-mcp"],
"env": { "LINUXDO_SITE": "idcflare" }
}
}
}
```
| | linux.do | idcflare.com |
| ---------------------- | ----------------------------------------- | ----------------------------------------------- |
| `search` tool | absent: full-text search needs a login | present: `/search.json` answers anonymously |
| Transport | `httpx` with a stored Cloudflare clearance | `curl_cffi` reproducing a browser TLS fingerprint |
| Cloudflare clearance | required, refreshed by a headful browser | never needed; no credential is held |
| Tags | about 2200, so `min_count`/`limit` matter | 17, so one page holds the vocabulary |
| Uploaded images | `cdn*.ldstatic.com` | `idcflare.com` |
The two forums barely overlap in content: on 2026-12-02 the 60 newest-plus-hot
titles on each shared exactly zero topics, and the category trees are unrelated
(linux.do is a developer community; idcflare is server deals, reviews, and
tutorials). Reading both is running both.
## Why there is a browser in the loop (linux.do only)
linux.do sits behind Cloudflare, and every anonymous JSON request is answered with a
managed challenge instead of Discourse data:
```shell
$ curl https://linux.do/latest.json
HTTP/2 403
cf-mitigated: challenge
<html><head><title>Just a moment...</title></head>…
```
Measured on 2026-12-01: browser headers, `curl_cffi` TLS impersonation, and headless
Chromium all fail. A **headful** Chromium with a real GPU solves the challenge in a few
seconds and leaves a `cf_clearance` cookie in its profile. Once that cookie exists, plain
`httpx` with the matching `User-Agent` gets `200` — the clearance is the only thing the
edge wants from an API client.
idcflare needs none of that. Measured on 2026-12-02: its edge judges the TLS
fingerprint, not a credential — `curl` with a browser user agent gets `200`,
`httpx` gets `403 cf-mitigated: challenge` with every header set tried, and
`curl_cffi` gets `200` with no cookie at all. So the idcflare instance runs
`curl_cffi` and never opens a browser, stores a cookie, or asks for a display.
So the transport has two speeds:
| Phase | Mechanism | Frequency |
| ------- | ------------------------------------------------------------------------- | ---------------------------------------- |
| Acquire | headful Chromium on a persistent profile, wait for the challenge to clear | once, then when the cookie stops working |
| Read | `httpx` with the stored clearance headers | every tool call |
Nothing is fetched with the browser except the initial page load. The browser window
appears for a few seconds during acquisition and closes itself.
## Install
```shell
$ uv sync --extra browser
$ uv run playwright install chromium
```
`--extra browser` is only needed for linux.do, and even then it is optional: without
Playwright the server still runs, and a challenge fails with a message naming the
missing piece. The idcflare instance never imports Playwright.
## Use
```shell
$ uv run linuxdo-mcp doctor # where am I? clearance age, edge status
$ uv run linuxdo-mcp doctor --refresh # linux.do: open the browser once and replace the clearance
$ uv run linuxdo-mcp # stdio MCP server
$ uv run linuxdo-mcp --transport streamable-http --host 127.0.0.1 --port 8000
```
`doctor` reports the selected site, its transport, and its credential state, then probes
`/latest.json` and — on idcflare — `/search.json`. On idcflare there is nothing to
refresh, so `--refresh` prints that and does nothing.
For linux.do, the clearance lives in `${XDG_CACHE_HOME:-~/.cache}/linuxdo-mcp/` (mode
`0600`), next to the Chromium profile. It is never printed, logged, or returned by a
tool; `session_status` reports only a fingerprint, an age, and whether it has gone past
30 days (`stale`). A stale cookie is still replayed — the browser only runs again when
linux.do actually challenges, or when you ask for it. The idcflare instance loads
nothing from that directory and reports `mode: "anonymous"`.
On a host without a display the acquisition step cannot run. Copy that directory from a
desktop session, or accept that reads will fail with a challenge message.
An MCP host spawns the server with a filtered environment, so `DISPLAY` and
`WAYLAND_DISPLAY` usually do not reach it even on a desktop. `session_status` therefore
reports `browser_available: false` there and names the cause in
`browser_unavailable_reason`; the clearance still works, and a refresh has to run from your
own shell (`doctor --refresh`).
## Tools
| Tool | Answers |
| ----------------- | --------------------------------------------------------------------------------------------------------------------- |
| `browse_topics` | what is new (`latest`), today's score (`hot`), a period (`top`), a category, a tag, or a `filter` by order/status/tag |
| `search` | keyword hits with their topic, post, excerpt, and author (**idcflare only**) |
| `list_categories` | category and subcategory ids and slugs, cached ten minutes |
| `list_tags` | tag names with topic counts, for `browse_topics(tag=...)` |
| `get_topic` | the posts of one topic, as text; walk a long one with `next_post_number` |
| `get_post` | one post by id, without pulling the topic window |
| `get_post_image` | one image of a post as an MCP image block, size-capped |
| `get_user` | a profile, plus activity totals and recent topics with `include_summary` |
| `session_status` | the site, its transport, whether a clearance is loaded and whether a refresh can run here |
On linux.do there is no `search` tool: it requires a login for full-text search
(`{"error_type": "not_logged_in"}`). `/filter.json` still accepts `tag:`, `status:`,
`order:` and `likes-min:` terms anonymously, which is what `sort="filter"` composes;
categories and tags remain the keyword-free way in.
idcflare does answer search anonymously, so that instance registers `search`: a term
returns matched posts with `topic_id`, `post_number`, an excerpt as plain text (the
highlight markup is stripped), the author, and the topic title joined from the same
response. Pass `next_page` back as `page` to read on; a page holds up to 50 hits.
Pass a tag's `name` to `browse_topics`. Discourse's slug is for display only: an
ASCII tag routes by either form, but a Chinese tag's slug is `{id}-tag` and
`/tag/31-tag.json` returns 404, while `/tag/公告.json` works.
`list_tags` returns the band `/tags.json` publishes (about 2,200 names on linux.do),
not every tag a topic can carry: linux.do omits some routable tags from that list
(「公告」 is absent there yet `/tag/公告.json` answers). So a tag missing from
`list_tags` is unknown, not nonexistent — pass it to `browse_topics(tag=...)` to
confirm.
`list_categories` flattens both levels, because a topic's `category_id` can name a
subcategory: its route carries the parent slug
(`/c/feedback/announcement/49.json`), and a bare `/c/announcement/49.json` only
redirects.
Paging is cursor-driven: `browse_topics` returns `next_page`, and passing it back
as `page` yields the next window (`null` means the listing ended). Page sizes are
30 except for `top` and `hot`, which are 50 — read `per_page` rather than assuming.
`limit` defaults to 50. Trim it below the page size and the reply is cut, `trimmed`
says how many topics were withheld, and `next_page` is `null`: a page cursor starts
after the whole upstream page, so hand it back and the withheld tail is skipped for
good. Raise `limit` to read that tail, or keep 50 while paging.
Pinned topics occupy the first slots of a page whatever the requested order, so a
`sort=filter order=likes` page starts with them, not with the most-liked ordinary
topic. They carry `pinned: true`; skip them when ranking.
Long topics work the same way: `get_topic` returns one window of posts plus
`next_post_number`, which is what to pass back as `post_number` (`null` means the
last window). Windows overlap rather than skip, so a few posts may repeat. The
header's `highest_post_number` is the real end of the walk: deleted posts leave
holes, so it exceeds `posts_count` and `stream_length`. Exact posts come from
`post_ids`, which costs a second upstream call because linux.do ignores that
parameter on the topic route; its `next_post_number` continues by position from the
highest requested number, not by id.
## Bodies, images, and truncation
Every read asks for `include_raw=true`, so `body` is the author's own Markdown
rather than cooked HTML reduced to text: about half the characters on a long post
(7,085 vs 15,149 on one measured linux.do post), with tables and link targets
intact. Discourse omits `raw` for a few posts; those fall back to the HTML path
automatically, and `include_raw=false` requests the simplified text outright.
Discourse's `|WxH` size suffix is dropped from an image's alt text, so a Markdown
host renders the description instead of `alt|690x350`.
A small action post (the topic was pinned, closed, or a user joined) has no body at
all upstream. Those carry `action_code` (`pinned_globally.enabled`) and an empty
`body`, so an empty post is never a rendering failure.
Each post carries `images`, in document order, with the lightbox's original file
and the downscaled render side by side:
```json
{
"url": "https://cdn3.ldstatic.com/original/4X/c/7/2/…jpeg",
"thumb_url": "https://cdn3.ldstatic.com/optimized/4X/c/7/2/…_2_512x499.jpeg",
"alt": "image"
}
```
`thumb_url` is `null` when Discourse served no render for that file; the image is
still readable, just only at its original size.
Emoji and avatars are excluded: both are decoration, and a quote or onebox pulls
in the quoted author's avatar along with the real content. A read never downloads
images; `get_post_image` does, one file at a time, on request (below). The links
need no clearance because the media hosts serve those files publicly.
`body` is Markdown throughout, with two Discourse forms normalised before it
reaches a caller. A quoted reply arrives as BBCode
(`[quote="user, post:3, topic:1"]…[/quote]`) and comes back as a `> **user**`
blockquote; an uploaded image's `upload://…` short link is replaced with the CDN
URL already listed in `images`, when the two counts line up. If they do not line
up, the short link is left alone and `images` stays the authoritative list.
### Reading an image
`get_post_image(topic_id, post_id, index)` returns the file itself as an MCP
`image` block plus one text line naming it, so a host that renders images can look
at a screenshot or a resume without a second download step. Read the post first:
`index` is the position in that post's `images`.
- One image per call, on purpose: a 20-post window can embed 20 pictures, and a
topic read must not become megabytes of base64.
- `size="full"` (default) fetches the original; `size="thumb"` the inline render.
A tall image has an unreadable render (a 1080×5285 resume becomes 102px wide),
which is why full is the default. When Discourse has no render for the file,
`thumb` returns the original and the text line says so.
- `max_bytes` defaults to 4 MiB. An original over it comes back as its render and
the text line says the substitution happened; a render that is also too big is
reported rather than retried.
- Only the selected site's media hosts over https are ever requested: `cdn*.ldstatic.com`
for linux.do, `idcflare.com` for idcflare. Post content is untrusted input, so any
other host in an image URL is refused instead of fetched.
- A clearance is not sent with an image: the hosts serve these files publicly, and the
cookie belongs to the forum host alone.
`max_post_chars` (default 8000, per post) caps `body`; a post that hit it reports
`truncated: true`. Raise the cap for that one post instead of treating the cut
text as the whole thing.
## Development
```shell
$ uv run ruff format --check .
$ uv run ruff check .
$ uv run pytest -q
```
Tests never touch either forum: they drive `httpx.MockTransport` with captured payloads.
TDQS
Scored across 8 tools
The two read tools (get_topic and get_post) genuinely overlap in the sense that both return post text, but the descriptions explicitly resolve this by telling the agent to prefer get_post for a known post id and get_topic for a window. list_categories, list_tags, browse_topics, get_post_image, get_user, and session_status each target a distinct resource, so selection is unambiguous in practice.
Seven of eight tools follow a clean verb_noun snake_case pattern (list_categories, browse_topics, list_tags, get_post, get_post_image, get_topic, get_user). session_status breaks the pattern as a bare noun phrase, but it is the sole deviation and remains self-explanatory.
Eight tools is well within the sweet spot and each one earns its place: discovery (categories, tags, topics), reading (topic, post, image), identity (user), and diagnostics (session_status). There is no obvious redundancy or padding.
For a read-only forum client the surface is solid: navigation, topic windows with pagination, single-post fetch, inline images, and user profiles. The main gaps are full-text search (documented as an upstream login restriction with tag/filter workarounds) and any per-user topic/activity listing or write operations, which limit some workflows but do not create dead ends for reading.