CTFd MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@CTFd MCP Server list the available challenges"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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 overstdioorsse.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), 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.
Related MCP server: CyberEdu MCP Server
Installation
Requires Python 3.10+.
The fastest way is to install from PyPI:
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-restFor MCP clients, point your config at the packaged entry point:
{
"mcpServers": {
"ctfd-mcp": {
"command": "ctfd-mcp",
"env": {
"CTFD_BASE_URL": "https://demo.ctfd.io",
"CTFD_ADMIN_TOKEN": "ctfd_..."
}
}
}
}Or run from source:
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 .envConfigure
Variable | Default | Meaning |
| (empty) | CTFd instance root, e.g. |
| (empty) | API token (preferred auth) |
| (empty) | Session cookie, e.g. |
| (empty) | Username for form login |
| (empty) | Password for form login |
|
| Per-request HTTP timeout (seconds) |
|
| Max redirects followed per request |
|
| File used to cache auth state |
|
| MCP transport: |
|
| REST server bind settings (loopback by default) |
| (empty) | Optional bearer token protecting the optional REST API ( |
|
| Allow connections to private/loopback/metadata addresses (e.g. local CTFd test instances) |
|
| Directory where challenge attachments are saved by |
|
| ⚠ Strongly discouraged: write secrets to disk |
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:
// 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:
# 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/sseMCP tools
Tool | Parameters | Description |
|
| Point the server at a CTFd instance |
|
| Adopt an API token (memory only) |
|
| Adopt a session cookie (memory only) |
|
| Form login; keeps the session cookie |
|
| Paginated challenge list with filters |
|
| Full detail of one challenge |
|
| Submit a flag (requires |
|
| Download a challenge attachment over the CTFd |
|
| Unlock and read a hint (paid hints cost points) |
| — | Public scoreboard standings |
| — | Your score + solved challenges |
| — | Safe public instance metadata |
| — | Auth mode + validity (no secrets) |
| — | Reachability, API and auth checks |
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.:
{ "error": { "type": "ChallengeNotFoundError", "message": "Challenge '99' not found (or not visible)." } }Running the REST API (optional)
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 8000Endpoints (all under /api/v1):
Method | Path | Description |
POST |
| Validate & set the CTFd base URL |
POST |
| Set API token |
POST |
| Set session cookie |
POST |
| Store username/password for later login |
POST |
| Form login (session cookie) |
GET |
| Paginated + filtered challenge list |
GET |
| Challenge detail |
POST |
| Submit a flag ( |
POST |
| Download a challenge attachment (body: |
POST |
| Unlock and read a hint (body: |
GET |
| Public standings |
GET |
| Your score and solves |
GET |
| Public instance metadata |
GET |
| Auth mode + validity |
GET |
| Health check |
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:
docker run --rm -p 8000:8000 \
-e CTFD_BASE_URL=https://ctf.example.com \
-e CTFD_ADMIN_TOKEN=ctfd_... \
jamescot/ctfd-mcp-serverOr build locally (REST mode):
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-mcpdocker compose up --build also works (REST API on http://localhost:8000).
To run the MCP SSE server in a container instead:
docker run --rm -it -e CTFD_BASE_URL=https://ctf.example.com ctfd-mcp python ctfd_mcp_server.py
# stdio on the attached terminalUsage 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=trueREST
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/healthSee DEMO.md for a complete walkthrough and
examples/ for curl and Python snippets.
Development & testing
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 testsThe 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):
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/healthSecurity 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
Available Tools
14 toolsauth_statusA
Report whether the current session is authenticated and which auth mode is active.
Reveals no tokens/cookies/passwords.
Inputs: no named parameters. Returns: result
challengeB
Get the full detail of a single challenge by numeric id or name.
Includes description, category, value, files, hints and connection info.
Args: identifier: challenge id (e.g. "3") or challenge name.
Inputs: identifier (required). Returns: result
challengesA
List challenges with optional filters and pagination.
Args: category: filter by challenge category (exact match). search: case-insensitive substring match on challenge name. solved: only show solved (True) or unsolved (False) challenges. page: page number (1-based) when no filters are applied. per_page: number of challenges per page (1-100).
Inputs: page, search, solved, category, +1 more. Returns: result
download_fileA
Download a challenge attachment to the local machine.
Challenge detail (challenge tool) returns a files array with
site-relative paths like /files/<hash>/<name> (signed URLs on some
deployments). Pass one of those values here.
Args: file_url: absolute http(s) URL or site-relative path to the file. dest_dir: optional local directory to store the file in (default: CTFD_DOWNLOAD_DIR or ./downloads).
Inputs: file_url (required), dest_dir. Returns: result
healthA
Perform a health check: CTFd reachability, API status and authentication state.
Inputs: no named parameters. Returns: result
instance_infoA
Return safe, public metadata about the configured CTFd instance.
No secrets are included.
Inputs: no named parameters. Returns: result
loginB
Log in to CTFd with a username and password (kept in memory only).
Creates a session cookie; the password is never returned.
Args: username: CTFd account name. password: CTFd account password.
Inputs: password (required), username (required). Returns: result
progressA
Return the authenticated user's progress (score and solved challenges).
Inputs: no named parameters. Returns: result
scoreboardA
Return the public CTFd scoreboard (top standings).
Inputs: no named parameters. Returns: result
set_base_urlB
Configure the CTFd instance this server talks to.
Args: url: absolute http(s) URL of the CTFd instance, e.g. https://ctf.example.com
Inputs: url (required). Returns: result
set_cookieB
Use a session cookie for authentication (memory only, never logged).
Args: cookie: full session cookie value, e.g. "session=abc..." or "name=..; session=..".
Inputs: cookie (required). Returns: result
set_tokenB
Use an API token for authentication (stored in memory only, never logged).
Args: token: CTFd API access token.
Inputs: token (required). Returns: result
submit_flagA
Submit a flag for a challenge.
Safety: requires confirm=True. Provide exactly one of challenge_id or challenge_name. The flag value is never logged.
Args: flag: the flag to submit. challenge_name: name of the challenge to submit against. challenge_id: numeric id of the challenge to submit against. confirm: must be set to True as an explicit submission opt-in.
Inputs: flag (required), confirm, challenge_id, challenge_name. Returns: result
unlock_hintA
Unlock a challenge hint and return its content.
WARNING: on CTFd a hint with a non-zero cost deducts that many points
from your account. When two hint IDs are needed (e.g. a hint's
prerequisites), unlock them in order.
Args:
hint_id: numeric id of the hint (see the challenge tool result).
Inputs: hint_id (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 14 tools
Most tools have clearly distinct purposes, but the authentication group (set_token, set_cookie, login, auth_status) plus health overlap around session/state checking, and challenge vs challenges differ only by singular/plural which can cause misselection. Descriptions do help disambiguate the intended usage.
A mix of conventions: verb_noun tools (set_token, submit_flag, download_file, unlock_hint) coexist with bare-noun tools (challenges, challenge, scoreboard, progress, instance_info, health). Each name is readable in isolation, but there is no single predictable pattern.
14 tools is well within a healthy range and each earns its place, covering setup, auth, challenge interaction, and status without bloat.
For a player-facing CTFd client the surface is strong: auth, listing/reading challenges, flag submission, file download, hint unlock, scoreboard, and progress. Minor gaps remain (e.g. category listing, team/teammate endpoints), but core workflows have no dead ends.
Maintenance
Related MCP Connectors
MCP server for AI dialogue using various LLM models via AceDataCloud
MCP server for OpenAI API (chat completions, image generation, embeddings) via AceDataCloud
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
An MCP server that let you interact with Cycloid.io Internal Development Portal and Platform
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAn MCP server that connects AI clients to a Linux terminal for real-time automated penetration testing and CTF challenge solving. It enables AI models to execute terminal commands and interact with offensive security tools like Nmap, SQLMap, and Gobuster.-
- FlicenseNot gradedqualityDmaintenanceOfficial MCP server for the CyberEdu CTF platform that automatically discovers and exposes all CyberEduClient methods as tools, enabling seamless interaction with the platform through MCP-compatible clients.8-
- FlicenseNot gradedqualityDmaintenanceA vulnerable MCP server designed for educational CTF challenges. It demonstrates various MCP security vulnerabilities in a controlled environment.8-
- FlicenseBqualityCmaintenanceA lightweight MCP server that enables AI assistants to interact with the local machine through terminal, filesystem, and Python execution tools.9-