use serde_json::{json, Value};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SchemaTarget {
AuditReport,
EvalReport,
AuditDiff,
RepairPlan,
PatchSet,
ApplyReport,
ComposeReport,
SourceScanReport,
RankerComparison,
AuditConfig,
}
#[must_use]
pub fn json_schema_for(target: SchemaTarget) -> Value {
match target {
SchemaTarget::AuditConfig => json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "mcp-vol AuditConfig (.mcp-vol.json)",
"type": "object",
"additionalProperties": false,
"properties": {
"collision_threshold": { "type": "number", "minimum": 0.0, "maximum": 1.0, "default": 0.72 },
"sibling_disambiguation_threshold": { "type": "number", "minimum": 0.0, "maximum": 1.0, "default": 0.50 },
"shadow_similarity_threshold": { "type": "number", "minimum": 0.0, "maximum": 1.0, "default": 0.30 },
"max_tool_tokens": { "type": "integer", "minimum": 1, "default": 250 },
"max_catalog_tokens": { "type": "integer", "minimum": 1, "default": 15000 },
"fail_on": { "type": ["string", "null"], "enum": ["error", "warn", "info", null], "default": "error" },
"disabled_rules": { "type": "array", "items": { "type": "string", "pattern": "^VOL[0-9]{3}$" }, "default": [] },
"input_price_per_million_usd": { "type": "number", "minimum": 0.0, "default": 3.0 },
"cached_price_per_million_usd": { "type": "number", "minimum": 0.0, "default": 0.3 }
}
}),
SchemaTarget::AuditReport => json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "mcp-vol AuditReport",
"type": "object",
"required": ["schema_version", "summary", "dimension_scores", "tool_scores", "findings", "collisions"],
"properties": {
"schema_version": { "type": "string" },
"summary": {
"type": "object",
"required": ["passed", "tool_count", "estimated_catalog_tokens", "overall_score", "worst_tool_score", "tier", "error_count", "warning_count", "info_count", "collision_count", "shadowing_count"],
"properties": {
"passed": { "type": "boolean" },
"tool_count": { "type": "integer" },
"estimated_catalog_tokens": { "type": "integer" },
"estimated_cost_per_turn_usd": { "type": "number" },
"estimated_200_turn_session_usd": { "type": "number" },
"estimated_200_turn_cached_usd": { "type": "number" },
"overall_score": { "type": "number", "minimum": 1.0, "maximum": 5.0 },
"worst_tool_score": { "type": "number", "minimum": 1.0, "maximum": 5.0 },
"tier": { "type": "string", "enum": ["A", "B", "C", "D", "F"] },
"error_count": { "type": "integer" },
"warning_count": { "type": "integer" },
"info_count": { "type": "integer" },
"collision_count": { "type": "integer" },
"shadowing_count": { "type": "integer" }
}
},
"dimension_scores": { "type": "object", "additionalProperties": { "type": "number" } },
"tool_scores": { "type": "array", "items": { "type": "object" } },
"findings": {
"type": "array",
"items": {
"type": "object",
"required": ["code", "slug", "severity", "dimension", "tool", "json_pointer", "message", "evidence", "fix_hint"],
"properties": {
"code": { "type": "string", "pattern": "^VOL[0-9]{3}$" },
"slug": { "type": "string" },
"severity": { "type": "string", "enum": ["info", "warn", "error"] },
"dimension": { "type": "string" },
"tool": { "type": "string" },
"related_tool": { "type": "string" },
"json_pointer": { "type": "string" },
"message": { "type": "string" },
"evidence": {},
"fix_hint": { "type": "string" },
"source_location": {
"type": "object",
"required": ["file", "line", "column"],
"properties": {
"file": { "type": "string" },
"line": { "type": "integer" },
"column": { "type": "integer" }
}
},
"source_server": { "type": "string" }
}
}
},
"collisions": { "type": "array", "items": { "type": "object" } },
"tool_fingerprints": { "type": "object", "additionalProperties": { "type": "string" } }
}
}),
SchemaTarget::EvalReport => json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "mcp-vol EvalReport",
"type": "object",
"required": ["schema_version", "total_cases", "top_k", "top1_hits", "top1_accuracy", "topk_hits", "recall_at_k", "mrr", "ndcg_at_k", "per_tool_accuracy", "confusion_matrix", "failures"],
"properties": {
"schema_version": { "type": "string" },
"total_cases": { "type": "integer" },
"top_k": { "type": "integer" },
"top1_hits": { "type": "integer" },
"top1_accuracy": { "type": "number", "minimum": 0.0, "maximum": 1.0 },
"topk_hits": { "type": "integer" },
"recall_at_k": { "type": "number", "minimum": 0.0, "maximum": 1.0 },
"mrr": { "type": "number", "minimum": 0.0, "maximum": 1.0 },
"ndcg_at_k": { "type": "number", "minimum": 0.0, "maximum": 1.0 },
"per_tool_accuracy": { "type": "object", "additionalProperties": { "type": "number" } },
"confusion_matrix": { "type": "array", "items": { "type": "object" } },
"failures": { "type": "array", "items": { "type": "object" } }
}
}),
SchemaTarget::AuditDiff => json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "mcp-vol AuditDiff",
"type": "object",
"required": ["schema_version", "score_delta", "token_delta", "error_delta", "warning_delta", "new_findings", "resolved_findings", "added_tools", "removed_tools", "modified_tools", "cache_busting_change", "regressed"],
"properties": {
"schema_version": { "type": "string" },
"score_delta": { "type": "number" },
"token_delta": { "type": "integer" },
"session_cost_delta_usd": { "type": "number" },
"error_delta": { "type": "integer" },
"warning_delta": { "type": "integer" },
"new_findings": { "type": "array" },
"resolved_findings": { "type": "array" },
"added_tools": { "type": "array", "items": { "type": "string" } },
"removed_tools": { "type": "array", "items": { "type": "string" } },
"modified_tools": { "type": "array", "items": { "type": "string" } },
"cache_busting_change": { "type": "boolean" },
"regressed": { "type": "boolean" }
}
}),
SchemaTarget::RepairPlan => json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "mcp-vol RepairPlan",
"type": "object",
"required": ["schema_version", "current_overall_score", "current_tier", "tools_to_fix", "total_findings", "items"],
"properties": {
"schema_version": { "type": "string" },
"current_overall_score": { "type": "number" },
"current_tier": { "type": "string", "enum": ["A", "B", "C", "D", "F"] },
"tools_to_fix": { "type": "integer" },
"total_findings": { "type": "integer" },
"items": { "type": "array", "items": { "type": "object" } }
}
}),
SchemaTarget::PatchSet => json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "mcp-vol PatchSet (RFC 6902)",
"type": "object",
"required": ["schema_version", "patch_count", "manual_prose_findings", "patches"],
"properties": {
"schema_version": { "type": "string" },
"patch_count": { "type": "integer" },
"manual_prose_findings": { "type": "integer" },
"patches": {
"type": "array",
"items": {
"type": "object",
"required": ["code", "tool", "confidence", "rationale", "operations"],
"properties": {
"code": { "type": "string" },
"tool": { "type": "string" },
"confidence": { "type": "string", "enum": ["high", "medium"] },
"rationale": { "type": "string" },
"operations": {
"type": "array",
"items": {
"type": "object",
"required": ["op", "path"],
"properties": {
"op": { "type": "string", "enum": ["add", "replace", "remove"] },
"path": { "type": "string" },
"value": {}
}
}
}
}
}
}
}
}),
SchemaTarget::ApplyReport => json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "mcp-vol ApplyReport",
"type": "object",
"required": ["schema_version", "min_confidence", "applied_patch_count", "skipped_patch_count", "score_before", "score_after", "errors_before", "errors_after", "warnings_before", "warnings_after", "applied_codes", "remaining_findings"],
"properties": {
"schema_version": { "type": "string" },
"min_confidence": { "type": "string", "enum": ["high", "medium"] },
"applied_patch_count": { "type": "integer" },
"skipped_patch_count": { "type": "integer" },
"score_before": { "type": "number" },
"score_after": { "type": "number" },
"errors_before": { "type": "integer" },
"errors_after": { "type": "integer" },
"warnings_before": { "type": "integer" },
"warnings_after": { "type": "integer" },
"applied_codes": { "type": "array", "items": { "type": "string" } },
"remaining_findings": { "type": "integer" }
}
}),
SchemaTarget::ComposeReport => json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "mcp-vol ComposeReport (Multi-Server Federation)",
"type": "object",
"required": ["schema_version", "server_count", "total_tools", "total_estimated_tokens", "combined_score", "combined_tier", "cross_server_exact_duplicates", "cross_server_semantic_collisions", "score_if_namespaced", "exact_duplicates_if_namespaced", "servers", "cross_server_collisions", "deferral_recommendations", "combined_audit"],
"properties": {
"schema_version": { "type": "string" },
"server_count": { "type": "integer" },
"total_tools": { "type": "integer" },
"total_estimated_tokens": { "type": "integer" },
"total_200_turn_uncached_usd": { "type": "number" },
"total_200_turn_cached_usd": { "type": "number" },
"combined_score": { "type": "number" },
"combined_tier": { "type": "string", "enum": ["A", "B", "C", "D", "F"] },
"cross_server_exact_duplicates": { "type": "integer" },
"cross_server_semantic_collisions": { "type": "integer" },
"score_if_namespaced": { "type": "number" },
"exact_duplicates_if_namespaced": { "type": "integer" },
"servers": { "type": "array", "items": { "type": "object" } },
"cross_server_collisions": { "type": "array", "items": { "type": "object" } },
"deferral_recommendations": { "type": "array", "items": { "type": "object" } },
"combined_audit": { "type": "object" }
}
}),
SchemaTarget::SourceScanReport => json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "mcp-vol SourceScanReport",
"type": "object",
"required": ["schema_version", "files_scanned", "tools_discovered", "by_language", "tools"],
"properties": {
"schema_version": { "type": "string" },
"files_scanned": { "type": "integer" },
"tools_discovered": { "type": "integer" },
"by_language": { "type": "object", "additionalProperties": { "type": "integer" } },
"tools": { "type": "array", "items": { "type": "object" } }
}
}),
SchemaTarget::RankerComparison => json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "mcp-vol RankerComparison",
"type": "object",
"required": ["schema_version", "total_cases", "top_k", "winner", "results"],
"properties": {
"schema_version": { "type": "string" },
"total_cases": { "type": "integer" },
"top_k": { "type": "integer" },
"winner": { "type": "string" },
"results": { "type": "array", "items": { "type": "object" } }
}
}),
}
}