Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

OpenCode

OpenCode is an open-source AI coding tool with first-class espctl support.

Configuration

Add to opencode.json in your project folder, or ~/.config/opencode/opencode.json to make espctl available everywhere:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "espctl": {
      "type": "local",
      "command": ["/path/to/espctl", "mcp", "serve"],
      "enabled": true,
      "environment": {
        "CONTROL_BASE_URL": "https://esphome.cloud",
        "MCP_AUTH_SECRET": "your-access-key"
      }
    }
  }
}

Four things to notice compared to the JSON-based AI tools:

  1. The top-level key is mcp, not mcpServers.
  2. command is a single array with the program and all its arguments together, not a separate command + args.
  3. The environment-variable key is environment, not env.
  4. type must be "local" for a program launched on your computer (which espctl is).

The path/value rules are otherwise the same as in Claude Code.

Check it’s working

Restart OpenCode. In any chat:

What espctl tools can you call?

You should see the standard ~40-tool list. If not, OpenCode’s logs will show the actual error — usually under ~/.local/share/opencode/logs/ on Linux or ~/Library/Logs/opencode/ on macOS.

OpenCode-specific notes

  • OpenCode supports a per-server cwd field, at the same level as command:
    "espctl": {
      "type": "local",
      "command": ["/path/to/espctl", "mcp", "serve"],
      "cwd": "/path/to/your/esp-idf/project",
      "enabled": true,
      "environment": { ... }
    }
    
  • The enabled flag lets you keep espctl in your config but turn it off temporarily without deleting the entry.

Tip

Ask OpenCode:

Read the install://opencode resource.

…and espctl will return a copy-paste-ready config block.