MCP EXTRACTION CRITERIA

Comprehensive guidelines for AI-assisted development within the Editor platform

MCP Extraction Criteria

Document: When to extract McpGatewayModule to backend-mcp-api Created: 2026-01-22 Session: 56.1 Status: Reference document for future evaluation


Overview

The McpGatewayModule in backend-ai-api is designed to be extractable. This document defines the specific, measurable criteria that would trigger extraction to a separate backend-mcp-api microservice.


Extraction Triggers

Extract when ANY of these conditions are met:

1. Traffic Volume

Metric Threshold How to Measure
Daily MCP requests > 100,000 mcp_usage collection aggregate
Peak requests/second > 100 APM metrics (P99 latency)
Unique users/day > 10,000 Distinct userId count

Current: Not measured. Add observability first.

2. Performance Isolation

Symptom Threshold Action
MCP latency impacts other endpoints P95 > 500ms Extract to isolate
Memory pressure from MCP operations > 1GB dedicated Extract to scale independently
CPU-bound MCP operations > 50% CPU Extract with dedicated resources

Current: No symptoms observed.

3. Scaling Requirements

Requirement Indicator
MCP needs horizontal scaling Traffic justifies multiple instances
Different scaling profile MCP scales differently than AI generation
Cost optimization Separate billing for MCP compute

Current: Single instance sufficient.

4. Team/Organizational

Trigger Justification
Dedicated MCP team Ownership boundaries
Different release cadence Decouple deployments
Regulatory requirement Compliance isolation

Current: Single team, unified release.

5. Revenue/Business

Trigger Justification
MCP as standalone product Separate pricing, billing
Enterprise customers need dedicated instances Isolation requirements
Third-party MCP marketplace Multi-tenant separation

Current: Integrated with GoGrab Space.


How to Measure (Observability Checklist)

Before extraction can be evaluated, implement these metrics:

Required Metrics

// Add to McpGatewayModule or use external APM
interface McpMetrics {
  // Request metrics
  requestCount: Counter;           // Total requests
  requestDuration: Histogram;      // Latency distribution
  requestErrors: Counter;          // Error count by type

  // Resource metrics
  activeConnections: Gauge;        // WebSocket connections
  memoryUsage: Gauge;              // MCP-specific memory

  // Business metrics
  uniqueUsers: Gauge;              // DAU for MCP
  toolUsageByName: Counter;        // Which tools are popular
  tierBreakdown: Counter;          // Free vs paid usage
}

Logging Requirements

// Structured logs for analysis
{
  level: 'info',
  service: 'mcp-gateway',
  event: 'tool_call',
  tool: 'preflight',
  userId: 'xxx',
  spaceId: 'xxx',
  durationMs: 45,
  success: true,
  tier: 'builder'
}

Dashboard Requirements


Extraction Process (When Triggered)

Step 1: Preparation

  1. Ensure all metrics are in place
  2. Document current baseline performance
  3. Identify all integration points

Step 2: Create New API

# Generate new NestJS application
nx generate @nx/nest:application backend-mcp-api

# Copy McpGatewayModule
cp -r apis/backend-ai-api/src/app/mcp-gateway apis/backend-mcp-api/src/app/

# Update imports to use shared libs
# @libs-api/backend-core
# @libs-api/auth-core

Step 3: Configure Infrastructure

// apis/backend-mcp-api/src/app/app.module.ts
@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }),
    AuthCoreModule.forRoot({ /* same config */ }),
    MongooseModule.forRootAsync({ /* same databases */ }),
    ThrottlerModule.forRoot(AI_THROTTLE_CONFIG),
    McpGatewayModule,  // Now the main module
  ],
})
export class AppModule {}

Step 4: Update Integration Points

  1. Update frontend to call new API endpoint
  2. Update backend-ai-api to remove McpGatewayModule
  3. If needed, create HTTP client for cross-service calls

Step 5: Deploy and Validate

  1. Deploy to staging with feature flag
  2. Run load tests to compare performance
  3. Gradual rollout with traffic splitting
  4. Monitor for regressions

Estimated Effort

Task Effort Notes
Create new API structure 2-4 hours NX generators help
Move and refactor module 4-8 hours Clean up imports
Update CI/CD 2-4 hours Add Railway service
Testing and validation 8-16 hours Load testing, integration
Documentation 2-4 hours Update all references

Total: 2-4 days (when criteria are met)


Feature Flag

The module already includes extraction preparation:

// McpGatewayModule providers
{
  provide: 'MCP_STANDALONE_MODE',
  useValue: process.env.MCP_STANDALONE_MODE === 'true' || false,
}

When MCP_STANDALONE_MODE=true:


Decision History

Date Decision Reason
2026-01-17 Keep as module Session 50.8 - 70% infrastructure reuse
2026-01-22 Reaffirmed Session 56.1 - No metrics justify extraction

Review Schedule

Re-evaluate this decision:


Created from Session 56.1 architecture analysis. Decision ID: dev_1769090837831_j0ub80x