> For the complete documentation index, see [llms.txt](https://docs.cloud.olakrutrim.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cloud.olakrutrim.com/mcp/connect-opencode.md).

# Connect OpenCode

Connect OpenCode to Krutrim Cloud using local MCP tools and a private API key.

Connect OpenCode to Krutrim Cloud through a local MCP server. OpenCode launches the server and adds its Cloud tools alongside the tools already available to your agent.

This guide covers local stdio. For the hosted setup and supported client examples, start with [Hosted MCP](/mcp/hosted-mcp.md).

## Before you begin

* Install OpenCode and make sure `uvx` is available in the environment that launches it.
* Complete the package installation and API-key setup in [Local MCP (stdio)](/mcp/local-mcp-stdio.md) before using the local configuration below.
* Set `KRUTRIM_API_KEY` privately in the environment used to start OpenCode. Use the raw API key, without a `Bearer` prefix or surrounding spaces.

## Connect with local stdio

{% stepper %}
{% step %}

### Open the OpenCode configuration

Open `~/.config/opencode/opencode.json` for a global user configuration. OpenCode also supports JSONC. Merge the example with existing settings; do not overwrite your other MCP servers.

OpenCode merges configuration from multiple locations. Project or managed settings can override a value, so check the effective scope if this server is configured elsewhere.
{% endstep %}

{% step %}

### Add the local MCP server

```json
{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "krutrim-cloud": {
      "type": "local",
      "command": [
        "uvx",
        "krutrim-mcp-server"
      ],
      "enabled": true,
      "environment": {
        "KRUTRIM_API_KEY": "{env:KRUTRIM_API_KEY}"
      }
    }
  }
}
```

OpenCode uses `mcp`, a `command` array, and `environment`—not the `mcpServers` / `env` shape used by some other clients.

> The `{env:KRUTRIM_API_KEY}` reference reads the key from OpenCode’s launch environment. If the variable is unset, it becomes an empty string. Keep the real key out of repository configuration and restart OpenCode after key changes.
> {% endstep %}

{% step %}

### Start OpenCode and check the server

From the environment where the private key is configured, check server status and then start a fresh session:

```bash
opencode mcp list
opencode
```

This local stdio setup does not use `opencode mcp auth`; that command is for remote OAuth servers.
{% endstep %}

{% step %}

### Verify with a read-only request

```
Use krutrim-cloud to list my VPCs in In-Bangalore-1.
```

Review the proposed read-only Cloud tool call and region. Server discovery is a local check; a successful Cloud request verifies API-key access and permissions.
{% endstep %}
{% endstepper %}

## Next steps

Before changing Cloud resources, follow the safety guidance in the [MCP Overview](/mcp/overview.md). Start with a read-only request and review the exact region and resource identifiers.

Need help? Open [Troubleshooting](/mcp/troubleshooting.md) for startup, API-key, and tool-discovery checks.

## Official references

[OpenCode: MCP servers](https://opencode.ai/docs/mcp-servers/)

[OpenCode configuration and environment substitution](https://opencode.ai/docs/config/)
