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.

ai mcp
ai mcp --profile media
ai mcp --profile all

--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):

{
  "mcp": {
    "ai": {
      "type": "local",
      "command": ["ai", "mcp"],
      "environment": {
        "AI_GATEWAY_API_KEY": "your-vercel-ai-gateway-api-key",
        "AI_CLI_OUTPUT_DIR": "/absolute/output/dir"
      }
    }
  }
}

Other clients (mcpServers):

{
  "mcpServers": {
    "ai": {
      "command": "ai",
      "args": ["mcp"],
      "env": {
        "AI_GATEWAY_API_KEY": "your-vercel-ai-gateway-api-key",
        "AI_CLI_OUTPUT_DIR": "/absolute/output/dir"
      }
    }
  }
}

opencode (opencode.json):

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "ai": {
      "type": "local",
      "command": ["ai", "mcp"],
      "environment": {
        "AI_GATEWAY_API_KEY": "your-vercel-ai-gateway-api-key",
        "AI_CLI_OUTPUT_DIR": "/absolute/output/dir"
      },
      "timeout": 600000
    }
  }
}

Claude Code:

claude mcp add ai -e AI_GATEWAY_API_KEY=your-vercel-ai-gateway-api-key -e AI_CLI_OUTPUT_DIR=/absolute/output/dir -- ai mcp

Codex:

codex mcp add ai --env AI_GATEWAY_API_KEY=your-vercel-ai-gateway-api-key --env AI_CLI_OUTPUT_DIR=/absolute/output/dir -- ai mcp
VariablePurpose
AI_GATEWAY_API_KEYVercel AI Gateway API key. Required.
AI_CLI_OUTPUT_DIRAbsolute directory for generated files. Without it, files land in each call's cwd.
AI_GATEWAY_BASE_URL, AI_GATEWAY_TEAM_ID_OR_SLUGOptional 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

ToolProfileCLI command
textcoreai text
imagecoreai image
decidecoreai decide
modelscoreai models
video_startmediaai video start
video_statusmediaai video status
audio_speakmediaai audio speak
audio_transcribemediaai 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:

InputTypeDescription
cwdstringWorking directory for the run
extraArgsstring[]Extra CLI flags appended last
timeoutMsintegerTimeout 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.

{
  "questions": [
    {
      "id": "refund",
      "type": "boolean",
      "question": "Refund requested?"
    },
    {
      "id": "team",
      "type": "choice",
      "question": "Which team?",
      "choices": ["billing", "support"]
    },
    {
      "id": "tone",
      "type": "score",
      "question": "How positive?",
      "levels": ["angry", "neutral", "happy"]
    }
  ],
  "state": "Customer asks for a refund."
}

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.

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.