-
Notifications
You must be signed in to change notification settings - Fork 168
Open
Labels
bugSomething isn't workingSomething isn't workingtriageIssues / Features awaiting triageIssues / Features awaiting triage
Milestone
Description
Metrics Enhancement Todo & Verification Checklist
Overview
This document tracks the remaining work for metrics enhancement after merging PR #657, which implemented the Metrics Tab UI enhancements as requested in issue #368.
Context
- Original Issue: #368 - Enhance Metrics Tab UI for MCP Context Forge
- Current PR: #657 - Metrics Tab UI Enhancements
- Branch:
feature/metrics-tab-enhancements
Completed Work (PR #657)
✅ Added Virtual Servers to metrics display
✅ Created enhanced Top 5 Performance Tables with detailed columns
✅ Implemented tab navigation for different entity types
✅ Added responsive and mobile-friendly tables
✅ Fixed authentication dependencies and SQLAlchemy syntax
✅ Resolved Alembic migration conflicts
✅ Improved test coverage (1403 tests passing)
Outstanding Issues to Address
1. Export Functionality - Export ALL Data, Not Just Top 5
Current Behavior
- Location:
mcpgateway/static/admin.js:1617-1662
(exportMetricsToCSV function) - Issue: Export button only exports the top 5 items passed to it from
topData
- Affected endpoints:
/admin/metrics
page export button/metrics
API endpoint (if it exports)
Required Changes
- Modify export functionality to fetch ALL metrics data, not just top 5
- UI should continue showing top 5 for performance/clarity
- Export should include complete dataset
Implementation Details
// Current implementation in admin.js:1629-1650
["tools", "resources", "prompts", "gateways", "servers"].forEach((type) => {
if (topData[type] && Array.isArray(topData[type])) {
// Only exports what's in topData (limited to 5 items)
}
});
Files to Check/Modify
mcpgateway/static/admin.js
- exportMetricsToCSV functionmcpgateway/admin.py:4046-4049
- Currently limits to 5 in API response- Service layer methods:
mcpgateway/services/tool_service.py:193
- get_top_tools(limit=5)mcpgateway/services/resource_service.py:116
- get_top_resources(limit=5)mcpgateway/services/prompt_service.py:143
- get_top_prompts(limit=5)mcpgateway/services/server_service.py:131
- get_top_servers(limit=5)
2. Metrics Accuracy Verification
Areas to Verify
A. Last Used Timestamps
- Check: Ensure
last_execution
orlastExecution
fields are properly updated - Location:
- Frontend:
admin.js:1348-1372
(formatLastUsed function) - Backend: Metric model properties in
mcpgateway/db.py
- Frontend:
- Test: Execute tools/resources/prompts and verify timestamp updates
B. Success Rate Calculations
- Current Implementation:
admin.js:1332-1342
(calculateSuccessRate function) - Check for:
- Division by zero protection (currently handled:
total > 0 ? ... : 0
) - Correct percentage calculation
- Proper field mapping (successRate vs calculated value)
- Division by zero protection (currently handled:
- Backend Sources:
- Tool metrics:
mcpgateway/db.py:527
(avg_response_time property) - Resource metrics:
mcpgateway/db.py:745
(avg_response_time property) - Prompt metrics:
mcpgateway/db.py:929
(avg_response_time property) - Server metrics:
mcpgateway/db.py:1073
(avg_response_time property)
- Tool metrics:
C. Execution Counts
- Verify: Increment logic for all entity types
- Check:
- Tools: execution_count increments on tool invocation
- Resources: execution_count increments on resource access
- Prompts: execution_count increments on prompt usage
- Servers: execution_count increments on server interaction
3. Response Time Truncation
Current Issue
- Response times show excessive decimal places:
1.1898999695965489
- Should be truncated to 3 decimal places:
1.189
Locations to Fix
-
Frontend Display:
admin.js:1642-1644
item.avg_response_time || item.avgResponseTime ? `${Math.round(item.avg_response_time || item.avgResponseTime)}ms` : "N/A"
Currently uses
Math.round()
which removes all decimals. Should use:`${(item.avg_response_time || item.avgResponseTime).toFixed(3)}ms`
-
Backend Response: Check if truncation should happen at API level
- Service methods returning avg_response_time
- Schema definitions in
mcpgateway/schemas.py
4. Performance & Edge Cases
Division by Zero
- Status: Already handled in frontend (
total > 0 ? ... : 0
) - Verify: Backend calculations in metric properties
Large Dataset Performance
- Check: Performance with 1000+ metrics entries
- Consider: Pagination for export functionality
- Test: Load testing with concurrent metric updates
Database Query Optimization
- Review: Query performance in service layer get_top_* methods
- Check: Proper indexing on metric tables
- Verify: Efficient aggregation queries
Null/Undefined Handling
- Frontend: Check all field access for null safety
- Backend: Verify Optional fields handle None properly
Testing Checklist
Manual Testing
- Create multiple tool executions, verify metrics update
- Create resource accesses, verify metrics update
- Use prompts, verify metrics update
- Interact with servers, verify metrics update
- Check "Last Used" shows correct relative time
- Verify success rates calculate correctly (successful/total * 100)
- Export metrics and verify CSV contains ALL data, not just top 5
- Check response times are truncated to 3 decimal places
- Test with no metrics (empty state)
- Test with failed executions (success rate < 100%)
Automated Testing
- Unit tests for metric calculation methods
- Integration tests for metric endpoints
- Test export functionality with large datasets
- Test edge cases (division by zero, null values)
Performance Testing
- Load test with 1000+ metric entries
- Concurrent metric updates
- Export performance with large datasets
- UI responsiveness with many metrics
Implementation Priority
-
High Priority
- Fix export to include ALL data (not just top 5)
- Truncate response times to 3 decimal places
- Verify success rate calculations
-
Medium Priority
- Verify last used timestamps update correctly
- Add comprehensive test coverage
- Performance optimization for large datasets
-
Low Priority
- Additional UI enhancements
- Advanced filtering options
- Real-time metric updates
Code Locations Reference
Frontend Files
mcpgateway/static/admin.js
- Main UI logicmcpgateway/templates/admin/metrics.html
- Metrics page template
Backend Files
mcpgateway/admin.py:4044-4051
- Metrics API endpointmcpgateway/services/tool_service.py
- Tool metrics logicmcpgateway/services/resource_service.py
- Resource metrics logicmcpgateway/services/prompt_service.py
- Prompt metrics logicmcpgateway/services/server_service.py
- Server metrics logicmcpgateway/db.py
- Metric model propertiesmcpgateway/schemas.py
- API response schemas
Database Models
ToolMetric
- Tool execution metricsResourceMetric
- Resource access metricsPromptMetric
- Prompt usage metricsServerMetric
- Server interaction metrics
Notes
- The UI should continue to display top 5 for clarity and performance
- Export functionality should provide complete data for analysis
- Consider adding a "View All" link for each metric category in future iterations
- Response time truncation should be consistent across all displays
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingtriageIssues / Features awaiting triageIssues / Features awaiting triage