Skip to main content

Metrics System

MCP Gatekeeper collects comprehensive metrics from both STDIO and HTTP MCP servers.

Metrics Collection Methods

STDIO Servers

Binary Wrapper Approach:

  1. Installed packages have their binaries replaced with wrapper scripts
  2. Wrapper intercepts STDIO communication
  3. Metrics sent to /api/metrics/record endpoint
  4. Original binary execution continues transparently

Collected Metrics:

  • Tool call counts
  • Request/response latency
  • Success/failure rates
  • Agent type (from MCPGK_AGENT_TYPE env var)
  • Timestamps

HTTP Servers

Transparent Proxy Approach:

  1. All HTTP requests pass through proxy
  2. Proxy logs request/response details
  3. Metrics stored in http_server_metrics table
  4. SSE streams monitored

Collected Metrics:

  • Request count by method
  • Response status codes
  • Latency measurements
  • Error rates
  • Agent type (from URL path)

Data Flow

MCP Server → Wrapper/Proxy → API Endpoint

Database Storage

WebSocket Broadcast

Frontend UI Update

Database Schema

Metrics Table (STDIO)

  • server_id
  • tool_name
  • latency_ms
  • success (boolean)
  • agent_type
  • timestamp

HTTP Server Metrics Table

  • http_server_id
  • request_type
  • method
  • latency_ms
  • status_code
  • success (boolean)
  • timestamp

Real-time Updates

Metrics are broadcast via WebSocket at /api/ws/metrics for:

  • Live dashboard updates
  • Real-time charts
  • Activity notifications

For API details, see Metrics API.