Observability & Monitoring
Track performance, monitor requests, and respond to MCP server events in real-time.
Track performance, monitor requests, and respond to events in real-time.
Statistics & Monitoring
The MCP server automatically tracks metrics for monitoring and analytics.
Enabling Statistics
Stats are enabled by default:
// Stats enabled by default
server = MCPServer( "myApp" )
// Explicitly disable
server = MCPServer( name: "myApp", statsEnabled: false )Get Summary Statistics
Quick overview of key metrics:
summary = server.getStatsSummary()
writeOutput( "Total Requests: #summary.totalRequests#" )
writeOutput( "Success Rate: #summary.successRate#%" )
writeOutput( "Avg Response Time: #summary.avgResponseTime#ms" )
writeOutput( "Tool Calls: #summary.totalToolInvocations#" )
writeOutput( "Resource Reads: #summary.totalResourceReads#" )
writeOutput( "Errors: #summary.totalErrors#" )
writeOutput( "Uptime: #summary.uptime / 1000#s" )Fields:
uptime— Server uptime in millisecondstotalRequests— Total requests processedsuccessRate— Success rate as percentageavgResponseTime— Average response time in msrequestsPerMinute— Request rateactiveRequests— Currently processing requestspaused— Whether server is pausedtotalToolInvocations— Total tool callstotalResourceReads— Total resource readstotalPromptGenerations— Total prompt generationstotalErrors— Total errors encounteredsecurity.authFailures— Failed HTTP basic auth attemptssecurity.apiKeyFailures— Failed API key checkssecurity.bodySizeViolations— Rejected oversized payloadssecurity.ipFilterFailures— Rejected client IP addresses
Get Detailed Statistics
Complete stats with breakdowns:
Managing Statistics
Event System 🎯
The MCP server fires custom events during its lifecycle, allowing you to add logging, monitoring, and custom integration.
Available Events
onMCPServerCreate
Fired when an MCP server instance is created.
onMCPServerRemove
Fired when an MCP server is removed.
onMCPRequest
Fired before processing an incoming MCP request.
onMCPResponse
Fired after processing and before returning the response.
onMCPError
Fired when an exception occurs.
Registering Event Listeners
Module Registration
In ModuleConfig.bx:
Application Registration
Use BoxRegisterInterceptor():
Practical Examples
Real-Time Dashboard
Custom Metrics
Integration with Monitoring Services
REST API Endpoint
Expose stats via API:
Performance Notes
Zero Overhead When Disabled — No impact if
statsEnabled: falseMemory Efficient — Last 1000 samples retained per metric
Thread Safe — Uses atomic operations
Real-Time — Stats updated immediately
Lightweight Summary —
getStatsSummary()optimized for frequent polling
Next Steps
⏸️ Pause & Resume — Pause server operations
✅ Best Practices — Production monitoring
💡 Examples — Complete working setups
Last updated