Skip to content

AnyRouter MCP with OpenCode

Add the AnyRouter MCP server to OpenCode via a project-local or global opencode.json.

OpenCode registers MCP servers from opencode.json — scope it to one project, or make AnyRouter available globally. This is the tools connection (catalog, credits, keys). To route OpenCode's inference through AnyRouter, use the OpenCode guide instead.

  1. Add the AnyRouter server to ./opencode.json at the repo root:

    {
      "$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

    Key fields:

    • type: "remote" — AnyRouter is a remote HTTP MCP server, not a stdio child.
    • url — the endpoint, identical for every client.
    • enabled: true — flip to false to keep the entry but disable it.
  2. Restart OpenCode. The next tool call opens anyrouter.dev/oauth/consent — pick a permission level (Read-only is the default and safest) and click Allow.

  1. Add the same server block to ~/.config/opencode/opencode.json so AnyRouter is available across every project:

    {
      "$schema": "https://opencode.ai/config.json",
      "mcp": {
        "anyrouter": {
          "type": "remote",
          "url": "https://anyrouter.dev/api/v1/mcp",
          "enabled": true
        }
      }
    }
    
  2. Restart OpenCode. The next tool call opens anyrouter.dev/oauth/consent — pick a permission level and click Allow.

You can keep the MCP block next to an AnyRouter provider block in the same file — inference and tools are independent. See the OpenCode guide for the provider.

Verify

In any OpenCode chat, ask "how many AnyRouter credits do I have left?". The agent calls get_credits and reports the balance. "What AnyRouter models support tools?" calls list_models.

Revoke

  • OpenCode side — set "enabled": false in opencode.json, or delete the entry entirely.
  • AnyRouter side — revoke the OAuth token from the MCP dashboard. Subsequent tool calls return 401 Unauthorized until you reconnect.

Related