
CTFd
io.github.MrJamescot由 GitHub 帳號 MrJamescot 發布v1.0.4更新於 Oct 24, 2026
MCP server for CTFd v3: list challenges, submit flags, and query scoreboards via AI agents.
概覽
面向 CTFd v3 實例的 MCP 伺服器,讓 AI 助理瀏覽題目、提交 flag、解鎖提示並查看排行榜。
- 可以做什麼
- 將伺服器指向 CTFd 實例並設定憑證(基礎 URL、API 權杖、工作階段 Cookie 或表單登入)。依分類、名稱與是否已解出篩選題目清單,並查看單一題目的完整詳情。在明確確認後提交 flag,並解鎖提示。將題目附件下載到本機目錄。讀取公開排行榜、自己的進度與實例中繼資料。檢查驗證狀態與實例健康狀態。
- 適用情境
- 適合在以 CTFd 為基礎的搶旗賽中,讓助理協助整理題目、查詢詳情、追蹤進度或提交你已找到的 flag。也適合透過可選的 REST 鏡像對 CTFd 實例撰寫腳本。
- 執行需求
- 本機 Python 3.10+ 程序,可從 PyPI 安裝(uvx 或 pip)或從原始碼執行。需要 CTFD_BASE_URL 指向 CTFd v3 實例,並提供一種憑證:CTFD_ADMIN_TOKEN(建議)、CTFD_SESSION_COOKIE,或 CTFD_USERNAME 加 CTFD_PASSWORD。需要能連線該實例的網路;除非啟用 CTFD_ALLOW_PRIVATE_IPS,否則私有與回送位址會被拒絕。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 CTFd,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
CTFd MCP Server
[PyPI - Version] [PyPI - Python Versions] [Docker Pulls] [License: MIT] [GitHub Stars]
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 overstdioorsse. - REST API (optional) —
server/main.py, a FastAPI mirror for scripting, debugging, and Docker deployments.
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), andsolved/unsolvedfilters, 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
GETs, no retries forPOSTs (no duplicate submissions), strict JSON/content parsing. - REST + MCP from one codebase — identical behaviour on both interfaces.
- No hardcoded instance —
BASE_URLis validated and configurable at startup and at runtime.
Installation
Requires Python 3.10+.
The fastest way is to install from PyPI:
For MCP clients, point your config at the packaged entry point:
Or run from source:
Configure
CTFD_BASE_URLmay include a path prefix (e.g.https://host/ctfd); the client appends/api/v1automatically.
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:
Manual launch:
MCP tools
With token auth, requests are sent with
Content-Type: application/json(CTFd only honoursAuthorization: Token ...on JSON requests). With cookie/credentials auth, state-changing requests echo the session CSRF nonce as theCSRF-Tokenheader, which is re-fetched from the site after login.
Tools return JSON text. Errors are structured, e.g.:
Running the REST API (optional)
Endpoints (all under /api/v1):
The optional REST API can be protected with an extra bearer token: set
CTFD_API_TOKEN, and requests to/api/v1/*will requireAuthorization: Bearer <token>. The server binds to loopback by default (MCP_HOST=127.0.0.1).
Docker
A ready-made image is published on Docker Hub:
Or build locally (REST mode):
docker compose up --build also works (REST API on http://localhost:8000).
To run the MCP SSE server in a container instead:
Usage examples
MCP (agent)
REST
See DEMO.md for a complete walkthrough and
examples/ for curl and Python snippets.
Development & testing
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):
Security considerations
- Credentials are memory-only. By default nothing is written to
server_state.json. EnablingCTFD_PERSIST_SECRETSis 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_urlrequires an absolutehttp(s)URL,submit_flagrequiresconfirm=True, etc.). - Controlled retries. Only idempotent
GETrequests 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=1opts out). A local container or a tool pointed at a private instance will get a clear error.
Limitations
- Requires CTFd v3+. The
/api/v1routes 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.
difficultyis not a standard CTFd field; challengevalue(points) is returned instead.solvedfiltering uses CTFd'ssolved_by_meflag, 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/v1calls 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_PASSWORDare 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/challengeson team-mode instances until it joins or creates a team; the server surfaces CTFd's permission message.
Contributing
Pull requests are welcome. Please:
- Open an issue describing the change.
- Add tests in
tests/(mocked CTFd API preferred). - Run
python -m pytest -qandruff check server ctfd_mcp_server.py tests. - Do not ship credentials in code, tests, or commit
server_state.json/.env.
License
MIT — repository: https://github.com/MrJamescot/ctfd-mcp-server
來源:README.md,提交 c75b77a
工具
0版本歷史
3- v1.0.4最新Sep 21, 2026
- v1.0.3Sep 20, 2026
- v1.0.2Sep 20, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分