validateAnnotations static method
Validate annotations against MCP 2025-03-26 standards
Implementation
static List<String> validateAnnotations(Map<String, dynamic> annotations) {
final errors = <String>[];
// Check for conflicting annotations
if (isReadOnly(annotations) && isDestructive(annotations)) {
errors.add('Tool cannot be both readOnly and destructive');
}
// Validate priority
final priority = annotations[ToolAnnotationKeys.priority];
if (priority != null && priority is String) {
try {
ToolPriority.values.firstWhere((p) => p.toString() == priority);
} catch (e) {
errors.add('Invalid priority value: $priority');
}
}
// Validate estimated duration
final duration = annotations[ToolAnnotationKeys.estimatedDuration];
if (duration != null && (duration is! int || duration < 0)) {
errors.add('estimatedDuration must be a non-negative integer');
}
// Validate resource usage
final usage = annotations[ToolAnnotationKeys.resourceUsage];
if (usage != null && usage is Map<String, dynamic>) {
final validLevels = ['low', 'medium', 'high'];
for (final level in ['cpu', 'memory', 'network', 'disk']) {
final value = usage[level];
if (value != null && !validLevels.contains(value)) {
errors.add('Invalid $level usage level: $value. Must be one of $validLevels');
}
}
}
return errors;
}