> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.getunleash.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.getunleash.io/_mcp/server.

# Integrate Unleash with OpenCode

> Configure the Unleash MCP server to automate feature flag management in OpenCode's model-neutral AI coding agent.

The [Unleash MCP server](/integrate/mcp) connects OpenCode to your Unleash instance, enabling AI-assisted feature flag management.
This page covers how to install and configure the server in OpenCode. To learn what the server can do, see [Unleash MCP server](/integrate/mcp).

OpenCode supports MCP across three interfaces:

* **OpenCode TUI** — The primary terminal-based interface
* **OpenCode CLI** — Non-interactive mode via `opencode run` for scripts and CI/CD
* **Desktop app** — GUI alternative available for macOS, Windows, and Linux

OpenCode is model-neutral, supporting 75+ LLM providers through [Models.dev](https://models.dev), including Anthropic (Claude), OpenAI (GPT), Google (Gemini), xAI (Grok), and local models via Ollama.

## Prerequisites

Before you begin, make sure you have the following:

* Node.js 24 or later: The MCP server is distributed as an npm package
* OpenCode: [TUI, CLI, or desktop app](https://opencode.ai) installed
* An Unleash instance: Cloud or self-hosted, with API access enabled
* A [personal access token](/concepts/api-tokens-and-client-keys#personal-access-tokens) (PAT): With permissions to create and manage feature flags

## Install the MCP server

The Unleash MCP server runs as a local stdio process. The same configuration works across all OpenCode interfaces (TUI, CLI, and desktop app).

#### Create a credentials file

Store your Unleash credentials in a centralized file and source it from your shell profile:

```bash
mkdir -p ~/.unleash
cat > ~/.unleash/mcp.env << 'EOF'
UNLEASH_BASE_URL=https://your-instance.getunleash.io
UNLEASH_PAT=your-personal-access-token
EOF
chmod 600 ~/.unleash/mcp.env
```

Add to your `~/.zshrc` or `~/.bashrc`:

```bash
# Unleash MCP credentials
if [ -f ~/.unleash/mcp.env ]; then
  source ~/.unleash/mcp.env
  export UNLEASH_BASE_URL UNLEASH_PAT
fi
```

Restart your terminal or run `source ~/.zshrc` to load the variables.

To opt in to [feedback reports](/integrate/mcp#send-feedback), also add `UNLEASH_MCP_SEND_FEEDBACK=true` to `~/.unleash/mcp.env`, export it from your shell profile, and reference it in `opencode.json` as `"UNLEASH_MCP_SEND_FEEDBACK": "{env:UNLEASH_MCP_SEND_FEEDBACK}"`.

| Variable                    | Description                                                                                                                                    | Required |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| `UNLEASH_BASE_URL`          | Your Unleash instance URL.                                                                                                                     | Yes      |
| `UNLEASH_PAT`               | A personal access token with flag creation permissions.                                                                                        | Yes      |
| `UNLEASH_MCP_SEND_FEEDBACK` | Set to `true` to opt in to [feedback reports](/integrate/mcp#send-feedback). With `false`, the assistant doesn't see the `send_feedback` tool. | No       |

#### Create the configuration file

Create `opencode.json` at your project root:

**`opencode.json`**

```json title="opencode.json"
{
  "mcp": {
    "unleash": {
      "type": "local",
      "command": ["npx", "-y", "@unleash/mcp@latest"],
      "environment": {
        "UNLEASH_BASE_URL": "{env:UNLEASH_BASE_URL}",
        "UNLEASH_PAT": "{env:UNLEASH_PAT}"
      }
    }
  }
}
```

This file contains no credentials, only variable references that expand at runtime. You can safely commit it to version control.

#### Verify the installation

Run the MCP list command to confirm the server is connected:

```bash
opencode mcp list
```

The output should show `unleash: connected`.

Within an agent session, ask: "What Unleash MCP tools are available?" The agent lists all available tools.

**Tool namespacing:** OpenCode prefixes MCP tool names with the server name.
The Unleash tools appear as `unleash_search`, `unleash_release`, `unleash_inspect`, and so on.

**Configuration scopes:**

| Location                           | Scope   | Use case                              |
| ---------------------------------- | ------- | ------------------------------------- |
| `opencode.json` (project root)     | Project | Team-shared, version controlled       |
| `~/.config/opencode/opencode.json` | Global  | Personal settings across all projects |

Both are merged; project takes precedence on conflict. For team collaboration, use the project-level file.

> **Tip**
>
> OpenCode also supports `{file:path}` substitution as an alternative to `{env:VAR}`.
> Create individual credential files (e.g., `~/.unleash/pat`) containing only the value, then reference them with `"UNLEASH_PAT": "{file:~/.unleash/pat}"`.
> This is useful when credentials are managed by a secrets tool that writes individual files.

## Tools and workflows

Once the server is connected, OpenCode can use every tool the Unleash MCP server exposes. To learn what the server can do and see step-by-step [workflows](/integrate/mcp#workflows), read [Unleash MCP server](/integrate/mcp). For the current list of tools, see the [README on GitHub](https://github.com/Unleash/unleash-mcp#tools).

### Feedback reports

To opt in to [feedback reports](/integrate/mcp#send-feedback), set `UNLEASH_MCP_SEND_FEEDBACK` to `"true"` in the `environment` block of `opencode.json`. OpenCode doesn't show consent prompts, so feedback reports stay off until you set the variable. To learn more, see [Clients without a consent prompt](/integrate/mcp#clients-without-a-consent-prompt).

To hide the `send_feedback` tool from the assistant, set the variable to `"false"`. To learn what a report contains, see [What is recorded](/integrate/mcp#what-is-recorded).

## Enterprise governance

OpenCode Enterprise provides controls relevant to MCP server deployment in organizations.

* **SSO integration** — Central config integrates with your organization's SSO provider. Enables credential access for internal AI gateways through existing identity systems. No separate OpenCode accounts needed.
* **Private AI gateway** — Restrict all AI provider access to internal infrastructure. Disable all external providers to ensure requests route through approved channels. Combined with the Unleash MCP server (which connects to your own Unleash instance), the entire stack operates within your network.
* **Managed configuration** — Non-overridable policies deployed via MDM on macOS (`.mobileconfig` profiles), `/etc/opencode/` on Linux, and `%ProgramData%\opencode` on Windows. Managed config has the highest precedence in the configuration hierarchy, so individual developers cannot override these settings.
* **Agent permission restrictions** — Enforce agent permission policies via managed config, such as requiring approval for every file change regardless of the developer's local configuration.
* **Disabled providers list** — Restrict which LLM providers are available to developers. Useful for organizations that need to route all AI traffic through approved gateways.

For MCP server governance, commit `opencode.json` to version control. This ensures all team members use the same MCP servers with the same permission policies.

> **Tip**
>
> Use custom agents with `"ask"` permissions for write operations like `release`, `kill_switch`, and `manage_flag`. Read-only operations like `search`, `inspect`, and `evaluate` can safely use `"allow"`.

## Troubleshooting

#### MCP server not appearing in OpenCode

* Verify `opencode.json` for syntax errors
* Check that the `mcp` key is at the top level of the JSON object
* Confirm the `command` field is an array of strings, not a single string
* Run `opencode mcp list` to check server status
* Restart OpenCode after making changes

#### Environment variables not expanding

* OpenCode uses `{env:VAR}` syntax (curly braces, no dollar sign prefix)
* Restart your terminal after modifying your shell profile
* Verify variables are exported: `echo $UNLEASH_BASE_URL`
* Check that your shell profile sources `~/.unleash/mcp.env` and exports the variables

#### Authentication failed

* Confirm your Unleash PAT is valid and has not expired
* Check that the PAT has permissions to create and manage feature flags
* Verify that `UNLEASH_BASE_URL` does not include `/api` at the end
* Test directly: `curl -H "Authorization: $UNLEASH_PAT" "$UNLEASH_BASE_URL/api/admin/projects"`

#### No envFile support

OpenCode does not support `envFile` like Cursor or VS Code. Use `{env:VAR}` substitution in the `environment` object and source credentials from your shell profile. Alternatively, use `{file:path}` substitution to read credentials from individual files. If you are migrating from Cursor, replace `envFile` references with `{env:VAR}` entries.

#### Command format errors

OpenCode's MCP `command` field takes an array (`["npx", "-y", "@unleash/mcp@latest"]`), not a string with separate `args` like Cursor or Claude Code. This is a common migration mistake. Each argument must be a separate element in the array.

#### Node.js not found

Local servers using npx require Node.js 24+. Verify with `node --version`. If Node.js is installed but not found by OpenCode, check that OpenCode inherits your shell PATH.

#### Tool approval prompts

By default, agents with `"ask"` permissions request approval before executing MCP tools. Configure permissions in agent definitions or use managed config to set organization-wide defaults. The five built-in agents have their own permission presets (Build has full access, Plan and Explore are read-only).

#### Variable substitution confusion

OpenCode uses `{env:VAR}` (curly braces, no dollar sign). Claude Code uses `${VAR}`. Cursor uses `${env:VAR}`. Mixing formats between tools is a common error when teams use multiple AI assistants. Check that your `opencode.json` uses the correct syntax.

#### MCP context overhead

If you have many MCP servers configured, their tool descriptions may exceed the model's context window. Use `"enabled": false` to disable servers you don't need for the current project. Consider the context impact when adding multiple MCP servers.

#### Feedback is disabled

`send_feedback` returns this message until you opt in, because OpenCode doesn't show consent prompts. To opt in, set `UNLEASH_MCP_SEND_FEEDBACK` to `"true"` in the `environment` block of `opencode.json` and restart OpenCode. Feedback settings don't affect flag operations.

## Related resources

* [Unleash MCP server on GitHub](https://github.com/Unleash/unleash-mcp)
* [OpenCode homepage](https://opencode.ai)
* [OpenCode documentation](https://opencode.ai/docs)
* [OpenCode MCP configuration](https://opencode.ai/docs/mcp-servers)
* [OpenCode agents documentation](https://opencode.ai/docs/agents)
* [Impact Metrics](/concepts/impact-metrics)
* [Unleash architecture overview](/get-started/unleash-overview)