MCP · Streamable HTTP
TokenRa MCP Server
TokenRa exposes its model catalog, live prices, balance and image/video generation as a remote MCP server. Any MCP-capable client can connect to one endpoint, discover seven tools, and spend against the same API key and balance as the REST API.
- Endpoint
https://tokenra.io/mcp- Transport
- Streamable HTTP, stateless
- Authentication
- API key or OAuth 2.1
- Tools
- 7 (2 read-only catalog tools, 3 account/task tools, 2 generation tools)
Overview
What the MCP server is
The MCP server is a thin, authenticated front door to the same gateway the REST API uses. Tool calls are executed by TokenRa itself: generation tools replay the request through the normal relay path, so channel selection, model permissions, IP allowlists, pre-consume, settlement and refunds behave exactly as they do for /v1 requests.
Two properties matter for agents:
- Read before spend.
list_modelsandget_model_priceare free, and every generation tool returns a price estimate unless you explicitly confirm. - Stateless transport. The server does not keep MCP sessions. A request that arrives during a deployment is served by whichever instance is live; no reconnect dance is needed.
Setup
Connect a client
You need a TokenRa account and an API key. Create one in the console under API Keys; the key is shown as sk-... and is the only secret a client needs.
Claude Code
Add the server with the HTTP transport and a bearer header:
claude mcp add --transport http tokenra https://tokenra.io/mcp \
--header "Authorization: Bearer sk-YOUR_API_KEY"Inside a session, /mcp lists the server and its tools. To use OAuth instead of a static header, omit --header and choose Authenticate from /mcp.
Any client that reads MCP JSON
Claude Desktop, Cursor and Cline accept the same mcpServers shape. Use this as the template and put it in the client's MCP configuration file:
{
"mcpServers": {
"tokenra": {
"type": "http",
"url": "https://tokenra.io/mcp",
"headers": {
"Authorization": "Bearer sk-YOUR_API_KEY"
}
}
}
}| Client | Where the file lives | Notes |
|---|---|---|
| Claude Code | ~/.claude.json or project .mcp.json | claude mcp add writes it for you; --scope user makes it global. ${VAR} expansion works in headers, so the key need not be literal. |
| Claude Desktop | claude_desktop_config.json | That file only holds stdio servers. For this remote server, either add a custom connector in Settings → Connectors (URL only; it authenticates with OAuth), or bridge it: npx -y mcp-remote https://tokenra.io/mcp --header "Authorization: Bearer sk-...". |
| Cursor | .cursor/mcp.json or ~/.cursor/mcp.json | A url entry is enough — Streamable HTTP is inferred; tools appear in Agent mode. |
| Cline | cline_mcp_settings.json | Add a Remote Server, then add the headers object to the entry by hand — the form has no header field. "type": "streamableHttp". |
| VS Code | .vscode/mcp.json | Uses "servers" instead of "mcpServers", with "type": "http". An inputs entry with "password": true prompts for the key instead of storing it. |
| Codex CLI | ~/.codex/config.toml | [mcp_servers.tokenra] with url and http_headers = { "Authorization" = "Bearer sk-..." }; bearer_token_env_var = "TOKENRA_API_KEY" reads the token from the environment. |
Clients that speak OAuth can connect with the URL alone — see Authentication.
Authentication
API key or OAuth 2.1
Every request to /mcp must carry a bearer credential. There are two ways to get one:
| Method | How it works | Best for |
|---|---|---|
| API key | Send Authorization: Bearer sk-... with every request. | Desktop and CLI clients you configure yourself; CI and scripts. |
| OAuth 2.1 | The client discovers the authorization server, registers itself, opens a consent page, and receives an API key as its access token. | Clients with built-in OAuth support; no secret copied into a config file. |
How OAuth works here
- The gateway is both the resource server and the authorization server. An unauthenticated request receives
401withWWW-Authenticate: Bearer resource_metadata="https://tokenra.io/.well-known/oauth-protected-resource/mcp". - Only public clients are supported: authorization code with PKCE (
S256), no client secret. Redirect URIs must be HTTPS, or HTTP on a loopback address; a loopback port is ignored when matching. - The consent page asks you to sign in to TokenRa and approve the
mcpscope. Approval creates a normal API key namedMCP (OAuth) · <client name>, so it appears in the console and can be renamed, restricted or deleted like any other key. - Access tokens are API keys. They expire after
MCP_OAUTH_KEY_EXPIRY_DAYSdays (default 90;0means never). Refresh tokens expire afterMCP_OAUTH_REFRESH_EXPIRY_DAYSdays (default 180). Each refresh rotates both tokens and deletes the old key. - Deleting the key in the console, or deleting the user, invalidates the refresh token immediately. A revoked authorization cannot be renewed.
Reference
Tools
Seven tools are registered. The three read-only groups are free; the two generation tools bill the current key's quota only after you confirm.
| Tool | Purpose | Billed |
|---|---|---|
list_models | List models available to this key, filtered by modality, vendor or name. | No |
get_model_price | Live unit price for one model in the key's group. | No |
get_balance | Account balance and this key's remaining and used quota, in USD. | No |
get_task | Status, progress and result URL of one image or video task. | No |
list_tasks | Recent generation tasks, optionally filtered by status. | No |
generate_image | Quote, then generate images through the OpenAI-compatible image endpoint. | Yes |
generate_video | Quote, then submit an asynchronous video job; poll with get_task. | Yes |
list_models
Arguments: modality (text, image, video, embedding), vendor, query, limit (default 50, maximum 200). Returns total, count, group and a models array of model, vendor, modalities and quota_type (0 = per token, 1 = per call). Only models the key may actually use are returned.
get_model_price
Arguments: model, optional group. Returns the effective group ratio and one of input_per_million_usd, output_per_million_usd, cache_per_million_usd, per_call_usd, or video_resolution_per_million_usd for video models, plus billing_mode and billing_expr when tiered billing applies.
get_balance
No arguments. Returns user_quota / user_balance_usd for the account and token_remain_quota / token_remain_usd for this key, along with the key's group, used quota and quota_per_usd.
get_task and list_tasks
get_task takes task_id and returns status (NOT_START, SUBMITTED, QUEUED, IN_PROGRESS, SUCCESS, FAILURE), progress, timestamps, quota_usd, result_url and fail_reason. list_tasks takes an optional status and limit (default 20, maximum 100).
generate_image
Arguments: model, prompt, n (1–128, default 1), optional size, quality, group, and confirm. Without confirm it returns a quote — requires_confirmation, estimated_usd for per-call models, call_cap_usd — and charges nothing. With confirm=true it generates and returns a JSON summary plus inline image content when the upstream returns base64 data.
generate_video
Arguments: model, prompt, optional image (first-frame or reference URL), duration (seconds, maximum 3600), resolution, ratio, generate_audio, group, and confirm. Without confirm it returns the unit price and a note explaining that the final charge depends on actual duration and resolution. With confirm=true it submits the job and returns task_id; poll get_task until result_url is present.
Billing
Quotes, billing and refunds
Generation tools use the gateway's normal billing chain. On confirmation TokenRa pre-consumes the estimated quota, settles against actual usage, and refunds failed jobs. The MCP layer does not keep a second ledger.
- Every generation tool accepts
confirm; calling it withoutconfirmis always free and safe to repeat. - A per-call guard rejects an image or video request whose estimate exceeds
MCP_MAX_CALL_USD(default5.00) before anything is charged. Raise the environment variable if you need larger single calls. - Token-billed image models cannot be estimated exactly before the call; the quote says so and the actual charge follows usage.
- Failed jobs are refunded automatically. Use
list_tasksorget_taskto confirm the final state rather than resubmitting.
Limits
Limits and errors
| Limit | Value |
|---|---|
| Request body | 4 MB |
| Image count per call | 128 images |
| Video duration | 3600 seconds |
| Model list page | 200 models |
| Task list page | 100 tasks |
| Client registration | 20 per hour per IP |
| Authorize / token endpoints | 120 requests per minute per IP |
Authentication failures return 401 with a WWW-Authenticate header. Non-POST requests to the endpoint return 405 with Allow: POST (browsers that navigate to /mcp receive the landing page instead). Tool failures are returned as MCP tool errors with an English message; gateway errors such as insufficient quota, a disabled model or an upstream failure are passed through with their original status and message.
Security
Data handling and key safety
- The MCP server has exactly the permissions of the key that authenticated the call: model limits, group, IP allowlist and quota all apply.
- Prompts, image URLs and generated content are forwarded to the upstream model provider. See zero data retention for what TokenRa stores and for the documented exceptions.
- Consume logs record the model, tokens, quota and the entry point (
client: mcp), so MCP usage is separable from direct/v1traffic in Usage Logs. - To revoke access, delete the key in the console. For OAuth, deleting the key also invalidates its refresh token, so the client cannot silently re-authorize itself.
FAQ
FAQ
Does MCP cost extra?
No. Tool calls are billed at the same model rates as the REST API, and the read-only tools are free. There is no MCP subscription or per-request surcharge.
Which clients work today?
Any client that speaks MCP Streamable HTTP. Tested configurations are Claude Code, Claude Desktop, Cursor, Cline, VS Code and Codex CLI; the JSON template above also works for clients that accept a custom HTTP MCP server.
Do I have to use OAuth?
No. A bearer API key is enough. OAuth is for clients that can run the discovery and consent flow without putting a secret in a file.
Can the agent generate a video and wait for it?
Yes, by polling. generate_video returns a task_id immediately; the agent should call get_task until status is SUCCESS or FAILURE instead of submitting again.
Why did a generation call return a quote instead of an image?
Because confirm was omitted. The first call is always a quote; repeat the same call with confirm=true to submit. This is deliberate: an agent that misreads a prompt cannot spend by accident.
How do I see what an MCP client spent?
Open Usage Logs and filter by the key name. MCP requests are tagged with client: mcp in the log detail, and OAuth keys are named MCP (OAuth) · <client>.