reversing-knowledge-mcp
# reversing-knowledge-mcp
A single-file [Model Context Protocol](https://modelcontextprotocol.io) server (stdio) that gives an AI client **search and read access to an allowlisted set of reverse-engineering and game-hacking sources**.
- **Search** — DuckDuckGo-backed search, hard-restricted to the allowlist (`site:` queries).
- **Read** — fetch an allowlisted page and return clean Markdown, with `httpx` first and a headless Playwright fallback for JavaScript or bot-protected pages.
- **List** — report the allowlist, cookie requirements and cookie-file status.
No database, no API keys, no external service. Everything runs locally over stdio.
---
## Tools
| Tool | Arguments | Returns |
| --- | --- | --- |
| `search_reversing_knowledge` | `query` (1–300 chars), `domain` (optional allowlisted domain), `limit` (1–25, default 10) | `list[{title, url, domain, snippet}]` |
| `read_thread_or_article` | `url` (allowlisted http/https), `page` (1–500, default 1) | `{url, domain, title, byline, page, pagination_supported, fetcher, content_markdown, truncated, content_length}` |
| `list_supported_sources` | — | `{domains, requires_cookies, cookies_file_present, notes}` |
---
## Requirements
- Python 3.10+
- Optional: Playwright Chromium for bot-protected sites
## Install
```bash
git clone https://github.com/<your-user>/reversing-knowledge-mcp.git
cd reversing-knowledge-mcp
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
playwright install chromium # optional but recommended
```
Or install it as a package, which adds a `reversing-knowledge-mcp` entry point:
```bash
pip install ".[browser]"
```
## Run
```bash
python /absolute/path/to/server.py
```
The server speaks MCP over stdin/stdout and prints logs to stderr, so it is meant to be launched by an MCP client rather than by hand.
---
## Client configuration
Always use an **absolute path** to `server.py` and the interpreter that has the dependencies installed — clients do not start the server from the project directory.
### Claude Desktop / Cursor / most clients (`mcpServers`)
`claude_desktop_config.json` on Windows lives at `%APPDATA%\Claude\claude_desktop_config.json`, on macOS at `~/Library/Application Support/Claude/claude_desktop_config.json`.
```json
{
"mcpServers": {
"reversing-knowledge": {
"command": "/absolute/path/to/.venv/bin/python",
"args": ["/absolute/path/to/server.py"],
"env": {
"MCP_COOKIES_PATH": "/absolute/path/to/cookies.json"
}
}
}
}
```
### OpenCode
```bash
opencode mcp add reversing-knowledge -- \
/absolute/path/to/.venv/bin/python /absolute/path/to/server.py
opencode mcp list
```
Or edit `opencode.json` (current releases nest servers under `mcp.servers`):
```json
{
"mcp": {
"servers": {
"reversing-knowledge": {
"type": "local",
"command": ["/absolute/path/to/.venv/bin/python", "/absolute/path/to/server.py"],
"environment": { "MCP_COOKIES_PATH": "/absolute/path/to/cookies.json" },
"protocol": "legacy"
}
}
}
}
```
`"protocol": "legacy"` avoids the new-protocol probe delaying startup; omit it on OpenCode 1.x, which also expects server names directly under `mcp` with an `enabled` flag.
### Claude Code
```bash
claude mcp add reversing-knowledge -- \
/absolute/path/to/.venv/bin/python /absolute/path/to/server.py
```
### VS Code (`.vscode/mcp.json`)
```json
{
"servers": {
"reversing-knowledge": {
"type": "stdio",
"command": "/absolute/path/to/.venv/bin/python",
"args": ["/absolute/path/to/server.py"]
}
}
}
```
Tool names are exposed as `<server>_<tool>`, e.g. `reversing-knowledge_search_reversing_knowledge`.
---
## Configuration
All settings are environment variables.
| Variable | Default | Purpose |
| --- | --- | --- |
| `MCP_COOKIES_PATH` | `./cookies.json` | Cookie file used for sites that require a session |
| `MCP_FETCH_TIMEOUT` | `20` | HTTP timeout in seconds |
| `MCP_PLAYWRIGHT_TIMEOUT` | `12000` | Browser navigation timeout in milliseconds |
| `MCP_MAX_CONCURRENCY` | `3` | Maximum concurrent outbound HTTP requests |
| `MCP_MAX_CONTENT_CHARS` | `60000` | Markdown truncation limit per read |
| `MCP_CACHE_TTL` | `600` | Read cache lifetime in seconds |
| `MCP_SEARCH_BACKENDS` | `yahoo,duckduckgo,mojeek,startpage,brave` | Comma-separated DuckDuckGo backends; an explicit list is used because `auto` aborts the whole search when one engine fails |
| `MCP_USER_AGENT` | Chrome 124 desktop UA | Outbound User-Agent |
| `MCP_LOG_LEVEL` | `WARNING` | stderr log level |
## Cookies
Several allowlisted forums return a challenge page or HTTP 403 without a session. Export your own cookies into a Playwright-compatible JSON array:
```bash
cp cookies.json.example cookies.json
chmod 600 cookies.json
```
Then fill in the real values. Cookie files are git-ignored, never logged, and only sent to the matching domain. This project does **not** bypass CAPTCHAs or logins — if a site blocks automated access, provide cookies for an account you are entitled to use, or read the page manually.
## Search quality notes
- An unrestricted keyword query runs first and its results are filtered against the allowlist.
- The remaining budget (up to 8 DuckDuckGo calls) is spent on per-domain `site:` queries for domains not yet covered.
- Multi-domain `site:(a OR b)` queries return nothing on the supported backends, so each domain is queried individually.
- Public search backends are rate-limited and occasionally answer with a challenge page; the explicit backend list makes a single failure non-fatal.
## Security model
- **Exact-or-subdomain host matching** against the allowlist — no substring matches (`evil-github.com` is rejected, `gist.github.com` is accepted).
- Only `http`/`https`, only ports 80/443, no userinfo (`user:pass@`).
- Hostnames are resolved and rejected if any address is loopback, private, link-local, reserved or multicast (SSRF guard).
- Redirects are re-validated; a redirect off the allowlist fails the read.
- Playwright requests are routed through the same allowlist and everything else is aborted.
- Reddit is restricted to `/r/ReverseEngineering`, `/r/REGames` and `/r/gamehacks`.
- Politeness: at most 3 concurrent outbound requests, one request per domain at a time, at least 1s between requests to the same domain.
## Tests
```bash
python -m unittest discover -s tests -v
```
The suite covers the allowlist and URL guards and needs no network access.
## Troubleshooting
| Symptom | Cause |
| --- | --- |
| Client shows the server as failed | Wrong interpreter path; install dependencies into the interpreter named in the config |
| `search_backend_unavailable` | Every search backend failed or rate-limited; retry later or change `MCP_SEARCH_BACKENDS` |
| `url_not_allowed` | URL is off the allowlist, non-http(s), on a non-standard port, or resolves to a private address |
| Forum thread returns a challenge page | Export cookies for that domain into `cookies.json` |
| `playwright_not_installed` | `pip install ".[browser]"` then `playwright install chromium` |
## Contributing
Issues and pull requests are welcome. Keep the server a single file, keep the three-tool surface, and add a guard test for any allowlist or validation change.
## License
MIT — see [LICENSE](LICENSE).
## Disclaimer
This project is a research tool. It only reads publicly reachable pages (or pages you supply cookies for) on the domains listed in `list_supported_sources`, and it is the user's responsibility to comply with each site's terms of service, robots.txt and local law. The maintainers do not host, mirror or distribute any third-party content, and the inclusion of a domain in the allowlist is not an endorsement of what is posted there.
TDQS
Scored across 3 tools
Each tool occupies a clearly distinct stage of the workflow: discovering sources, searching them, and reading the result. There is no plausible way to confuse list_supported_sources with search_reversing_knowledge or read_thread_or_article, since the descriptions name the resource and action unambiguously.
All three names use snake_case verb_noun form (list_, search_, read_) with nouns that match the server's domain vocabulary. The pattern is fully predictable.
Three tools is a minimal but coherent surface for a search-and-retrieve knowledge server, and each earns its place. It sits at the low end of the ideal range, though the narrow purpose justifies the small surface.
The retrieve lifecycle (enumerate sources, search, read with pagination) is covered end to end with no dead ends. Minor gaps remain: no way to list or filter sources by category without searching, and no multi-URL or batch fetch for assembling knowledge across threads.