Skip to content

featbit/featbit-mcp

Repository files navigation

FeatBit MCP Server

A Model Context Protocol (MCP) server that enables AI coding agents to interact with FeatBit feature flag management. Built with .NET 10, ASP.NET Core, and Aspire for modern cloud-native architecture.

🔌 Installation & Getting Started

The FeatBit MCP Server supports quick installation across multiple development environments. Choose your preferred client below:

Standard config works in most clients:

{
  "servers": {
    "featbit": {
      "type": "http",
      "url": "https://mcp.featbit.co/mcp"
    }
  }
}

VS Code

Install in VS Code or search "@mcp featbit" in Extensions, or manually add to .vscode/mcp.json:

{
  "servers": {
    "featbit": {
      "type": "http",
      "url": "https://mcp.featbit.co/mcp"
    }
  }
}

VS Code MCP Guide

Cursor

Add to Cursor MCP settings (~/.cursor/mcp.json on macOS/Linux or %APPDATA%\.cursor\mcp.json on Windows):

{
  "servers": {
    "featbit": {
      "url": "https://mcp.featbit.co/mcp"
    }
  }
}

Cursor MCP Guide

Claude Code

Run the following command:

claude mcp add --transport http featbit https://mcp.featbit.co/mcp

Claude Code MCP Guide

Codex

Run the following command:

codex mcp add "featbit" --url "https://mcp.featbit.co/mcp"

Codex MCP documentation

▶️ Getting Started

  1. Install the FeatBit MCP Server using one of the methods above
  2. You should see the FeatBit MCP Server in the list of available tools
  3. Try a prompt like:
    • "How do I integrate FeatBit .NET SDK in my ASP.NET Core project?"
    • "Show me how to deploy FeatBit to Kubernetes using Helm"
    • "What's the best way to use feature flags in React?"

That's it! Your AI assistant will now have access to FeatBit documentation and integration guides.


What Problems Does This Solve?

This MCP server enables AI coding agents (like GitHub Copilot) to help developers with FeatBit feature flag management through natural language interactions. The server exposes three main MCP tools to solve these problems:

  1. SDK Integration Code Generation (generate_integration_code tool)

    • Generate integration code for multiple SDKs (.NET, JavaScript/TypeScript, Java, Python, Go, OpenFeature)
    • Provides best practices and working examples tailored to specific use cases
    • Helps developers quickly integrate FeatBit into their applications
  2. Feature Flag Deployment Assistance (how_to_deploy tool)

    • Step-by-step deployment guides for various platforms (Kubernetes, Azure, AWS, GCP, on-premise)
    • Support for different deployment methods (Helm, Docker Compose, Terraform, etc.)
    • Simplifies the FeatBit deployment process across different environments
  3. Documentation Search & Troubleshooting (search_documentation tool)

    • Intelligent document routing using AI and RAG for quick access to relevant FeatBit documentation
    • Provides troubleshooting guidance for common issues
    • Helps developers find answers without leaving their coding environment

How to Run Locally

Prerequisites

  • .NET 10 SDK
  • Visual Studio 2025, VS Code, or JetBrains Rider
  • (Optional) FeatBit account for online mode - get one at featbit.co

Configuration

  1. Clone the repository

    git clone https://github.com/featbit/featbit-mcp.git
    cd featbit-mcp
  2. Configure AI Provider (Azure OpenAI Only)

    Edit the same file to add your Azure OpenAI configuration:

    {
      "AI": {
        "Provider": "AzureOpenAI",
        "AzureOpenAI": {
          "Endpoint": "https://your-resource.openai.azure.com/",
          "ApiKey": "your-azure-openai-api-key",
          "Deployment": "gpt-4"
        }
      }
    }

    Note: Currently, only Azure OpenAI is supported as the AI provider.

  3. Configure FeatBit SDK (Optional for Online Mode)

Note: The server can run with or without FeatBit connection configured. Without FeatBit connection, it uses default values from FeatureFlag.cs for all feature flags. To enable dynamic feature flag control, configure the FeatBit connection in the Configuration section above.

Running Options

Option 1: Using .NET Aspire AppHost (Recommended)

cd FeatBit
dotnet run --project FeatBit.AppHost

This starts the Aspire Dashboard where you can monitor the MCP server with full observability.

Option 2: Run MCP Server Directly

cd FeatBit
dotnet run --project FeatBit.McpServer

The server will start on http://localhost:5000 (or the port specified in launchSettings.json).

Option 3: Using VS Code Tasks

The project includes pre-configured VS Code tasks:

  • build - Build the entire solution
  • build-apphost - Build only the AppHost
  • build-mcpserver - Build only the MCP Server

Press Ctrl+Shift+P → "Tasks: Run Task" → Select a task

Testing the MCP Server

Connect to Hosted Server (Recommended)

Use the standard configuration to connect to the hosted FeatBit MCP server:

{
  "servers": {
    "featbit": {
      "type": "http",
      "url": "https://mcp.featbit.co/mcp"
    }
  }
}

Connect to Local Server

If you're running the server locally, use:

{
  "servers": {
    "featbit-local": {
      "type": "http",
      "url": "http://localhost:5180/mcp"
    }
  }
}

Using HTTP API

The server also exposes HTTP endpoints for testing:

# Test with curl
curl -X POST http://localhost:5000/mcp \
  -H "Content-Type: application/json" \
  -d '{"method":"tools/list"}'

Or use the included Postman collection.


Architecture & Design Patterns

Technology Stack

  • .NET 10: Latest .NET runtime
  • ASP.NET Core: Web framework for HTTP-based MCP server
  • Aspire: Cloud-native orchestration and observability
  • Model Context Protocol (MCP): Microsoft's MCP framework for AI agent integration
  • Microsoft Extensions AI: Unified AI client abstraction
  • FeatBit Server SDK: Feature flag evaluation
  • OpenTelemetry: Distributed tracing, metrics, and logging

Project Structure

FeatBit.sln
├── FeatBit.AppHost              # Aspire orchestration host
├── FeatBit.McpServer            # Main MCP server application
│   ├── Controllers/             # (Future: REST controllers)
│   ├── Domain/                  # Domain models
│   │   ├── Deployments/        # Deployment-related models
│   │   ├── Migrations/         # Data migrations
│   │   └── Sdks/               # SDK-specific models
│   ├── Extensions/             # Service registration extensions
│   ├── Infrastructure/         # Cross-cutting concerns
│   ├── Middleware/             # Request pipeline middleware
│   ├── Resources/              # Embedded documentation
│   │   ├── Deployments/       # Deployment guides
│   │   └── Sdks/              # SDK integration guides
│   ├── Services/               # Business logic services
│   └── Tools/                  # MCP tool implementations
├── FeatBit.ServiceDefaults      # Aspire service defaults
├── FeatBit.FeatureFlags         # Feature flag evaluation
└── FeatBit.Contracts            # Shared interfaces

Design Patterns

1. Gateway Pattern (Tool Routing)

The MCP server uses a gateway pattern to limit and consolidate tools exposed to AI agents:

// Single tool handles multiple SDKs and topics
[McpServerTool]
public async Task<string> GenerateIntegrationCode(string sdk, string topic)
{
    // Gateway validates and routes to appropriate internal handler
    return await sdkService.GetSdkDocumentationAsync(sdk, topic);
}

Benefits:

  • Simplified AI agent interaction (fewer tools to choose from)
  • Centralized validation and routing logic
  • Easier to add new SDKs without exposing new tools

2. Strategy Pattern (SDK Selection)

Different SDK implementations registered as services:

builder.Services.AddTransient<NetServerSdk>();
builder.Services.AddTransient<JavascriptSdks>();
builder.Services.AddTransient<JavaSdks>();

The SdkService acts as a context that selects the appropriate strategy based on the sdk parameter.

3. Middleware Pipeline Pattern

Custom middleware for cross-cutting concerns:

app.UseMiddleware<McpToolTracingMiddleware>();      // OpenTelemetry tracing
app.UseMiddleware<GlobalExceptionHandlerMiddleware>(); // Error handling

4. Dependency Injection Pattern

Heavy use of .NET's built-in DI container:

// Scoped per request
builder.Services.AddScoped<ISessionContext, SessionContext>();
builder.Services.AddScoped<IFeatureFlagEvaluator, FeatureFlagEvaluator>();

// Singleton for shared resources
builder.Services.AddSingleton<IDocumentLoader, ResourcesDocumentLoader>();
builder.Services.AddSingleton<IClaudeSkillsMarkdownParser, ClaudeSkillsMarkdownParser>();

// Transient for lightweight services
builder.Services.AddTransient<NetServerSdk>();

5. Abstract Factory Pattern (AI Client Factory)

AiChatClientFactory creates different AI chat clients based on configuration:

public IChatClient CreateChatClient(string? provider = null)
{
    // Factory selects OpenAI, Azure OpenAI, or other providers
}

6. Repository Pattern (Document Loading)

IDocumentLoader abstracts document retrieval:

public interface IDocumentLoader
{
    Task<string> LoadDocumentAsync(string path);
}

Implementations:

  • ResourcesDocumentLoader: Loads from embedded resources
  • S3DocumentLoader: Could load from AWS S3 (future)
  • Enables easy switching between storage backends

7. Feature Toggle Pattern (Self-Dogfooding)

The server uses FeatBit's own SDK to control its behavior:

// Feature flags control SDK selection strategy
var useAiForSelection = await featureFlagEvaluator.BoolVariationAsync(
    "use-ai-sdk-selection", 
    defaultValue: false
);

This enables:

  • Gradual rollout of new features
  • A/B testing different AI selection strategies
  • Safe experimentation in production

8. Chain of Responsibility Pattern (Document Selection)

Document selection can use multiple strategies in sequence:

  1. Try exact match by filename
  2. If not found, use AI for semantic search
  3. If still not found, return default documentation

9. Adapter Pattern (MCP Tool Tracing)

McpToolTracingMiddleware adapts the MCP request/response into OpenTelemetry spans:

public class McpToolTracingMiddleware
{
    // Converts MCP tool invocations to OpenTelemetry traces
}

Key Architectural Decisions

Session Context vs MCP Session Management

// Separate from MCP's internal session management
builder.Services.AddScoped<ISessionContext, SessionContext>();

The server maintains its own session context for feature flag user identification, independent of MCP's session handling.

Embedded Resources Strategy

Documentation is embedded in the assembly:

<EmbeddedResource Include="Resources\Deployments\*.md" />
<EmbeddedResource Include="Resources\Sdks\**\*.md" />

Benefits:

  • Self-contained distribution
  • No external dependencies at runtime
  • Versioning aligned with code

Trade-offs:

  • Larger assembly size
  • Documentation updates require recompilation

Bootstrap Mode and Offline Operation

The server uses feature flags defined in FeatureFlag.cs with default values as fallback:

public sealed record FeatureFlag(string Key, bool DefaultValue, string Description)
{
    public static readonly FeatureFlag DocNotFound = new(
        Key: "doc-not-found",
        DefaultValue: false,
        Description: "Controls whether to return a suggestion message when no documentation is found"
    );
}

This enables:

  • Development without connecting to FeatBit server
  • Automatic fallback when FeatBit server is unavailable
  • Type-safe feature flag definitions with default values

Advanced Offline Mode: For more advanced offline scenarios and bootstrap capabilities, please refer to the FeatBit .NET Server SDK documentation or contact FeatBit official support.

Observability Architecture

Full OpenTelemetry integration via Aspire:

builder.AddServiceDefaults(); // Adds OpenTelemetry

Traces:

  • HTTP request tracing
  • MCP tool invocation tracing (via McpToolTracingMiddleware)
  • AI chat client tracing (via ChatClientOpenTelemetryMiddleware)
  • Feature flag evaluation tracing

Metrics:

  • Request counts and durations
  • Tool usage statistics
  • Feature flag evaluation counts

Logs:

  • Structured logging via ILogger<T>
  • Correlated with traces via Activity IDs

Scalability Considerations

  1. Stateless Design: Each request is independent, enabling horizontal scaling
  2. Scoped Services: Session context is scoped per request, no shared state
  3. Feature Flag Caching: FeatBit SDK caches flags locally, reducing network calls
  4. Resource Embedding: No external I/O for documentation retrieval

Security Considerations

  1. API Key Management: AI provider keys stored in configuration (use Key Vault in production)
  2. FeatBit Secret: Environment secret for feature flag evaluation
  3. Input Validation: Tool parameters validated before processing
  4. Error Handling: Global exception handler prevents information leakage

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

License

See LICENSE for details.

Support

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages