1use serde_json::{json, Value};
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum SchemaTarget {
7 AuditReport,
9 EvalReport,
11 AuditDiff,
13 RepairPlan,
15 PatchSet,
17 ApplyReport,
19 ComposeReport,
21 SourceScanReport,
23 RankerComparison,
25 AuditConfig,
27}
28
29#[must_use]
31pub fn json_schema_for(target: SchemaTarget) -> Value {
32 match target {
33 SchemaTarget::AuditConfig => json!({
34 "$schema": "https://json-schema.org/draft/2020-12/schema",
35 "title": "mcp-vol AuditConfig (.mcp-vol.json)",
36 "type": "object",
37 "additionalProperties": false,
38 "properties": {
39 "collision_threshold": { "type": "number", "minimum": 0.0, "maximum": 1.0, "default": 0.72 },
40 "sibling_disambiguation_threshold": { "type": "number", "minimum": 0.0, "maximum": 1.0, "default": 0.50 },
41 "shadow_similarity_threshold": { "type": "number", "minimum": 0.0, "maximum": 1.0, "default": 0.30 },
42 "max_tool_tokens": { "type": "integer", "minimum": 1, "default": 250 },
43 "max_catalog_tokens": { "type": "integer", "minimum": 1, "default": 15000 },
44 "fail_on": { "type": ["string", "null"], "enum": ["error", "warn", "info", null], "default": "error" },
45 "disabled_rules": { "type": "array", "items": { "type": "string", "pattern": "^VOL[0-9]{3}$" }, "default": [] },
46 "input_price_per_million_usd": { "type": "number", "minimum": 0.0, "default": 3.0 },
47 "cached_price_per_million_usd": { "type": "number", "minimum": 0.0, "default": 0.3 }
48 }
49 }),
50 SchemaTarget::AuditReport => json!({
51 "$schema": "https://json-schema.org/draft/2020-12/schema",
52 "title": "mcp-vol AuditReport",
53 "type": "object",
54 "required": ["schema_version", "summary", "dimension_scores", "tool_scores", "findings", "collisions"],
55 "properties": {
56 "schema_version": { "type": "string" },
57 "summary": {
58 "type": "object",
59 "required": ["passed", "tool_count", "estimated_catalog_tokens", "overall_score", "worst_tool_score", "tier", "error_count", "warning_count", "info_count", "collision_count", "shadowing_count"],
60 "properties": {
61 "passed": { "type": "boolean" },
62 "tool_count": { "type": "integer" },
63 "estimated_catalog_tokens": { "type": "integer" },
64 "estimated_cost_per_turn_usd": { "type": "number" },
65 "estimated_200_turn_session_usd": { "type": "number" },
66 "estimated_200_turn_cached_usd": { "type": "number" },
67 "overall_score": { "type": "number", "minimum": 1.0, "maximum": 5.0 },
68 "worst_tool_score": { "type": "number", "minimum": 1.0, "maximum": 5.0 },
69 "tier": { "type": "string", "enum": ["A", "B", "C", "D", "F"] },
70 "error_count": { "type": "integer" },
71 "warning_count": { "type": "integer" },
72 "info_count": { "type": "integer" },
73 "collision_count": { "type": "integer" },
74 "shadowing_count": { "type": "integer" }
75 }
76 },
77 "dimension_scores": { "type": "object", "additionalProperties": { "type": "number" } },
78 "tool_scores": { "type": "array", "items": { "type": "object" } },
79 "findings": {
80 "type": "array",
81 "items": {
82 "type": "object",
83 "required": ["code", "slug", "severity", "dimension", "tool", "json_pointer", "message", "evidence", "fix_hint"],
84 "properties": {
85 "code": { "type": "string", "pattern": "^VOL[0-9]{3}$" },
86 "slug": { "type": "string" },
87 "severity": { "type": "string", "enum": ["info", "warn", "error"] },
88 "dimension": { "type": "string" },
89 "tool": { "type": "string" },
90 "related_tool": { "type": "string" },
91 "json_pointer": { "type": "string" },
92 "message": { "type": "string" },
93 "evidence": {},
94 "fix_hint": { "type": "string" },
95 "source_location": {
96 "type": "object",
97 "required": ["file", "line", "column"],
98 "properties": {
99 "file": { "type": "string" },
100 "line": { "type": "integer" },
101 "column": { "type": "integer" }
102 }
103 },
104 "source_server": { "type": "string" }
105 }
106 }
107 },
108 "collisions": { "type": "array", "items": { "type": "object" } },
109 "tool_fingerprints": { "type": "object", "additionalProperties": { "type": "string" } }
110 }
111 }),
112 SchemaTarget::EvalReport => json!({
113 "$schema": "https://json-schema.org/draft/2020-12/schema",
114 "title": "mcp-vol EvalReport",
115 "type": "object",
116 "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"],
117 "properties": {
118 "schema_version": { "type": "string" },
119 "total_cases": { "type": "integer" },
120 "top_k": { "type": "integer" },
121 "top1_hits": { "type": "integer" },
122 "top1_accuracy": { "type": "number", "minimum": 0.0, "maximum": 1.0 },
123 "topk_hits": { "type": "integer" },
124 "recall_at_k": { "type": "number", "minimum": 0.0, "maximum": 1.0 },
125 "mrr": { "type": "number", "minimum": 0.0, "maximum": 1.0 },
126 "ndcg_at_k": { "type": "number", "minimum": 0.0, "maximum": 1.0 },
127 "per_tool_accuracy": { "type": "object", "additionalProperties": { "type": "number" } },
128 "confusion_matrix": { "type": "array", "items": { "type": "object" } },
129 "failures": { "type": "array", "items": { "type": "object" } }
130 }
131 }),
132 SchemaTarget::AuditDiff => json!({
133 "$schema": "https://json-schema.org/draft/2020-12/schema",
134 "title": "mcp-vol AuditDiff",
135 "type": "object",
136 "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"],
137 "properties": {
138 "schema_version": { "type": "string" },
139 "score_delta": { "type": "number" },
140 "token_delta": { "type": "integer" },
141 "session_cost_delta_usd": { "type": "number" },
142 "error_delta": { "type": "integer" },
143 "warning_delta": { "type": "integer" },
144 "new_findings": { "type": "array" },
145 "resolved_findings": { "type": "array" },
146 "added_tools": { "type": "array", "items": { "type": "string" } },
147 "removed_tools": { "type": "array", "items": { "type": "string" } },
148 "modified_tools": { "type": "array", "items": { "type": "string" } },
149 "cache_busting_change": { "type": "boolean" },
150 "regressed": { "type": "boolean" }
151 }
152 }),
153 SchemaTarget::RepairPlan => json!({
154 "$schema": "https://json-schema.org/draft/2020-12/schema",
155 "title": "mcp-vol RepairPlan",
156 "type": "object",
157 "required": ["schema_version", "current_overall_score", "current_tier", "tools_to_fix", "total_findings", "items"],
158 "properties": {
159 "schema_version": { "type": "string" },
160 "current_overall_score": { "type": "number" },
161 "current_tier": { "type": "string", "enum": ["A", "B", "C", "D", "F"] },
162 "tools_to_fix": { "type": "integer" },
163 "total_findings": { "type": "integer" },
164 "items": { "type": "array", "items": { "type": "object" } }
165 }
166 }),
167 SchemaTarget::PatchSet => json!({
168 "$schema": "https://json-schema.org/draft/2020-12/schema",
169 "title": "mcp-vol PatchSet (RFC 6902)",
170 "type": "object",
171 "required": ["schema_version", "patch_count", "manual_prose_findings", "patches"],
172 "properties": {
173 "schema_version": { "type": "string" },
174 "patch_count": { "type": "integer" },
175 "manual_prose_findings": { "type": "integer" },
176 "patches": {
177 "type": "array",
178 "items": {
179 "type": "object",
180 "required": ["code", "tool", "confidence", "rationale", "operations"],
181 "properties": {
182 "code": { "type": "string" },
183 "tool": { "type": "string" },
184 "confidence": { "type": "string", "enum": ["high", "medium"] },
185 "rationale": { "type": "string" },
186 "operations": {
187 "type": "array",
188 "items": {
189 "type": "object",
190 "required": ["op", "path"],
191 "properties": {
192 "op": { "type": "string", "enum": ["add", "replace", "remove"] },
193 "path": { "type": "string" },
194 "value": {}
195 }
196 }
197 }
198 }
199 }
200 }
201 }
202 }),
203 SchemaTarget::ApplyReport => json!({
204 "$schema": "https://json-schema.org/draft/2020-12/schema",
205 "title": "mcp-vol ApplyReport",
206 "type": "object",
207 "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"],
208 "properties": {
209 "schema_version": { "type": "string" },
210 "min_confidence": { "type": "string", "enum": ["high", "medium"] },
211 "applied_patch_count": { "type": "integer" },
212 "skipped_patch_count": { "type": "integer" },
213 "score_before": { "type": "number" },
214 "score_after": { "type": "number" },
215 "errors_before": { "type": "integer" },
216 "errors_after": { "type": "integer" },
217 "warnings_before": { "type": "integer" },
218 "warnings_after": { "type": "integer" },
219 "applied_codes": { "type": "array", "items": { "type": "string" } },
220 "remaining_findings": { "type": "integer" }
221 }
222 }),
223 SchemaTarget::ComposeReport => json!({
224 "$schema": "https://json-schema.org/draft/2020-12/schema",
225 "title": "mcp-vol ComposeReport (Multi-Server Federation)",
226 "type": "object",
227 "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"],
228 "properties": {
229 "schema_version": { "type": "string" },
230 "server_count": { "type": "integer" },
231 "total_tools": { "type": "integer" },
232 "total_estimated_tokens": { "type": "integer" },
233 "total_200_turn_uncached_usd": { "type": "number" },
234 "total_200_turn_cached_usd": { "type": "number" },
235 "combined_score": { "type": "number" },
236 "combined_tier": { "type": "string", "enum": ["A", "B", "C", "D", "F"] },
237 "cross_server_exact_duplicates": { "type": "integer" },
238 "cross_server_semantic_collisions": { "type": "integer" },
239 "score_if_namespaced": { "type": "number" },
240 "exact_duplicates_if_namespaced": { "type": "integer" },
241 "servers": { "type": "array", "items": { "type": "object" } },
242 "cross_server_collisions": { "type": "array", "items": { "type": "object" } },
243 "deferral_recommendations": { "type": "array", "items": { "type": "object" } },
244 "combined_audit": { "type": "object" }
245 }
246 }),
247 SchemaTarget::SourceScanReport => json!({
248 "$schema": "https://json-schema.org/draft/2020-12/schema",
249 "title": "mcp-vol SourceScanReport",
250 "type": "object",
251 "required": ["schema_version", "files_scanned", "tools_discovered", "by_language", "tools"],
252 "properties": {
253 "schema_version": { "type": "string" },
254 "files_scanned": { "type": "integer" },
255 "tools_discovered": { "type": "integer" },
256 "by_language": { "type": "object", "additionalProperties": { "type": "integer" } },
257 "tools": { "type": "array", "items": { "type": "object" } }
258 }
259 }),
260 SchemaTarget::RankerComparison => json!({
261 "$schema": "https://json-schema.org/draft/2020-12/schema",
262 "title": "mcp-vol RankerComparison",
263 "type": "object",
264 "required": ["schema_version", "total_cases", "top_k", "winner", "results"],
265 "properties": {
266 "schema_version": { "type": "string" },
267 "total_cases": { "type": "integer" },
268 "top_k": { "type": "integer" },
269 "winner": { "type": "string" },
270 "results": { "type": "array", "items": { "type": "object" } }
271 }
272 }),
273 }
274}