MCP
Run ai-cli as a stdio MCP server with typed tools for every command.
ai mcp starts a stdio MCP server that exposes every ai command as a typed
tool. It speaks newline-delimited JSON-RPC 2.0 over stdin and stdout and
supports MCP 2025-11-25 tools. Diagnostics go to stderr.
--profile core|media|all selects the tools to expose. core is the default.
Setup
The server reads your key from its environment, like every ai command. Set
AI_GATEWAY_API_KEY in your MCP client's config, as below. Many clients do not
pass your shell environment to MCP servers. The key is never a tool input, so
agents cannot read it or send it elsewhere.
fx (~/.fx/mcp.json):
Other clients (mcpServers):
opencode (opencode.json):
Claude Code:
Codex:
| Variable | Purpose |
|---|---|
AI_GATEWAY_API_KEY | Vercel AI Gateway API key. Required. |
AI_CLI_OUTPUT_DIR | Absolute directory for generated files. Without it, files land in each call's cwd. |
AI_GATEWAY_BASE_URL, AI_GATEWAY_TEAM_ID_OR_SLUG | Optional Gateway overrides. Agents cannot set these. |
Add --profile all to the command for the video and audio tools. opencode stops
tool calls after 30 seconds unless timeout is raised, as in the example.
Profiles
| Tool | Profile | CLI command |
|---|---|---|
text | core | ai text |
image | core | ai image |
decide | core | ai decide |
models | core | ai models |
video_start | media | ai video start |
video_status | media | ai video status |
audio_speak | media | ai audio speak |
audio_transcribe | media | ai audio transcribe |
media contains the four media tools. all contains all eight tools.
Results
Tool results are the command's JSON output. Generation tools return a manifest
with the saved file paths. text and audio_transcribe return a file path
to read. If you do not pass output, files are written to the call's cwd, or
to AI_CLI_OUTPUT_DIR when it is set.
Tool failures return an error result with the command's diagnostic.
Inputs
Each tool's inputs are its command's own flags, named in camelCase
(--aspect-ratio becomes aspectRatio) with the same descriptions as
--help. Repeatable flags take a string array, and on/off flags take a boolean.
Terminal-only flags (--quiet, --no-preview, --no-play, --no-waveform)
are left out. Gateway connection flags (--base-url, --headers,
--scope, --team-id-or-slug) are rejected, including in extraArgs, so an agent cannot
send your Gateway key to another endpoint. Set AI_GATEWAY_BASE_URL and
AI_GATEWAY_TEAM_ID_OR_SLUG in the server environment instead.
Every tool also accepts these inputs:
| Input | Type | Description |
|---|---|---|
cwd | string | Working directory for the run |
extraArgs | string[] | Extra CLI flags appended last |
timeoutMs | integer | Timeout from 1 to 2147483647 (default 600000) |
Decide
decide takes a non-empty questions array. Each question has an id,
type, and question. type is boolean, choice, or score. A choice
requires choices; a score requires levels. IDs must not contain =, and
choices and levels must not contain commas.
The optional state string is written to stdin. The result is the command's
JSON output.
Video
video_start returns immediately and requires output, which receives the
operation file. Pass that same path as operationFile to video_status to
check the job. Set download: true to save completed videos, and pass output
to choose where they are written.
Documentation search
The ai-cli.dev site serves a separate MCP endpoint at https://ai-cli.dev/api/mcp. Its only tool, search_docs, searches these docs. It doesn't run ai commands, so use ai mcp when an agent needs to generate or decide.