Environment:21st dev Magic mcp 21st MCP Endpoint
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Protocol, Authentication |
| Last Updated | 2026-10-19 16:40 GMT |
Overview
The hosted 21st MCP HTTP endpoint at `https://21st.dev/api/mcp`, authenticated via the `x-api-key` header, reachable directly or through the `@21st-dev/magic` stdio proxy.
Description
This environment is the remote 21st MCP server — a streamable-HTTP MCP endpoint that hosts every tool in this repo's surface: `search`, `get_component`, `generate`, `get_generation`, `get_take`, `search_logo`, `get_usage`, and `tools/list`. It is not part of this repo; `src/index.ts` only forwards JSON-RPC messages to it opaquely over `fetch`. The server enforces authentication (the `x-api-key` header must be a valid, non-reset 21st key) and, on the `initialize` response, returns an `mcp-session-id` header that must be echoed on subsequent requests for capability negotiation and inline UI to work.
The default URL is `https://21st.dev/api/mcp`; it can be overridden with the `MCP_URL_21ST` environment variable (used for staging/self-hosted testing). The `server.json` registry manifest declares the same URL with `type: "streamable-http"` and marks `x-api-key` as required + secret.
Usage
Use this environment for every 21st MCP tool call. It is the mandatory prerequisite for all server-side tools (`search`, `get_component`, `generate`, `get_generation`, `get_take`, `search_logo`, `get_usage`) and the `tools/list` discovery method. The `@21st-dev/magic` proxy (Implementation:21st_dev_Magic_mcp_forward) reaches it; clients that speak HTTP MCP directly can point at it without the proxy.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| Network | Outbound HTTPS to 21st.dev | TCP 443; the endpoint is internet-facing |
| Client | HTTP MCP (streamable-http) or a stdio MCP client + the proxy | Direct config uses `url` + `headers`; stdio clients use `command: npx @21st-dev/magic` |
| Hardware | Any | Server-side; the client only needs to send/receive JSON-RPC |
Dependencies
Endpoint
- URL: `https://21st.dev/api/mcp` (default; override with `MCP_URL_21ST`)
- Transport: streamable HTTP (one POST per JSON-RPC message; responses are JSON or `text/event-stream`)
- Auth: `x-api-key: <21st key>` header on every request
- Session: `mcp-session-id` header returned on `initialize`, echoed thereafter
Client-side
- A working MCP client (Cursor, Claude Code, VS Code, Windsurf, Codex, or any stdio/HTTP MCP host)
- Network egress to `21st.dev`
Credentials
- `x-api-key` (request header) — a valid, non-reset 21st API key from https://21st.dev/mcp. Old Magic keys were reset and are invalid.
- `MCP_URL_21ST` (optional) — override of the default endpoint URL.
The proxy resolves the key from argv/env via Implementation:21st_dev_Magic_mcp_resolveApiKey and sends it as the `x-api-key` header (Implementation:21st_dev_Magic_mcp_forward). Direct HTTP clients set `headers: { "x-api-key": "..." }` in their MCP config.
Quick Install
# Direct HTTP MCP config (no proxy needed):
# Add to your client's mcp.json:
# { "mcpServers": { "21st": {
# "url": "https://21st.dev/api/mcp",
# "headers": { "x-api-key": "YOUR_21ST_API_KEY" } } } }
# Or via the 21st CLI:
npx @21st-dev/cli@latest init --client <cursor|claude|vscode|windsurf|codex>
# Or via the stdio compatibility proxy (clients that only speak stdio):
npx -y @21st-dev/magic@latest API_KEY="21st-xxxxx"
Code Evidence
Default endpoint and override in `src/index.ts:21,75`:
const DEFAULT_ENDPOINT = "https://21st.dev/api/mcp";
// ...
const endpoint = process.env.MCP_URL_21ST || DEFAULT_ENDPOINT;
Auth header set on every proxied request in `src/index.ts:141-147`:
const headers: Record<string, string> = {
"content-type": "application/json",
accept: "application/json, text/event-stream",
"user-agent": `21st-magic-shim/${VERSION}`,
};
if (apiKey) headers["x-api-key"] = apiKey;
if (sessionId) headers["mcp-session-id"] = sessionId;
Session-id latch from the `initialize` response in `src/index.ts:170-171`:
const newSession = res.headers.get("mcp-session-id");
if (newSession) sessionId = newSession;
Registry manifest `server.json:8-20` declaring the remote + required secret header:
"remotes": [
{
"type": "streamable-http",
"url": "https://21st.dev/api/mcp",
"headers": [
{
"name": "x-api-key",
"description": "Your 21st.dev API key ... Authentication is required for discovery and tool calls.",
"isRequired": true,
"isSecret": true
}
]
}
]
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `Not authenticated - your API key is missing or was reset` (HTTP 401, latched) | Key missing, invalid, or an old reset Magic key | Issue a fresh key at https://21st.dev/mcp and restart the proxy / update the client config |
| `21st MCP endpoint unreachable (https://21st.dev/api/mcp): ...` | Network blocked, DNS failure, or `MCP_URL_21ST` pointing somewhere down | Allow outbound HTTPS to 21st.dev; unset `MCP_URL_21ST` to use the default |
| `Empty response (HTTP 200)` | Endpoint returned no body for a request expecting a reply | Usually a notification misclassified as a request; check the JSON-RPC `id` |
| `Non-JSON response (HTTP ...)` | Endpoint returned non-JSON (e.g. HTML error page) | Inspect the truncated body in the error; often a proxy/CDN issue, not the MCP server |
| `tools/list` omits `generate` | Account has no AI entitlement (by design, not an error) | Use `search`/`get_component`; see Environment:21st_dev_Magic_mcp_AI_Entitlement |
Compatibility Notes
- Direct HTTP vs. stdio proxy: Both paths reach the same server. HTTP clients skip the proxy entirely; stdio-only clients use `@21st-dev/magic` as the shim.
- Legacy tool names: `21st_magic_component_builder`, `21st_magic_component_inspiration`, `21st_magic_component_refiner`, `logo_search` are still accepted server-side and translated — old agent muscle memory keeps working.
- `mcp-session-id`: Must be captured from `initialize` and echoed. The proxy does this automatically (`src/index.ts:170-171`); direct HTTP clients must implement the same latch or capability negotiation (e.g. inline UI) breaks.
- `MCP_URL_21ST`: Overriding the endpoint is intended for staging; production should always resolve to `https://21st.dev/api/mcp`.
Related Pages
- Implementation:21st_dev_Magic_mcp_forward
- Implementation:21st_dev_Magic_mcp_search
- Implementation:21st_dev_Magic_mcp_get_component
- Implementation:21st_dev_Magic_mcp_generate
- Implementation:21st_dev_Magic_mcp_get_generation
- Implementation:21st_dev_Magic_mcp_get_take
- Implementation:21st_dev_Magic_mcp_search_logo
- Implementation:21st_dev_Magic_mcp_get_usage
- Implementation:21st_dev_Magic_mcp_tools_list