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 run for scripts and CI/CDOpenCode 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.
Before you begin, make sure you have the following:
The Unleash MCP server runs as a local stdio process. The same configuration works across all OpenCode interfaces (TUI, CLI, and desktop app).
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.
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 |
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.
Use this workflow when implementing a change that might affect production stability, such as a payment integration, authentication flow, or external API call.
Tell the agent what you are working on:
The agent calls evaluate_change and returns a recommendation with a suggested flag name.
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.
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.
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.
Use this workflow to enable a flag in staging for testing while keeping it disabled in production.
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.
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:
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.
Use this workflow to take inventory of existing flags before creating new ones, or to run a periodic audit for cleanup candidates.
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.
The agent calls list_flags with the target projectId. The default response returns active (non-archived) flags only.
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.
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.
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.
This file loads into every agent session. Use it for organization-wide flag standards.
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 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/.
A primary agent with a custom prompt that always evaluates changes for feature flags. Edit operations require approval; destructive bash commands are blocked.
A read-only subagent that evaluates code changes for feature flag compliance without creating or modifying anything.
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.
Usage: /evaluate-flag Stripe payment integration in the checkout service
Commit the .opencode/ directory to version control so the entire team shares the same agents, skills, and commands:
The following prompt patterns help you use the MCP tools effectively.
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.
Intent: Avoid duplicate flags when similar functionality exists.
Prompt:
Expected behavior: The agent calls detect_flag and presents matches with confidence levels.
Intent: Enable, disable, or query a flag in a specific environment.
Prompts:
Expected behavior: The agent calls toggle_flag_environment or get_flag_state.
Intent: Safely remove flagged code and delete unused flags.
Prompts:
Expected behavior: The agent calls cleanup_flag and provides removal instructions.
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.
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.
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.
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.
OpenCode Enterprise provides controls relevant to MCP server deployment in organizations.
.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."edit": "ask" ensures every file change requires approval, regardless of the developer’s local configuration.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".
opencode.json for syntax errorsmcp key is at the top level of the JSON objectcommand field is an array of strings, not a single stringopencode mcp list to check server status{env:VAR} syntax (curly braces, no dollar sign prefix)echo $UNLEASH_BASE_URL~/.unleash/mcp.env and exports the variablesUNLEASH_BASE_URL does not include /api at the endcurl -H "Authorization: $UNLEASH_PAT" "$UNLEASH_BASE_URL/api/admin/projects"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.
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.
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.
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).
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.
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.
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.