This specification defines monitoring and reporting capabilities for the CodeQL Development MCP Server that capture comprehensive data about query development sessions. The system tracks all interactions, test results, and quality metrics in a unified JSON structure, enabling multiple downstream applications including functional testing, comparative analysis, and development insights.
Each query development session is represented as a single, comprehensive JSON object that captures:
- Session Metadata: Timestamps, query path, language, session ID
- MCP Call History: Complete log of all MCP primitive calls with parameters and results
- Test Execution Records: Compilation attempts, test runs, and results over time
- Quality Metrics: Multi-dimensional scoring and assessment data
- Development Progression: Evolution of query state and recommendations
These session objects can be:
- Aggregated into arrays for batch analysis across multiple sessions/queries
- Compared to evaluate different development approaches for the same query
- Processed for functional testing (pass/fail determinations)
- Analyzed for reporting and insights generation
- Post-processed by external tools for custom analytics
Enable comprehensive monitoring and flexible reporting by:
- Unified Session Tracking - Single JSON object per query development session containing all relevant data
- MCP Usage Analytics - Complete audit trail of which primitives are called, when, and with what results
- Quality Evolution Monitoring - Track how query quality scores change over development iterations
- Flexible Data Export - Session objects designed for easy aggregation and post-processing
- Multi-Purpose Analysis - Support functional testing, comparative studies, and development insights from the same data
- Intelligent Guidance - Leverage session history to provide contextual next-step recommendations
The core data structure is a comprehensive JSON object representing a complete query development session:
interface QueryDevelopmentSession {
// Session Metadata
sessionId: string;
queryPath: string;
language: string;
queryType?: string;
description?: string;
startTime: string; // ISO timestamp
endTime?: string; // ISO timestamp
status: 'active' | 'completed' | 'failed' | 'abandoned';
// MCP Call History
mcpCalls: MCPCallRecord[];
// Test Execution Records
testExecutions: TestExecutionRecord[];
// Quality Metrics
qualityScores: QualityScoreRecord[];
// Development State
currentState: QueryState;
recommendations: string[];
nextSuggestedTool?: string;
}
interface MCPCallRecord {
callId: string;
timestamp: string;
toolName: string;
parameters: Record<string, any>;
result: any;
success: boolean;
duration: number; // milliseconds
nextSuggestedTool?: string;
}
interface TestExecutionRecord {
executionId: string;
timestamp: string;
type: 'compilation' | 'test_run' | 'database_build';
success: boolean;
details: Record<string, any>;
metrics?: {
passRate?: number;
coverage?: number;
performance?: number;
};
}
interface QualityScoreRecord {
scoreId: string;
timestamp: string;
overallScore: number; // 0-100
dimensions: {
syntacticCorrectness: number;
testCoverageResults: number;
documentationQuality: number;
functionalCorrectness: number;
};
grade: 'A' | 'B' | 'C' | 'D' | 'F';
recommendations: string[];
}
interface QueryState {
filesPresent: string[];
compilationStatus: 'unknown' | 'success' | 'failed';
testStatus: 'unknown' | 'passing' | 'failing' | 'no_tests';
documentationStatus: 'unknown' | 'present' | 'missing' | 'incomplete';
lastActivity: string; // ISO timestamp
}A production-grade CodeQL query must have:
- ✅ Syntactically valid
.qlfile that compiles successfully - ✅ Comprehensive documentation (
.mdor.qhelp) with compliant/non-compliant examples - ✅ Valid test structure with
.qlreffile and test cases - ✅ Passing tests where
.actualmatches.expected100% - ✅ Low false-positive rate with accurate detection
Maintain unified JSON objects for each query development session:
- Session Lifecycle: Create, update, and finalize session objects with complete development history
- Transparent Integration: Automatically capture all MCP calls and associate them with active sessions
- Real-time Updates: Continuously update session objects as development progresses
- Persistent Storage: Store session objects using lowdb for reliable JSON persistence
- Query Association: Link all activities to specific
.qlfile paths, updating MCP primitive schemas to includequeryPathparameters
Record complete audit trails of MCP server interactions:
- Call Logging: Capture every MCP primitive call with full parameters and results
- Performance Metrics: Track call duration and success rates
- Context Preservation: Maintain relationship between sequential calls within a session
- Transparent Operation: Integrate tracking without affecting existing MCP tool behavior
Continuous evaluation system integrated into session objects:
- Syntactic Correctness (25%): Compilation status, syntax quality, library usage
- Test Coverage & Results (30%): Test existence, pass rates, result accuracy
- Documentation Quality (20%): Documentation presence, completeness, examples
- Functional Correctness (25%): True/false positive rates, performance characteristics
Scores stored as time-series data within session objects for evolution tracking.
Leverage session history to provide contextual recommendations:
- Next Action Suggestions: Include
nextSuggestedToolin all MCP responses based on session state - Development Insights: Analyze patterns across sessions to suggest optimal approaches
- Progress Assessment: Identify when sessions are stagnating and recommend interventions
- Adaptive Recommendations: Adjust suggestions based on query type, language, and historical success patterns
Generate insights from session object collections:
- Session Reports: Detailed analysis of individual query development sessions
- Comparative Analysis: Cross-session comparisons for the same query across different approaches
- Aggregate Insights: Batch analysis of multiple sessions for pattern identification
- Export Capabilities: JSON (primary), HTML, and Markdown formats for different consumption needs
- Functional Testing: Process session collections to generate pass/fail results for automated testing
session_start(queryPath: string, language?: string, queryType?: string, description?: string)→sessionIdsession_end(sessionId: string, status: 'completed' | 'failed' | 'abandoned')→QueryDevelopmentSessionsession_get(sessionId: string)→QueryDevelopmentSessionsession_list(filters?: { queryPath?: string, status?: string, dateRange?: [string, string] })→QueryDevelopmentSession[]session_update_state(sessionId: string, stateUpdate: Partial<QueryState>)→QueryDevelopmentSession
session_get_call_history(sessionId: string, limit?: number)→MCPCallRecord[]session_get_test_history(sessionId: string, limit?: number)→TestExecutionRecord[]session_get_score_history(sessionId: string, limit?: number)→QualityScoreRecord[]session_calculate_current_score(sessionId: string)→QualityScoreRecord
sessions_compare(sessionIds: string[], dimensions?: string[])→ComparisonReportsessions_aggregate(filters: SessionFilter)→AggregateReportsessions_export(sessionIds: string[], format?: 'json' | 'html' | 'markdown')→ExportResult
sessions_evaluate_functional_tests(sessionIds: string[])→FunctionalTestResult[]sessions_generate_test_report(sessionIds: string[], criteria: TestCriteria)→TestReport
Unified JSON storage approach using lowdb in .ql-mcp-tracking/:
.ql-mcp-tracking/
├── sessions.json # Primary storage: array of QueryDevelopmentSession objects
├── sessions-archive/ # Completed sessions moved for performance
│ ├── 2024-09/{sessionId}.json # Archived by month
│ └── 2024-10/{sessionId}.json
├── exports/ # Generated reports and exports
│ ├── comparative-analysis-{timestamp}.json
│ ├── functional-test-results-{timestamp}.json
│ └── session-reports-{timestamp}.html
└── config.json # Storage configuration and metadata
- Primary Storage: Active sessions in
sessions.jsonas a single array ofQueryDevelopmentSessionobjects - Performance Optimization: Archive completed sessions to monthly files to maintain lookup performance
- Unified Structure: All session data (calls, tests, scores) embedded within session objects
- Export Support: Generate static reports and export files for external processing
- Backup-Friendly: Simple JSON files easily backed up and version controlled
- Single Source of Truth: Each session object contains complete development history
- Aggregation Ready: Session arrays can be directly processed by analysis tools
- Cross-Session Analysis: Multiple session objects easily compared and aggregated
- Export Flexibility: Session objects serialize naturally to JSON for external tools
- Functional Testing: Session collections map directly to test execution results
- Unified Data Model: Single session object per query development containing all tracking data
- Transparent Monitoring: Automatic session updates during MCP primitive calls without affecting existing functionality
- Backwards Compatible: All monitoring features opt-in; existing tools work unchanged
- Session-Aware Primitives: Update MCP primitive schemas to include optional
sessionIdparameter for explicit session association - Performance Optimized: <10% overhead through efficient JSON operations and configurable tracking depth
- Multi-Purpose Design: Session objects support functional testing, reporting, and analysis without additional data transformation
-
Unified Data Model & Storage (2 weeks)
- Define
QueryDevelopmentSessionschema and related interfaces - Implement lowdb-based storage with session object management
- Create session lifecycle management APIs
- Define
-
Transparent Session Integration (2 weeks)
- Update MCP primitive schemas to include session parameters
- Implement automatic session updates during MCP calls
- Add session-aware call tracking and state management
-
Quality Assessment & Guidance (2 weeks)
- Implement multi-dimensional scoring within session objects
- Build intelligent next-step recommendation system
- Integrate quality metrics with session state tracking
-
Reporting & Analysis Tools (2 weeks)
- Build session comparison and aggregation capabilities
- Implement export functionality for multiple formats
- Create functional testing evaluation from session collections
- Complete Session Tracking: Every MCP call associated with a query development captured in session objects
- Unified Data Structure: Single JSON object per session containing all development data (calls, tests, scores, state)
- Flexible Analysis Support: Session objects easily aggregated and processed for multiple purposes
- Performance Efficiency: <10% overhead for session tracking and data updates
- Multi-Purpose Utility: Same session data serves functional testing, reporting, and development insights
- Backwards Compatibility: Existing MCP tools work unchanged with optional session integration
Process collections of session objects to determine pass/fail status based on configurable criteria:
const testResults = await sessions_evaluate_functional_tests(sessionIds);
// Returns: { sessionId, queryPath, passed: boolean, criteria: TestCriteria, details: any }[]Compare multiple development approaches for the same query:
const comparison = await sessions_compare([sessionA, sessionB, sessionC]);
// Returns: detailed comparison of approaches, success rates, and recommendationsAnalyze patterns across sessions to improve development processes:
const insights = await sessions_aggregate({ queryType: 'security', language: 'java' });
// Returns: aggregated metrics, common patterns, success factorsTrack individual query development in real-time:
const session = await session_get(sessionId);
// Returns: complete QueryDevelopmentSession with current state and recommendationsinterface MonitoringConfig {
storageLocation: string; // Default: ".ql-mcp-tracking/"
autoTrackSessions: boolean; // Auto-track when sessions active
retentionDays: number; // Data retention period for archived sessions
includeCallParameters: boolean; // Log detailed MCP call parameters
includeCallResults: boolean; // Log detailed MCP call results
maxActiveSessionsPerQuery: number; // Limit concurrent sessions per query
scoringFrequency: 'per_call' | 'periodic' | 'manual'; // When to calculate quality scores
archiveCompletedSessions: boolean; // Move completed sessions to archive
enableRecommendations: boolean; // Provide next-step suggestions
}This specification provides the foundation for implementing comprehensive monitoring and reporting capabilities that enable functional testing, comparative analysis, and development insights through unified query development session tracking.