SuperAPI AI Directory

tokenlab-mcp-server

TokenLab AI gateway: model and price discovery plus OpenAI-compatible Chat Completions, Responses, Anthropic Messages and Gemini inference.

Open website

About this tool

TokenLab MCP Server is a Model Context Protocol (MCP) server automatically generated from OpenAPI, targeting the TokenLab public API and providing model discovery, pricing queries, native LLM endpoints, typed decisions, multimodal generation, asynchronous tasks, files, embeddings, reranking, translation, resources, prompts, and broader developer API capabilities.

Purpose This server is primarily intended for agents to perform model selection, view supported request formats, or compare prices before calling the TokenLab API. It exposes both public catalog tools and tools that require credentials: public catalog tools do not require an API key; credential tools cover text inference, image generation and editing, video, music, 3D, asynchronous task polling, embeddings, reranking, typed decisions, and text translation.

Main capabilities

  • Public catalog tools: used for model discovery, pricing comparison, and request format viewing.
  • Credential tools: text inference, image generation and editing, video, music, 3D, asynchronous task polling, embeddings, reranking, typed decisions, text translation.
  • Native MCP features: JSON tool responses include structuredContent while retaining serialized text for compatibility with older clients; HTTP errors preserve the original response text (up to 4,000 characters) along with structured status, request ID, and retry time; generation tools provide readable titles, standard read-only/destructive/idempotent/open-world annotations, and response request IDs.
  • Resources and prompts: three resources respectively expose a live API overview, the package's OpenAPI snapshot, and a compact MCP public contract; the choose_tokenlab_model and build_tokenlab_request prompts guide agents to use live model information and preserve native endpoint shapes.
  • Server instructions: prompt clients to confirm billing or destructive operations, and treat external model/API output as untrusted content.

Tool profiles and modes

  • TOKENLAB_MCP_TOOL_PROFILE=catalog: a minimal public-only tool list.
  • TOKENLAB_MCP_TOOL_PROFILE=core (default): the core tool set.
  • TOKENLAB_MCP_TOOL_PROFILE=full: broad developer API.
  • TOKENLAB_MCP_SCHEMA_MODE=portable (defaults to the profile), exact, strict. Use exact only when the client needs the full nested JSON Schema and can accept larger/deeper tool payloads; strict is suitable for providers that require all properties listed in required and additionalProperties: false set on every object, with complex top-level parameters represented as JSON-encoded strings and decoded before canonical validation. Version 0.6.30 generates 87 endpoint tools; together with two MCP-specific composite discovery tools, the full profile returns 89 tools from tools/list. All profiles include compare_models and get_api_overview, with totals of 6, 32, and 89 respectively. Live and streaming-only operations are excluded because stdio MCP tool calls return only one final result.

Usage Install from npm:

The agent-assisted installer can follow llms-install.md for credential-safe setup and verification flow. Add -e TOKENLAB_API_KEY when using credential API tools. Public catalog tools do not require a key. Claude Desktop-style configuration:

Public catalog and pricing operations do not require a TokenLab API key. Set TOKENLAB_API_KEY when credential tools need to call the TokenLab API. Generated tools preserve the OpenAPI request shapes of OpenAI-compatible and native endpoints rather than flattening them into a shared prompt format. Multipart operations accept local file paths. Small image and audio responses are returned as native MCP content; larger or other binary responses are written to TOKENLAB_ARTIFACT_DIR, and the path, MIME type, and byte count are returned.

Synchronous and asynchronous media results Video, music, and 3D creation tools always return asynchronous tasks. Image generation and editing may return a completed result or an asynchronous task, depending on the selected model and request. Media tools preserve the full TokenLab API response under response and add a normalized delivery summary. Use delivery.mode rather than assuming all image requests are synchronous. For asynchronous tasks, call get_task_status and pass { "id": delivery.task_id } until delivery.terminal is true. Completion status is determined by status, not the optional progress field.

Environment variables

  • TOKENLAB_API_BASE: optional, default https://api.tokenlab.sh
  • TOKENLAB_API_KEY: Optional; required for text inference, multimodal generation, asynchronous tasks, embeddings, reranking, decisions, and translation tools
  • TOKENLAB_MCP_TOOL_PROFILE: Optional, catalog, core (default), or full
  • TOKENLAB_MCP_SCHEMA_MODE: Optional, portable, exact, or strict; by default uses the tested mode of the selected profile
  • TOKENLAB_REQUEST_TIMEOUT_MS: Optional request timeout in milliseconds, default 120000
  • TOKENLAB_MCP_MAX_FILE_BYTES: Optional maximum local upload size per file, default 104857600 (100 MiB)
  • TOKENLAB_MCP_INLINE_BYTES: Optional maximum size of binary/JSON responses returned inline, default 2097152 (2 MiB)
  • TOKENLAB_ARTIFACT_DIR: Optional output directory for non-inline response artifacts, default tokenlab-mcp under the OS temporary directory

Image Input and MIME Handling For Chat Completions image input, prefer byte-exact data URLs, such as data:image/png;base64,.... If the MCP caller marks a recognizable PNG, JPEG, WebP, or GIF payload as application/octet-stream, the server corrects that generic MIME before forwarding. Unrecognizable generic binary payloads are rejected locally with an exact input error.

Contract and Release The public OpenAPI document is the source of the API contract. The overlay contains only MCP-specific choices: profile exposure, stable tool aliases, secret omission, non-streaming constraints, content type variants, asynchronous task semantics, and the compact public projection used by the website and documentation gate. Always run git pull --ff-only before manually syncing the contract. contract:check only proves internal consistency; contract:source-check proves freshness relative to the canonical source. The planned Sync TokenLab OpenAPI contract workflow runs the full write sequence and commits only the verified OpenAPI snapshot and generated manifest to main. Fetch failures, stale local branches, dirty generated output, generation errors, schema compilation errors, or test failures all leave the tracked contract unchanged.

MCP Registry Metadata The repository contains server.json for the official MCP Registry. Release metadata: npm package @tokenlabai/mcp-server@0.6.30; MCP registry name io.github.hedging8563/tokenlab; package.json.mcpName is io.github.hedging8563/tokenlab. When releasing a new version, bump the matching version in package.json, package-lock.json, and server.json; push a matching tag such as v0.6.0; the release workflow tests and publishes npm via trusted publishing, then publishes the MCP Registry entry via GitHub Actions OIDC. The same workflow can be run manually from main to republish only the current MCP Registry metadata. No npm or MCP Registry tokens are stored in GitHub.

Security Recommendations Use the catalog profile when credential tools are not needed. Keep TOKENLAB_API_KEY in the local MCP client's secret environment, enable human confirmation for billing and destructive calls, and review tool annotations before granting persistent approval. Do not send TokenLab API keys to untrusted hosted MCP servers.

Webhook Management Use the full profile to configure workspace webhooks via list_webhooks, create_webhook, get_webhook, update_webhook, delete_webhook, rotate_webhook_secret, test_webhook, and list_webhook_deliveries. Set TOKENLAB_MANAGEMENT_TOKEN=mt-... separately from TOKENLAB_API_KEY=sk-.... Create a management token in Dashboard → API → Management Tokens. It onlyAuthorized management operations within the workspace, not limited to webhooks. Reasoning keys cannot replace it; the whsec_... returned by creation/rotation is only used for receiver signature verification. Keep all credentials out of tool parameters and prompts. Webhook notifications avoid continuous task polling. In polling fallback, stop on terminal states, 401/403/404, or retryable: false; back off on transient failures.

Applicable scenarios Applicable to agent workflows that need to access the TokenLab API through an MCP client, including model selection and pricing comparison, text inference, multimodal generation, asynchronous task management, embeddings and reranking, translation, and webhook management.

Limitations Real-time and streaming-only operations are excluded, because stdio MCP tool calls return only one final result. API operations that accept stream are internally fixed to false, and boolean constants are not exposed to provider adapters; the Gemini query string API key is intentionally hidden from tool parameters. create_gemini_content exposes camelCase Gemini fields (systemInstruction, generationConfig, safetySettings, toolConfig, cachedContent), and hides their snake_case proto spellings. The compatibility budget keeps core at no more than 60 KB and depth 8, and full at no more than 115 KB and depth 8. Tests also run the full profiles using the Google AI SDK version used by the observed OpenCode/Gemini failures, and keep its function declarations within 90 KB.

Website:https://tokenlab.sh/mcp Documentation:https://tokenlab.sh/docs OpenAPI:https://tokenlab.sh/docs/openapi.json Model catalog:https://api.tokenlab.sh/v1/models Skills:https://github.com/hedging8563/tokenlab-skills