Ctfd MCP Server

MCP运维云端

提供方 MrJamescot

运维云端 stdio · 本地进程 Token 社区 / 第三方 Claude DesktopClaude
查看接入方式

一个轻量级且可扩展的模型上下文协议(MCP)服务器,用于与任何CTFd实例交互,支持AI工具和自动化通过稳定API层进行认证、检索挑战和提交标志。

一句话选型结论

按资料字段整理

Ctfd MCP Server 属于运维云端类 MCP 服务器,stdio · 本地进程,Token,可直接接入 Claude Desktop、Claude,有可直接执行的安装命令。接入前先确认权限范围;涉及写入、删除或付款的操作,建议先在测试环境验证。

分类运维云端 传输方式stdio · 本地进程 鉴权Token 部署方式本地部署
GitHub 星标 3 仓库热度,无公开仓库时显示未标注
工具数 5 暴露给模型的工具数量
资源 / 提示词 0 / 0 资源与提示词模板数量
维护方 社区 / 第三方 核验等级 仅资料核对

工具与能力

运维云端
数量来自来源目录的标注,具体工具清单以官方文档为准
工具数量5暴露给模型可调用的工具个数
资源数量0可读取的资源条目
提示词数量0内置提示词模板数量

能力标签

支持客户端

适用场景

CTFdPython本地部署MCP服务器API接口自动化工具AI集成

安装与配置

stdio · 本地进程 Token
客户端在本机拉起子进程,数据不出本机
pip install -r requirements.txt

这条命令只是入口,具体启动参数请按官方文档补齐,不要直接照搬到别的服务器。

  1. 1
    准备运行环境

    stdio 服务在本地起进程,需要先装好 Node.js 等运行时,再按安装命令拉取依赖。

  2. 2
    安装服务

    复制上面的安装命令执行;命令里带占位符的位置,换成自己的密钥或路径。

  3. 3
    写入客户端配置

    在客户端的 MCP 配置里填好启动命令和参数,保存后完全退出客户端再打开,让新配置生效。

  4. 4
    验证是否可用

    连接成功后客户端会列出约 5 个工具,随便调一个只读工具确认能返回结果。

典型使用场景

3 类
按分类与标签整理的常见用法,具体以官方文档为准
云资源查询

查实例、存储、账单等云上资源状态。

部署与发布

把部署、重启、回滚这类操作接进对话。

监控与告警

拉取监控指标,异常时让模型帮你判断。

选择建议

选之前先看这几条
按条目字段给出的判断,不替你决定用不用

值得选的地方

  • 资料标注 5 个工具,职责相对集中,接入后不容易误操作。
  • 有现成的安装命令,不用自己找入口,照着跑就能起服务。
  • 已适配 Claude Desktop、Claude,换客户端不用重新研究配置。

先想清楚的地方

  • stdio 方式要求本地装好运行时(如 Node.js),换机器要重新装一遍。
  • 使用前要准备好Token对应的凭据,并按最小权限配置。
  • 版本更新与行为细节以官方仓库为准。

更适合

  • 需要在运维云端场景里让模型直接调用外部能力的人。
  • 已经在用 Claude Desktop、Claude 的用户,接入路径最短。
  • 想先快速试一下、能接受在本地或自有环境跑服务的人。

不太适合

  • 完全不想在本地装环境的人。
  • 不方便管理密钥或第三方授权的人。
  • 需要厂商级 SLA 和技术支持的生产环境。

同类对比

6 个同类
同分类里挑最接近的几条,字段以各自详情页为准
MCP 服务器工具数传输方式部署方式安装命令最后核验
Ctfd MCP Server当前 5 stdio · 本地进程 本地部署 有 2026-05-17
lobehub 未标注 stdio · 本地进程 本地部署 有 2026-04-11
TrendRadar 未标注 stdio · 本地进程 本地部署 有 2026-04-13
Ui Tars Desktop 8a825770 未标注 stdio · 本地进程 本地部署 有 2026-05-17
ruflo 未标注 stdio · 本地进程 本地部署 有 2026-04-13
FastGPT 未标注 stdio · 本地进程 本地部署 有 2026-04-11

服务器档案

运维云端
字段来自项目仓库与公开索引,中文说明由本站标注
提供方MrJamescot上游标注的维护方 MrJamescot
分类运维云端本站按上游分类展示
连接方式stdio · 本地进程客户端在本机拉起子进程,数据不出本机
鉴权方式Token远程服务建议用最小权限凭据
维护方社区 / 第三方核验等级 仅资料核对
包名 / 运行时未标注 · 未标注本地安装时用到的包标识与运行时
部署类型本地部署上游给出的部署形态
最近核验2026-05-17上游最后核验时间

详细介绍

16.3 KB
来自项目仓库与上游目录的原文,未做删改

CTFd MCP Server

A Model Context Protocol (MCP) server for interacting with any CTFd v3 instance.
It lets AI tools (Claude Desktop, Cursor, custom agents, ...) authenticate, list
and inspect challenges, submit flags, and query instance state through a stable,
type-safe interface.

The project ships two interfaces built on the same client library:

  • MCP tools (primary) — ctfd_mcp_server.py, used over stdio or sse.
  • REST API (optional) — server/main.py, a FastAPI mirror for scripting,
    debugging, and Docker deployments.```
    ┌──────────────────────────────────────────────┐
    AI agent / MCP │ FastMCP (MCP tools) │
    client ────────►│ set_token · login · challenges · submit_flag │
    └──────────────────┬───────────────────────────┘
    │ shared client
    ┌──────────────────▼───────────────────────────┐
    curl / scripts ─►│ FastAPI REST (/api/v1/...) (optional) │
    └──────────────────┬───────────────────────────┘
    │
    ┌──────────────────▼───────────────────────────┐
    │ server.ctfd_client.CTFdClient │
    │ └─ gateway.py (HTTP, auth, timeouts) │
    └──────────────────┬───────────────────────────┘
    │ HTTPS / HTTP
    ┌─────▼─────┐
    │ CTFd │
    └───────────┘

Credentials (token / cookie / password) live **in memory only** and are never
echoed in tool output, written to `server_state.json`, or logged.

---

## Features

- **Multiple authentication modes** — API token, session cookie, or username/password
  form login (with CSRF handling).
- **Rich challenge queries** — paginated listing with `category`, `search` (name),
  and `solved`/`unsolved` filters, plus per-challenge detail retrieval.
- **Safe flag submission** — requires an explicit `confirm=True`, returns clear
  success/failure, and surfaces rate-limit errors. Flags are never logged.
- **Instance introspection** — public instance info, health check, and an
  authentication-status tool that reveal no secrets.
- **Consistent structured errors** — `AuthenticationError`, `CTFdAPIError`,
  `ChallengeNotFoundError`, `SubmissionError`, `ValidationError`,
  `ConfigurationError`.
- **Pagination by default** — one page of challenges per call; no accidental
  full-dump downloads.
- **Hardened HTTP** — configurable timeouts, one safe retry for idempotent `GET`s,
  no retries for `POST`s (no duplicate submissions), strict JSON/content parsing.
- **REST + MCP from one codebase** — identical behaviour on both interfaces.
- **No hardcoded instance** — `BASE_URL` is validated and configurable at startup
  and at runtime.

---

## Installation

Requires Python 3.10+.

The fastest way is to install from **PyPI**:```bash
pip install ctfd-mcp-server

# MCP stdio server with env config:
CTFD_BASE_URL=https://ctf.example.com CTFD_ADMIN_TOKEN=ctfd_... ctfd-mcp

# optional REST interface:
ctfd-rest

For MCP clients, point your config at the packaged entry point:```jsonc
{
"mcpServers": {
"ctfd-mcp": {
"command": "ctfd-mcp",
"env": {
"CTFD_BASE_URL": "https://demo.ctfd.io",
"CTFD_ADMIN_TOKEN": "ctfd_..."
}
}
}
}


Or run from source:```bash
git clone https://github.com/MrJamescot/ctfd-mcp-server.git
cd ctfd-mcp-server
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

cp .env.example .env     # then edit .env

Configure

Variable Default Meaning
CTFD_BASE_URL (empty) CTFd instance root, e.g. https://ctf.example.com (without /api/v1)
CTFD_ADMIN_TOKEN (empty) API token (preferred auth)
CTFD_SESSION_COOKIE (empty) Session cookie, e.g. session=abc...
CTFD_USERNAME (empty) Username for form login
CTFD_PASSWORD (empty) Password for form login
CTFD_HTTP_TIMEOUT 15 Per-request HTTP timeout (seconds)
CTFD_HTTP_MAX_REDIRECTS 5 Max redirects followed per request
CTFD_STATE_FILE ~/.local/state/ctfd-mcp/server_state.json File used to cache auth state
CTFD_MCP_TRANSPORT stdio MCP transport: stdio or sse
MCP_HOST / MCP_PORT 127.0.0.1 / 8000 REST server bind settings (loopback by default)
CTFD_API_TOKEN (empty) Optional bearer token protecting the optional REST API (/api/v1/*)
CTFD_ALLOW_PRIVATE_IPS false Allow connections to private/loopback/metadata addresses (e.g. local CTFd test instances)
CTFD_DOWNLOAD_DIR ./downloads Directory where challenge attachments are saved by download_file
CTFD_PERSIST_SECRETS false ⚠ Strongly discouraged: write secrets to disk

> CTFD_BASE_URL may include a path prefix (e.g. https://host/ctfd); the client
> appends /api/v1 automatically.


Running the MCP Server

Most MCP clients launch the server themselves via a command/args config.
For that, your client config should reference ctfd_mcp_server.py:```jsonc
// e.g. Claude Desktop / mcp.json
{
"mcpServers": {
"ctfd-mcp": {
"command": "python",
"args": ["/path/to/ctfd-mcp-server/ctfd_mcp_server.py"],
"env": {
"CTFD_BASE_URL": "https://demo.ctfd.io",
"CTFD_ADMIN_TOKEN": "ctfd_..."
}
}
}
}


Manual launch:```bash
# stdio (default) — used by MCP clients
python ctfd_mcp_server.py

# SSE — expose over HTTP for remote/Docker use
CTFD_MCP_TRANSPORT=sse python ctfd_mcp_server.py   # http://127.0.0.1:8000/sse

MCP tools

Tool Parameters Description
set_base_url url Point the server at a CTFd instance
set_token token Adopt an API token (memory only)
set_cookie cookie Adopt a session cookie (memory only)
login username, password Form login; keeps the session cookie
challenges category, search, solved, page, per_page Paginated challenge list with filters
challenge identifier (id or name) Full detail of one challenge
submit_flag flag, challenge_name/challenge_id, confirm Submit a flag (requires confirm=True)
download_file file_url, dest_dir Download a challenge attachment over the CTFd /files/… route
unlock_hint hint_id Unlock and read a hint (paid hints cost points)
scoreboard — Public scoreboard standings
progress — Your score + solved challenges
instance_info — Safe public instance metadata
auth_status — Auth mode + validity (no secrets)
health — Reachability, API and auth checks

> With token auth, requests are sent with Content-Type: application/json
> (CTFd only honours Authorization: Token ... on JSON requests). With
> cookie/credentials auth, state-changing requests echo the session CSRF nonce
> as the CSRF-Token header, which is re-fetched from the site after login.

Tools return JSON text. Errors are structured, e.g.:```json
{ "error": { "type": "ChallengeNotFoundError", "message": "Challenge '99' not found (or not visible)." } }


---

## Running the REST API (optional)```bash
python scripts/run_local.sh           # reads .env, default http://127.0.0.1:8000
# or
uvicorn server.main:app --host 0.0.0.0 --port 8000

Endpoints (all under /api/v1):

Method Path Description
POST /set_base_url Validate & set the CTFd base URL
POST /set_token Set API token
POST /set_cookie Set session cookie
POST /set_creds Store username/password for later login
POST /login Form login (session cookie)
GET /challenges Paginated + filtered challenge list
GET /challenges/{id-or-name} Challenge detail
POST /submit Submit a flag (confirm: true required)
POST /download Download a challenge attachment (body: file_url)
POST /unlock_hint Unlock and read a hint (body: hint_id)
GET /scoreboard Public standings
GET /progress Your score and solves
GET /instance_info Public instance metadata
GET /auth_status Auth mode + validity
GET /health Health check

> The optional REST API can be protected with an extra bearer token: set
> CTFD_API_TOKEN, and requests to /api/v1/* will require
> Authorization: Bearer. The server binds to loopback by default
> (MCP_HOST=127.0.0.1).


Docker

A ready-made image is published on Docker Hub:```bash
docker run --rm -p 8000:8000 \
-e CTFD_BASE_URL=https://ctf.example.com \
-e CTFD_ADMIN_TOKEN=ctfd_... \
jamescot/ctfd-mcp-server


Or build locally (REST mode):```bash
docker build -t ctfd-mcp .
docker run --rm -p 8000:8000 \
  -e CTFD_BASE_URL=https://ctf.example.com \
  -e CTFD_ADMIN_TOKEN=ctfd_... \
  ctfd-mcp

docker compose up --build also works (REST API on http://localhost:8000).

To run the MCP SSE server in a container instead:```bash
docker run --rm -it -e CTFD_BASE_URL=https://ctf.example.com ctfd-mcp python ctfd_mcp_server.py

stdio on the attached terminal


---

## Usage examples

### MCP (agent)```
1. set_base_url      url="https://ctf.example.com"
2. set_token         token="ctfd_..."
3. challenges        category="web", solved=false, page=1, per_page=25
4. challenge         identifier="3"
5. submit_flag       flag="flag{...}", challenge_id=3, confirm=true

REST```bash

curl -X POST http://localhost:8000/api/v1/set_base_url \
-H 'Content-Type: application/json' -d '{"url":"https://ctf.example.com"}'

curl -X POST http://localhost:8000/api/v1/set_token \
-H 'Content-Type: application/json' -d '{"token":"ctfd_..."}'

curl 'http://localhost:8000/api/v1/challenges?search=web&solved=false&per_page=10'

curl -X POST http://localhost:8000/api/v1/submit \
-H 'Content-Type: application/json' \
-d '{"challenge_id":3,"flag":"flag{...}","confirm":true}'

curl http://localhost:8000/api/v1/health


See `DEMO.md` for a complete walkthrough and
`examples/` for curl and Python snippets.

---

## Development & testing```bash
pip install -r requirements-dev.txt

python -m pytest -q          # 76 unit tests, mocked CTFd API (no network)
ruff check server ctfd_mcp_server.py tests

The test suite mocks the CTFd API (tests/conftest.py::FakeGateway), so unit
tests run offline.

Integration testing against a real CTFd

Run a local CTFd for live tests (recommended over the shared demo instance,
which serves HTML on public auth-gated routes):```bash
git clone https://github.com/CTFd/CTFd.git /tmp/CTFd
docker compose -f /tmp/CTFd/docker-compose.yml up

create a user/challenge, then:

CTFD_BASE_URL=http://localhost:8000 python ctfd_mcp_server.py
CTFD_BASE_URL=http://localhost:8000 uvicorn server.main:app --port 8001
curl http://localhost:8001/api/v1/health
```


Security considerations

  • Credentials are memory-only. By default nothing is written to
    server_state.json. Enabling CTFD_PERSIST_SECRETS is discouraged.
  • Secrets are never echoed. Tool and API responses, error messages and logs
    redact tokens, cookies, passwords and flags (server/utils.py).
  • Every tool validates its input before touching the network (set_base_url
    requires an absolute http(s) URL, submit_flag requires confirm=True,
    etc.).
  • Controlled retries. Only idempotent GET requests are retried (once).
    Flag submissions are never automatically replayed.
  • Trust model. The server is a local/dev tool: whoever can call its tools can
    point it at any CTFd instance and (with a valid credential) read data or submit
    flags. Do not expose the REST/SSE endpoints on an untrusted network.
  • SSRF guard. By default connections to private / loopback / link-local /
    metadata addresses are refused (CTFD_ALLOW_PRIVATE_IPS=1 opts out). A local
    container or a tool pointed at a private instance will get a clear error.

Limitations

  • Requires CTFd v3+. The /api/v1 routes used are standard CTFd v3 API
    routes.
  • Form login depends on CTFd's web session flow (CSRF nonce extraction is
    best-effort). API tokens are the recommended authentication method.
  • difficulty is not a standard CTFd field; challenge value (points) is
    returned instead.
  • solved filtering uses CTFd's solved_by_me flag, which is only meaningful
    when authenticated.
  • Instance "version" is reported only when it appears in the rendered page; CTFd
    has no public version API endpoint.
  • Tokens are per-instance. CTFd redirects /api/v1 calls to its login page
    when a credential is invalid. The server detects this and reports: "the
    credential is not valid for THIS instance"
    — a token from one CTFd instance
    never works on another.
  • When CTFD_USERNAME/CTFD_PASSWORD are configured, the server auto-logs-in
    on demand
    (rotating the session cookie) whenever a call returns
    unauthenticated, so expired sessions self-heal. After each login the CSRF
    nonce is re-fetched from the site (a fresh nonce is required for flag
    submissions over a web session).
  • A teamless account sees no /api/v1/challenges on team-mode instances until it
    joins or creates a team; the server surfaces CTFd's permission message.

Contributing

Pull requests are welcome. Please:

  1. Open an issue describing the change.
  2. Add tests in tests/ (mocked CTFd API preferred).
  3. Run python -m pytest -q and ruff check server ctfd_mcp_server.py tests.
  4. Do not ship credentials in code, tests, or commit server_state.json /
    .env.

License

MIT — repository:

常见问题

8 问
答案由本站依据条目字段整理,不引用上游原文
Ctfd MCP Server 怎么安装?

在客户端按下面的安装命令接入:pip install -r requirements.txt。装完在客户端配置里引用同一个包或端点。

Ctfd MCP Server 怎么在 Claude Desktop、Claude 里配置?

它的传输方式是stdio · 本地进程,在客户端的 MCP 配置里填好启动命令和参数,保存后完全退出客户端再打开,配置才会生效。

Ctfd MCP Server 收费吗?

本站不代收费用,也没有标注具体价格。是否收费取决于服务本身和背后的接口额度,正式使用前按官方说明确认。

Ctfd MCP Server 需要 API Key 吗?

资料标注需要Token认证,使用前准备好对应凭据,并按最小权限配置。

Ctfd MCP Server 支持哪些客户端?

资料标注支持 Claude Desktop、Claude;其他客户端只要能配置 MCP Server,也能用同样的命令或地址接入。

Ctfd MCP Server 能提供哪些能力?

资料显示约 5 个工具;能力标签包括 API接口、Python、Claude、自动化。具体工具清单以官方文档为准。

Ctfd MCP Server 需要什么运行环境?

属于本地进程,需要在本机装好运行环境。

Ctfd MCP Server 是本地还是远程?

它是本地进程(stdio),由客户端在本机拉起。传输方式为stdio · 本地进程。

热门专题

按标签挑服务器
全部专题 →

服务器信息以作者仓库与官方文档为准;分类、传输方式与鉴权方式的中文说明为中文整理,最近核验 2026-05-17。