Integrate Unleash with OpenCode
The Unleash MCP server connects OpenCode to your Unleash instance, enabling AI-assisted feature flag management. You can evaluate code changes, create flags, generate wrapping code, manage rollouts, and clean up flags from within OpenCode’s terminal-first development environment.
OpenCode supports MCP across three interfaces:
- OpenCode TUI — The primary terminal-based interface with custom agents, skills, and commands
- OpenCode CLI — Non-interactive mode via
opencode runfor 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, including Anthropic (Claude), OpenAI (GPT), Google (Gemini), xAI (Grok), and local models via Ollama. When developers can switch providers between sessions, governance cannot live in the model. It must live in the tools. Custom agents with fine-grained permission controls are the primary governance mechanism, ensuring consistent FeatureOps behavior regardless of which model writes the code.
Prerequisites
Before you begin, make sure you have the following:
- Node.js 18 or later: The MCP server is distributed as an npm package
- OpenCode: TUI, CLI, or desktop app installed
- An Unleash instance: Cloud or self-hosted, with API access enabled
- A personal access token (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:
Add to your ~/.zshrc or ~/.bashrc:
Restart your terminal or run source ~/.zshrc to load the variables.
Tool namespacing: OpenCode prefixes MCP tool names with the server name.
The Unleash tools appear as unleash_evaluate_change, unleash_create_flag, unleash_get_flag_state, and so on.
Configuration scopes:
Both are merged; project takes precedence on conflict. For team collaboration, use the project-level file.
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.
Tool reference
The Unleash MCP server exposes several tools. The following table summarizes each tool and when to use it.
| Tool | Description | When to use |
|---|---|---|
evaluate_change | Analyzes a code change and determines whether it should be behind a feature flag. | Before implementing risky changes |
detect_flag | Searches for existing flags that match a description to prevent duplicates. | Before creating new flags |
create_flag | Creates a new feature flag with proper naming, typing, and metadata. | When no suitable flag exists |
wrap_change | Generates framework-specific code to guard a feature behind a flag. | After creating a flag |
list_projects | Lists Unleash projects available to the configured token, with optional pagination. | Discovering available projects |
list_flags | Lists feature flags in a project (active by default; set archived=true for archived flags). | Auditing flag inventory; discovering existing flags before creating new ones |
get_flag_state | Returns the current state, strategies, and metadata for a flag. | Debugging, status checks |
set_flag_rollout | Configures rollout percentages and activation strategies. | Gradual releases |
toggle_flag_environment | Enables or disables a flag in a specific environment. | Testing, staged rollouts |
remove_flag_strategy | Deletes a rollout strategy from a flag. | Simplifying flag configuration |
cleanup_flag | Returns file locations and instructions for removing a flag after rollout. | After full rollout |
Workflows
The Unleash MCP server supports these core workflows: evaluate and wrap code in feature flags, discover and audit flags, manage rollouts across environments, and clean up after rollout. OpenCode adds a fifth workflow unique to its architecture: agent-guided flag evaluation.
Evaluate and wrap code in feature flags
Use this workflow when implementing a change that might affect production stability, such as a payment integration, authentication flow, or external API call.
Evaluate the change
Tell the agent what you are working on:
The agent calls evaluate_change and returns a recommendation with a suggested flag name.
Check for duplicates
The agent automatically calls detect_flag to search for existing flags.
If a suitable flag exists, the agent suggests reusing it instead of creating a duplicate.
Agent-guided flag evaluation
Use this workflow to automate flag evaluation using a custom FeatureOps agent with permission controls. The agent evaluates risk without the developer explicitly asking, and its behavior is identical regardless of which model is selected.
Define a FeatureOps agent
Create a custom agent with a system prompt encoding your team’s policies (see custom agent definitions below for a complete example).
The agent’s prompt instructs it to always call evaluate_change before writing implementation code.
Agent-guided evaluation catches risk during implementation rather than during code review. The flag becomes part of the development flow, not an afterthought. Because agents are model-independent, the same governance applies whether the developer uses Claude, GPT, Gemini, or a local model.
Manage rollouts across environments
Use this workflow to enable a flag in staging for testing while keeping it disabled in production.
Check flag state
Enable in staging
Configure rollout
The agent calls get_flag_state and returns the flag metadata, enabled environments, and active strategies.
AI assistants can make mistakes and toggle the wrong flag. Enable change requests on production environments to require human approval before changes take effect. See the MCP server documentation for details.
Clean up after rollout
Use this workflow when a feature has been fully rolled out and the flag is no longer needed.
The agent calls cleanup_flag and returns:
- All files and line numbers where the flag is used
- Which code path to preserve (the “enabled” branch)
- Suggestions for tests to run after removal
Review the list, remove the conditional branches, and delete the flag from Unleash.
Feature flags should be temporary. Regularly clean up flags after successful rollouts to prevent technical debt.
Discover and audit flags
Use this workflow to take inventory of existing flags before creating new ones, or to run a periodic audit for cleanup candidates.
List available projects (optional)
If you don’t already know the target project, the agent calls list_projects to enumerate projects the configured token can access. Skip this step if UNLEASH_DEFAULT_PROJECT is set.
List active flags
The agent calls list_flags with the target projectId. The default response returns active (non-archived) flags only.
List archived flags
For a full audit, the agent calls list_flags a second time with archived=true. Active and archived flags are disjoint result sets in Unleash; both calls are needed for complete inventory.
Cross-reference with the codebase
The agent compares the returned flags against references in your code. Flags present in Unleash but unused in code (especially archived ones) are cleanup candidates — chain into the Clean up after rollout workflow to remove them safely.
AGENTS.md templates
OpenCode uses AGENTS.md files for project-level instructions, similar to Cursor Rules or Claude Code’s CLAUDE.md. Store your FeatureOps policies in AGENTS.md so the agent considers feature flags automatically in every session.
For more details on project instructions, see the OpenCode rules documentation.
Standard AGENTS.md with FeatureOps policies
This file loads into every agent session. Use it for organization-wide flag standards.
Domain-specific instructions via opencode.json
Create additional instruction files for high-risk domains and load them via the instructions field in opencode.json.
This field supports glob patterns and remote URLs.
Custom agent definitions
Custom agents are OpenCode’s primary governance mechanism. Each agent has a mode, a system prompt, and fine-grained permission controls that gate what the agent can do.
Permissions support three levels per tool: ask (prompt for approval), allow (execute without prompting), and deny (block entirely).
For more details on agents, see the OpenCode agents documentation.
Agents can be defined in two formats: JSON in opencode.json or as markdown files in .opencode/agents/.
FeatureOps agent
A primary agent with a custom prompt that always evaluates changes for feature flags. Edit operations require approval; destructive bash commands are blocked.
JSON format
Markdown format
Flag reviewer agent
A read-only subagent that evaluates code changes for feature flag compliance without creating or modifying anything.
Skill and command definitions
Skills and commands package reusable workflows and common operations.
Skills define multi-step processes that agents invoke automatically.
Commands define prompt templates that developers invoke with /command-name in the TUI.
evaluate-and-flag skill
cleanup-flag skill
evaluate-flag command
Usage: /evaluate-flag Stripe payment integration in the checkout service
Team distribution
Commit the .opencode/ directory to version control so the entire team shares the same agents, skills, and commands:
Prompt patterns
The following prompt patterns help you use the MCP tools effectively.
Evaluate and create a flag
Intent: Determine if a change requires a feature flag, then create and wrap it.
Prompt:
Expected behavior: The agent calls evaluate_change, then detect_flag, create_flag, and wrap_change as needed.
Detect and reuse existing flags
Intent: Avoid duplicate flags when similar functionality exists.
Prompt:
Expected behavior: The agent calls detect_flag and presents matches with confidence levels.
Toggle or check flag state
Intent: Enable, disable, or query a flag in a specific environment.
Prompts:
Expected behavior: The agent calls toggle_flag_environment or get_flag_state.
Clean up a flag
Intent: Safely remove flagged code and delete unused flags.
Prompts:
Expected behavior: The agent calls cleanup_flag and provides removal instructions.
Discover and audit flags
Intent: Take inventory of existing flags and identify cleanup candidates.
Prompts:
Expected behavior: The agent calls list_projects (if no project is specified), then list_flags for active and archived flags. It cross-references results against code and reports cleanup candidates.
Agent-guided evaluation (FeatureOps agent)
Intent: Automatically evaluate code changes based on encoded policies using a custom agent.
Trigger: Switch to the FeatureOps agent via Tab key or start with --agent featureops.
Expected behavior: The agent’s system prompt instructs it to call evaluate_change whenever the developer describes a code change. If a flag is needed, the agent notifies you and offers to create it. Permission controls gate flag creation with "ask", so you approve before the flag is created. This works identically across all LLM providers.
Skill-orchestrated workflow
Intent: Run a multi-step FeatureOps workflow using a skill.
Trigger: The agent discovers the evaluate-and-flag skill automatically when the context is relevant, or you ask for it directly.
Expected behavior: The skill orchestrates the full workflow: evaluate the current changes, check for duplicates, create the flag if needed, wrap the code, and suggest a rollout strategy. Each step calls the appropriate MCP tool.
CLI-based evaluation
Intent: Evaluate and flag changes from the terminal without the interactive TUI.
Prompts:
Expected behavior: The CLI agent uses the same MCP tools as the TUI. In non-interactive mode, the agent outputs results and exits. The attach pattern avoids cold-booting MCP servers for each invocation.
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 (
.mobileconfigprofiles),/etc/opencode/on Linux, and%ProgramData%\opencodeon Windows. Managed config has the highest precedence in the configuration hierarchy, so individual developers cannot override these settings. - Agent permission restrictions — Enforce FeatureOps agent definitions and permission policies via managed config. A managed FeatureOps agent with
"edit": "ask"ensures every file change requires approval, 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 and the .opencode/ directory to version control. This ensures all team members use the same MCP servers, agents, and skills with the same permission policies.
Use custom agents with "ask" permissions for write operations like create_flag and toggle_flag_environment. Read-only operations like get_flag_state, detect_flag, and evaluate_change can safely use "allow".
Troubleshooting
MCP server not appearing in OpenCode
- Verify
opencode.jsonfor syntax errors - Check that the
mcpkey is at the top level of the JSON object - Confirm the
commandfield is an array of strings, not a single string - Run
opencode mcp listto 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.envand 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_URLdoes not include/apiat 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 18+. 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.
Best practices
Follow these guidelines for effective feature flag management with OpenCode.
While the MCP server can automate flag creation, high-risk changes should involve human review. Use custom agents with "ask" permissions for flag creation, rollout plans, and cleanup decisions.
Establish organization-wide standards for flag names (e.g., domain-feature-variant) and types. Encode these in AGENTS.md and in custom agent prompts so the agent applies them automatically.
Always use detect_flag before creating new flags. This keeps naming consistent and reduces fragmentation across services.
Feature flags should be removed after successful rollouts. Use cleanup_flag regularly to prevent technical debt.
Configure MCP servers at project scope (opencode.json) and commit to version control along with .opencode/ definitions. All team members get the same configuration, agents, and skills.
Define a FeatureOps agent with permission controls that gate flag creation and enforce your team’s policies. Agents work the same regardless of which model the developer selects.