# AnyRouter MCP with OpenCode

> Add the AnyRouter MCP server to OpenCode with a project or global opencode.json.


# Connect AnyRouter to OpenCode

This is the **tools** connection (catalog, credits, keys). To route OpenCode's inference through AnyRouter, use the [OpenCode guide](/guides/opencode); the two blocks can live in the same file.

1. Add the server to `./opencode.json` (project) or `~/.config/opencode/opencode.json` (global):

   ```json
   {
     "$schema": "https://opencode.ai/config.json",
     "mcp": {
       "anyrouter": {
         "type": "remote",
         "url": "https://anyrouter.dev/api/v1/mcp",
         "enabled": true
       }
     }
   }
   ```

   ![Project-local opencode.json with the AnyRouter remote MCP server](/img/docs/mcp/opencode-json.png)

2. Restart OpenCode. On the next tool call, approve `anyrouter.dev/oauth/consent` (Read-only is the default).
3. Check it: ask "how many AnyRouter credits do I have left?". The agent calls `get_credits`.

`anyr opencode` connects the gateway for you when **Auto-connect in coding agents** is on in the [dashboard](https://anyrouter.dev/dashboard/mcp). Turn it off with `--no-mcp`, `anyr mcp auto off`, or the dashboard.

## Revoke

Set `"enabled": false` or delete the entry, and revoke the token in the [MCP dashboard](https://anyrouter.dev/dashboard/mcp). Later tool calls return `401 Unauthorized` until you reconnect.


## Related

- [OpenCode with AnyRouter — free models, one API key](/docs/guides/opencode.md)
- [anyr opencode](/docs/cli/opencode.md)
- [AnyRouter MCP with Claude Desktop](/docs/mcp/claude-desktop.md)
- [AnyRouter MCP with Claude Code](/docs/mcp/claude-code.md)
- [AnyRouter MCP with Cursor](/docs/mcp/cursor.md)
- [AnyRouter MCP with other clients](/docs/mcp/other-clients.md)
