Building a Production-Ready MCP Server for AI Agents to Manage Feature Flags
devcycle · Tech · 2025 · source Agentic: yes · promotional bias: med · source-backed · extracted with prompt 0.5.4 (schema v2)
Generated from extraction.json — do not edit by hand. Every claim cites verbatim source evidence; stated means the quote directly asserts the claim, implied means it supports it indirectly.
Problem
Domain: MCP server for feature-flag management inside AI coding workflows
DevCycle needed to turn a compelling but unreliable hackathon MCP demo into a production-ready remote MCP server that lets AI coding agents create, inspect, promote, target, and clean up feature flags without leaving the developer's coding workflow.
Constraints:
- The hackathon version failed regularly
- AI agents used wrong tools when schemas lacked enough context
- Bad error handling caused hallucinated fixes and circular recovery attempts
- Too many MCP tools consumed context and increased wrong-tool risk
- Authentication for a new MCP standard needed to integrate with existing systems
- Local MCP installation patterns raised filesystem and permission risks
Architecture
DevCycle adapted its existing CLI/API surface into a production MCP server with carefully described input schemas, descriptive structured error responses, pruned and higher-level tool calls, OAuth hosted through Cloudflare Workers, Durable Objects for per-user session/project state, and a remote HTTP/SSE architecture. The result lets AI coding agents manage feature flags as part of everyday editor prompts while staying scoped by permissions and preserving developer flow.
Diagram confidence: reconstructed (reconstructed from prose).
flowchart LR developer-ide[Developer IDE] --> ai-coding-agent[AI Coding Agent] ai-coding-agent --> devcycle-mcp-server[DevCycle MCP Server] devcycle-mcp-server --> input-schema-layer[Input Schema Layer] devcycle-mcp-server --> tool-catalog[Tool Catalog] devcycle-mcp-server --> cloudflare-workers-host[Cloudflare Workers Host] cloudflare-workers-host --> oauth-flow[OAuth Flow] cloudflare-workers-host --> durable-object-session-store[Durable Object Session Store] durable-object-session-store --> devcycle-feature-api[DevCycle Feature API] devcycle-mcp-server --> devcycle-feature-api devcycle-feature-api --> error-response-layer[Error Response Layer] error-response-layer --> devcycle-mcp-server
Components
| Component | Role | Interacts with |
|---|---|---|
AI Coding Agent |
Claude or other coding assistant that calls MCP tools from the developer workflow. | Developer IDE, DevCycle MCP Server |
Developer IDE |
Coding environment where developers ask natural-language prompts and remain in flow. | AI Coding Agent |
DevCycle MCP Server |
Remote MCP interface exposing selected feature-flag workflows to AI agents. | AI Coding Agent, Input Schema Layer, Tool Catalog, Cloudflare Workers Host, DevCycle Feature API |
Input Schema Layer |
Zod-style schema descriptions that guide tool selection and argument construction. | DevCycle MCP Server |
Error Response Layer |
Structured descriptive API errors that help agents self-correct. | DevCycle MCP Server, DevCycle Feature API |
Tool Catalog |
Pruned set of higher-level MCP tools for feature-flag workflows. | DevCycle MCP Server |
Cloudflare Workers Host |
Remote MCP hosting layer that makes OAuth and remote installation easier. | DevCycle MCP Server, OAuth Flow, Durable Object Session Store |
OAuth Flow |
Web-standard authentication and permission scoping for remote MCP access. | Cloudflare Workers Host |
Durable Object Session Store |
Per-user session state including selected DevCycle project for subsequent tool calls. | Cloudflare Workers Host, DevCycle Feature API |
DevCycle Feature API |
Underlying API for creating, targeting, promoting, archiving, and listing feature flags. | DevCycle MCP Server, Error Response Layer, Durable Object Session Store |
Data flow
A developer asks an AI agent to perform a feature-flag workflow in the editor. The agent chooses a DevCycle MCP tool using schema descriptions, calls the remote MCP server, authenticates through OAuth, uses Durable Object session state to know the selected DevCycle project, invokes DevCycle feature-flag APIs, receives descriptive errors when API rules are violated, and self-corrects or completes the feature-flag action.
4 supporting quotes
Why this architecture
DevCycle optimized for production agent behavior rather than maximum API exposure. Schemas and errors became part of the agent's reasoning context, pruning reduced context-window pressure, higher-level tools simplified workflows, and remote OAuth-scoped hosting avoided the security pitfalls of local MCP servers with broad filesystem access.
4 supporting quotes
Models used: AI coding agents · Claude
Scale
- DevCycle's starting point was a hackathon prototype adapted from an existing CLI.“When we started building our MCP server, it began as a simple hackathon project: take our existing CLI interface, which already has authentication and most of our API calls, and adapt it to work as an MCP server.”article, stated
- DevCycle had over a decade of SDK-based SaaS experience informing the MCP onboarding flow.“As a team that has built SDK-based SaaS services for over a decade, this approach addresses two persistent challenges: getting customers to install and update SDKs and streamlining the onboarding process.”article, stated
- The MCP tooling supports routine development flows such as creating flags, self-targeting, promoting to staging, and enabling production for internal users.“create a new variable and feature for you in DevCycle, and self-target you into that flag to initially test it locally.”article, stated
Alternatives considered (roads not taken)
Expose the full API surface as MCP tools
Rejected because: Every tool consumes context, raises wrong-tool risk, and some destructive project-level actions are unlikely to be appropriate for agents.
Rely on traditional terse API errors
Rejected because: Agents hallucinated fixes and looped when errors were not descriptive.
Use local npx-installed MCP servers
Rejected because: Local install patterns can grant broad filesystem access, while remote OAuth scopes permissions and time-limited tokens.
npx -y some-mcp-script to install a local MCP server with full access to your computer's file system is rife with security concerns”article, statednpx -y some-mcp-script to install a local MCP server with full access to your computer's file system is rife with security concerns, compared to an HTTP / SSE-based remote MCP server, scoped using permissions and time-scoped OAuth tokens.”article, statedUse large output schemas for more tool context
Rejected because: The token cost was likely not worth the benefit compared with concise tool descriptions.
Patterns
tool-use-orchestration (mcp-integration)
The MCP server lets coding agents create, target, promote, inspect, and clean up DevCycle feature flags from editor prompts.
structured-output-contract (agent-interface)
Input schemas and descriptions encode the tool-call contract the agent uses to select tools and arguments.
.describe() statements on your schema parameters will help push the AI agent in the right direction.”article, statedfallback-degradation (agent-recovery)
Detailed API errors act as feedback that lets agents recover from invalid requests instead of hallucinating fixes.
context-compaction (tool-surface-management)
DevCycle pruned tool calls and combined API functions into larger workflow tools to reduce MCP context usage.
safety-policy-enforcement (remote-mcp-security)
The production MCP uses remote OAuth-scoped access instead of local filesystem-wide MCP installs.
agent-memory (session-state)
Durable Objects store the selected DevCycle project so later tool calls do not force the agent to remember it.
Tradeoffs
Host MCP remotely
Chose HTTP/SSE remote MCP with OAuth over local npx MCP server installs.
Rationale: Remote hosting is easier to install and scopes permissions better than local filesystem-accessing servers.
Prune and combine MCP tools
Chose fewer higher-level workflow tools over one MCP tool for every API function.
Rationale: Fewer, broader tools reduce context pressure and wrong-tool selection.
Use Cloudflare Workers and Durable Objects
Chose Cloudflare-hosted remote MCP with durable session state over custom auth/session implementation from scratch.
Rationale: Cloudflare made OAuth mostly painless and Durable Objects provided scalable per-user MCP session state.
Gotchas (what bit them)
A compelling MCP demo can still fail regularly.
Root cause: The hackathon build lacked production-grade schema, error, auth, tool-surface, and workflow hardening.
Resolution: DevCycle iterated through schema descriptions, structured errors, tool pruning, OAuth, durable session state, and remote hosting.
Weak schemas send agents down the wrong path.
Root cause: The schema is the agent's main context for tool selection and argument filling.
Resolution: DevCycle added explicit parameter descriptions to guide tool usage.
.describe() statements”article, statedBad errors trigger hallucinated recovery loops.
Root cause: Agents need concrete information about what failed and how to fix it.
Resolution: DevCycle returns detailed error type, message, tool name, suggestions, and timestamp.
Tool sprawl wastes agent context.
Root cause: Each exposed MCP tool needs description/context, and many agent platforms restrict or warn on too many tools.
Resolution: DevCycle minimized the exposed tool count and made higher-level tool calls.
Evaluation
DevCycle evaluated production readiness through trial-and-error hardening, agent success creating complex features, observed wrong-tool/error behavior, and workflow fit inside coding-agent prompts.
Metrics: feature creation success rate · wrong-tool attempts · agent self-correction after errors · MCP tool count · OAuth/session reliability · developer workflow adoption
3 supporting quotes
Outcomes
- DevCycle moved from a hackathon MCP prototype to a production-ready remote MCP server.
- Agents can create feature flags, investigate incidents, self-target, promote features, enable production targeting, and clean stale flags through natural language.
- Structured schemas and descriptive errors enabled high success on complex feature creation.
- Remote Cloudflare Workers hosting plus Durable Objects solved OAuth and session-state needs.
- The MCP kept developers in coding context rather than forcing dashboard switching.
The article reports a hackathon-to-production transition, support for multi-step feature-flag workflows, Durable Object session state across all user requests, and DevCycle's decade-plus SDK/SaaS experience; the ZenML summary additionally reports roughly 3x more users reaching SDK installation than the prior onboarding flow.