keepcalculator

06 Numbers and Powers

Managing Feature Flags from Claude Code and Cursor with MCP

Card No. 06·67935 · Updated · Standard formula, shown below

You can manage feature flags directly from Claude Code and Cursor by using the Model Context Protocol (MCP), which lets these AI coding tools connect to your feature flag service’s API and read, create, update, or toggle flags through natural language commands. This article explains how MCP-based feature flag management works, how to set it up, what to watch out for, and how it compares to other approaches.

Background: Why Feature Flags and AI Coding Tools Need a Bridge

Feature flags (also called feature toggles) let you turn parts of your application on or off without deploying new code. They are essential for gradual rollouts, A/B testing, and kill switches. However, managing them usually means switching from your editor to a separate dashboard or CLI, which breaks flow and slows down iteration.

Claude Code (Anthropic’s terminal-based coding agent) and Cursor (an AI-powered code editor) both support MCP, an open standard that lets AI assistants call external tools and services. By connecting these editors to a feature flag service via MCP, you can ask the AI to “enable flag X for 10% of users” or “create a new flag for the checkout redesign” without leaving your code context. This integration turns your AI coding tool into a control plane for your feature lifecycle.

How MCP Works for Feature Flag Management

MCP works by defining a set of tools (functions) that an AI model can invoke. For feature flags, the MCP server exposes operations like:

  • List flags – get all flags and their current states
  • Get flag – fetch details of a single flag
  • Create flag – add a new flag with a name, key, and default state
  • Update flag – change a flag’s description, tags, or targeting rules
  • Toggle flag – enable or disable a flag globally or for specific segments
  • Delete flag – remove a flag (often with safeguards)

When you type a request in Claude Code or Cursor, the AI decides which tool to call, passes the necessary parameters (like flag key and percentage), and the MCP server translates that into an API request to your feature flag provider. The response comes back to the AI, which then summarizes the result for you.

For example, you might say: “Turn on the new payment flow for internal users only.” The AI would call the MCP tool with the flag key and a targeting rule that matches your internal email domain. The server sends the update, and the AI confirms the change.

Setting Up an MCP Server for Your Feature Flag Service

Most major feature flag platforms (like LaunchDarkly, Flagsmith, Unleash, or Split) either provide an official MCP server or have a community-built one. If your provider doesn’t have one, you can build a custom MCP server that wraps their REST API. Here’s the general setup process:

  1. Install the MCP server package – usually via npm, pip, or a Docker container, depending on the provider.
  2. Configure authentication – you’ll need an API token or service account with the right permissions (read-only or read-write, depending on your needs).
  3. Add the server to Claude Code – in Claude Code, you add MCP servers via the configuration file (e.g., .mcp.json or the claude mcp add command).
  4. Add the server to Cursor – in Cursor, go to Settings → MCP, and add the server URL or command.
  5. Test the connection – ask the AI to list flags. If it returns data, you’re connected.

For a custom server, you’ll need to implement the MCP protocol (which uses JSON-RPC over stdio or HTTP) and map each tool to your provider’s API endpoints. The official MCP SDKs for Python and TypeScript make this straightforward.

Choosing Between MCP and Native Integrations

Before committing to MCP, consider whether your feature flag provider already has a native integration with Claude Code or Cursor. Some providers offer plugins or extensions that don’t require MCP. However, MCP has advantages:

  • Vendor-neutral – MCP works with any provider that exposes an API, so you can switch providers without changing your editor setup.
  • Flexible – you can combine multiple MCP servers (e.g., one for flags, one for databases) in the same session.
  • Standardized – MCP is an open standard, so the same server works across different AI tools.

Native integrations might offer deeper UI integration (like showing flag states inline in your code), but MCP is often sufficient and more portable.

Common Problems and How to Avoid Them

Working with MCP and feature flags isn’t always smooth. Here are frequent pitfalls:

  • Permission errors – your API token might not have write access. Use a token with least privilege, but remember that the AI can only do what the token allows.
  • Accidental toggles – a misphrased prompt could turn on a flag for all users. Always review the AI’s plan before it executes, or use a read-only token for exploration and switch to a write token only when needed.
  • Context limits – MCP responses can be large (especially listing hundreds of flags). Ask for specific flags or use filters to keep responses small.
  • Rate limits – feature flag APIs often have rate limits. If you’re making many calls, you might hit them. Batch operations or cache responses where possible.
  • State drift – if you change flags from the dashboard while the AI has a stale view, it might make outdated decisions. Always fetch fresh data before acting.

Safety and Best Practices for AI-Driven Flag Changes

Because AI can execute changes quickly, you need guardrails:

  • Use a staging environment first – test MCP operations against a staging flag environment before pointing at production.
  • Require confirmation for destructive actions – some MCP servers have a “dry-run” mode or require an explicit confirmation flag for deletions or global toggles.
  • Audit logs – ensure your feature flag provider logs who made changes and when. MCP actions should appear in the same audit trail as dashboard changes.
  • Set up approval workflows – if your provider supports it, require an approval step for production flag changes. This adds a human check before the AI’s change goes live.
  • Use short-lived tokens – rotate API tokens regularly and avoid committing them to your repository.

Alternatives to MCP for Feature Flag Management

If MCP isn’t right for you, there are other ways to manage flags from your coding environment:

  • CLI tools – most providers offer a command-line interface. You can run these from your terminal, and even have Claude Code or Cursor execute them via shell commands.
  • Editor extensions – some providers have VS Code extensions that show flag states inline and allow quick toggles from the editor.
  • API scripts – write small scripts that call the provider’s API, and invoke them from your AI tool via a custom tool or shell command.
  • Manual dashboard – the simplest fallback, but it breaks flow.

MCP is the most integrated approach, but it requires setup and trust. If you only need to toggle a flag occasionally, a CLI might be simpler.

Frequently Asked Questions

Is MCP secure for production flag changes?

MCP itself doesn’t add or remove security; it’s just a transport. The security depends on your API token permissions, network encryption (use HTTPS), and whether you have approval workflows in your flag service. For production, use a token with limited scope and require human approval for destructive actions.

Can I use MCP with any feature flag provider?

Yes, as long as the provider has an API and someone has built an MCP server for it (or you build one yourself). Most popular providers have official or community MCP servers. If not, you can write a simple wrapper around their REST API.

Will the AI accidentally turn on a flag for all users?

It can if you give it write access and your prompt is ambiguous. To prevent this, use a read-only token for most interactions, and switch to a write token only when you explicitly want to make a change. Also, ask the AI to show you the exact parameters before executing.

How do I debug MCP connection issues in Cursor or Claude Code?

Check the MCP server logs (usually in the terminal where you started it). Verify that the server URL or command is correct, and that your API token is valid. Most MCP servers have a test endpoint or a list command you can call manually to confirm connectivity.

Does MCP work with self-hosted feature flag services?

Yes, as long as the self-hosted service exposes an HTTP API. You can run the MCP server locally or on a server that can reach your self-hosted instance. This is common for companies that need to keep flag data on-premises.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →