Metrics System
MCP Gatekeeper collects comprehensive metrics from both STDIO and HTTP MCP servers.
Metrics Collection Methods
STDIO Servers
Binary Wrapper Approach:
- Installed packages have their binaries replaced with wrapper scripts
- Wrapper intercepts STDIO communication
- Metrics sent to
/api/metrics/recordendpoint - Original binary execution continues transparently
Collected Metrics:
- Tool call counts
- Request/response latency
- Success/failure rates
- Agent type (from
MCPGK_AGENT_TYPEenv var) - Timestamps
HTTP Servers
Transparent Proxy Approach:
- All HTTP requests pass through proxy
- Proxy logs request/response details
- Metrics stored in
http_server_metricstable - 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.