Skip to main content
The backend uses a command queue system to orchestrate satellites, enabling dynamic MCP server management through prioritized commands with automatic retry logic.

Command Queue Architecture

Commands are created by the backend and stored in the satelliteCommands table. Satellites poll for pending commands, execute them, and report results back to the backend.

Command Flow

Key Components:
  • Command Queue: PostgreSQL table with priority-based ordering
  • Polling: Satellites poll every 2-60 seconds based on priority
  • Execution: Satellite processes command and performs action
  • Result Reporting: Satellite reports success/failure back to backend

Command Types

The system supports 5 command types defined in the command_type enum:

Configure Commands

Most Common: Used for all MCP installation lifecycle events (create/update/delete). How It Works:
  1. Backend creates configure command with event metadata
  2. Satellite fetches fresh configuration from backend
  3. DynamicConfigManager compares old vs. new config
  4. Identifies added/removed/modified servers
  5. Takes appropriate action (spawn/restart/terminate)
Key Insight: The satellite doesn’t parse individual event types. All configure commands trigger a full configuration refresh where changes are detected by comparing configurations.

Command Priorities

Commands are processed based on priority: Higher priority commands are retrieved first when satellite polls.

Command Payload Structure

All commands include a JSON payload with event-specific data:

Status Changes Triggered by Commands

Commands trigger per-user instance status changes through satellite event emission: Per-User Status Tracking: Each team member’s instance has independent status. User A’s config change only affects User A’s instance status. Status Lifecycle on Installation (per user):
  1. Backend creates installation → creates instances for all team members
  2. If user has required config → status=provisioning
  3. If user missing required config → status=awaiting_user_config (not sent to satellite)
  4. User configures settings → status changes to provisioning → satellite spawns
  5. Satellite connects → status=connecting
  6. Satellite discovers tools → status=discovering_tools
  7. Process complete → status=online
For complete instance lifecycle documentation, see Instance Lifecycle. For complete status transition documentation, see Backend Events - Status Values.

Command Event Types

All configure commands include an event field in the payload for tracking and logging:

Event Field Usage

Current Implementation: The satellite does NOT parse the event field. All configure commands trigger a full configuration refresh where the satellite:
  1. Fetches fresh config from backend
  2. Compares with current running config
  3. Identifies added/removed/modified servers
  4. Takes appropriate action
Per-User Instance Impact: Configure commands trigger per-user instance creation/updates:
  • Installation created → All team members get instances (status depends on required user config)
  • Installation updated → Only affects users with existing configs (others remain awaiting_user_config)
  • Installation deleted → CASCADE deletes all user instances
Purpose of Event Field:
  • Database record keeping
  • Structured logging
  • Future extensibility
  • Developer debugging
Example payload for deletion:

SatelliteCommandService API

The backend provides convenience methods for creating commands:

notifyMcpInstallation()

Creates immediate priority configure commands when a new MCP server is installed.
Payload: event: 'mcp_installation_created'

notifyMcpUpdate()

Creates immediate priority configure commands when MCP configuration is updated.
Payload: event: 'mcp_installation_updated'

notifyMcpDeletion()

Creates immediate priority configure commands when an MCP installation is deleted.
Payload: event: 'mcp_installation_deleted'

notifyMcpRecovery()

Creates high priority configure commands when a server recovers from failure.
Payload: event: 'mcp_recovery' Status Flow:
  • Triggered by health check detecting offline installation
  • Sets status to connecting
  • Satellite rediscovers tools
  • Status progresses: offline → connecting → discovering_tools → online
For complete recovery system documentation, see Backend Communication - Auto-Recovery.

notifyMcpRedeploy()

Creates immediate priority configure commands for GitHub deployment redeploy.
Payload:
Use Case: GitHub-deployed MCP servers only Satellite Actions:
  1. For active processes:
    • Calls removeServerCompletely() to delete deployment directory
    • Triggers config refresh
    • Downloads fresh tarball from GitHub
    • Extracts, installs dependencies, builds
    • Spawns with new code
  2. For dormant processes:
    • Clears dormant config cache
    • Triggers config refresh
    • Forces fresh download on respawn
Status Flow:
  • Backend sets status to restarting
  • Satellite deletes old deployment directory
  • Downloads fresh code from GitHub (new SHA)
  • Status progresses: restarting → connecting → discovering_tools → online
  • New/updated tools become available
Key Difference from Update:
  • notifyMcpUpdate() → Restarts with existing cached code
  • notifyMcpRedeploy() → Deletes cache, downloads fresh from GitHub
For GitHub deployment details, see GitHub Deployment.

Critical Pattern

ALWAYS use the correct convenience method:
  • Installation created → notifyMcpInstallation()
  • Installation updated → notifyMcpUpdate()
  • Installation deleted → notifyMcpDeletion()
  • Server recovered → notifyMcpRecovery()
  • GitHub deployment redeploy → notifyMcpRedeploy()
NEVER call the wrong method for an operation! For example:
  • ❌ Don’t call notifyMcpInstallation() for delete operations
  • ❌ Don’t call notifyMcpUpdate() for GitHub redeploy (won’t download fresh code)
  • ❌ Don’t call notifyMcpInstallation() for redeploy (wrong semantic meaning)

Command Lifecycle

Commands progress through the following states:

Retry Logic

Failed commands are automatically retried:
  • Max Retries: 3 attempts
  • Retry Delay: Exponential backoff
  • Expiration: Commands expire after 5 minutes

Database Schema

Table: satelliteCommands Key Fields:
  • id: Command UUID
  • satellite_id: Target satellite
  • command_type: One of 5 command types
  • priority: Command priority level
  • payload: JSON command data (includes event type)
  • status: Current execution state
  • target_team_id: Team context
  • correlation_id: Request tracing
  • retry_count: Retry attempts
  • error_message: Failure details
  • result: Execution result

Command Processing on Satellite

When satellites receive commands: For configure commands:
  1. Fetch fresh configuration from backend
  2. Compare with current running config
  3. Identify changes (added/removed/modified servers)
  4. Execute appropriate actions:
    • Added: Spawn new processes
    • Modified: Restart affected processes
    • Removed: Terminate processes
For spawn commands:
  1. Parse server configuration
  2. For stdio: Launch subprocess with JSON-RPC
  3. For HTTP/SSE: Create proxy tracker entry
  4. Discover tools via tools/list call
For kill commands:
  1. Locate running process
  2. Send SIGTERM for graceful shutdown
  3. Wait for timeout (10 seconds)
  4. Send SIGKILL if needed
For restart commands:
  1. Execute kill sequence
  2. Wait for process termination
  3. Execute spawn sequence
For health_check commands:
  1. Check payload.check_type field:
    • connectivity (default): Call tools/list to verify server responds
    • credential_validation: Validate OAuth tokens for installation
  2. Execute appropriate validation
  3. Report health status via mcp.server.status_changed event:
    • online - Health check passed
    • requires_reauth - OAuth token expired/revoked
    • error - Validation failed with error
Credential Validation Flow:
  • Backend cron job sends health_check command with check_type: 'credential_validation'
  • Satellite validates OAuth token (performs token refresh test)
  • Emits status event based on validation result
  • Backend updates mcpServerInstallations.status and last_credential_check_at
For satellite-side credential validation implementation, see Satellite OAuth Authentication.

Example Usage

Creating Commands for Installation Deletion

Creating Commands for Configuration Update

Monitoring Commands

Check Command Status

View Command Payload

Monitor Failed Commands