validate_code
Validates code against the design system's ACTUAL rules from the database.
Reference
Parameters
- Name
code- Type
- string · required
- Description
The code to validate
- Name
intent- Type
- string · optional
- Description
What the code is meant to do (enables intent route matching)
- Name
filePath- Type
- string · optional
- Description
File path context (enables context rule matching)
- Name
autoCorrect- Type
- boolean · optional
- Description
Return auto-corrected code where possible
- Name
layerId- Type
- string · optional
- Description
Design system layer UUID for layer-specific rules
- Name
includeDefaults- Type
- boolean · optional
- Description
Also run @preset/core default violation patterns
- Name
framework- Type
- enum · optional
- Description
Source framework: 'jsx' | 'tsx' | 'svelte'. Omit to infer from filePath (defaults to 'tsx'). 'svelte' routes through the converged DesignSignal checks. (
jsx·tsx·svelte)
- Name
trace- Type
- boolean · optional
- Description
PRE-2048/2107: persist a governance audit trace of this validation (verdict + per-rule provenance) and return its validationId. Internal (dogfood) orgs persist by default; set false to opt out. Other orgs do not persist yet regardless of this flag.
- Name
generationId- Type
- string · optional
- Description
Optional caller-supplied id of the upstream generation event, recorded on the trace.
- Name
idempotencyKey- Type
- string · optional
- Description
Optional caller-supplied key; retries with the same key reuse one trace row.
Returns
{
valid true when zero errors. Not a compliance claim; read verdict.
verdict "blocked" | "warned" | "passed" | "unchecked". "unchecked" = no findings, but no binding rules (none at warn/block) applied to this code: safe to write, NOT a compliance pass. Do not report it as passed.
coverage { bindingRules, advisoryRules, byFamily }; bindingRules 0 => unchecked
violations array with rule, found, fix, severity, line, ruleId, fixCode, reason
summary { errors, warnings, suggestions, byRule } — 'suggestions' are advisory findings from rules at enforcement_level 'suggest'; never a reason to change code
correctedCode auto-fixed code (if autoCorrect=true)
checksRun which check categories ran
nextAction suggested next step
}
Description
Validates code against the design system's ACTUAL rules from the database.
Unlike validate_generated_code (hardcoded defaults), this checks real forbidden_primitives, context_rules, intent_routes, patterns, and design_tokens.
RECOMMENDED WORKFLOW (generate → validate → fix loop):
- Generate code using get_component_api, get_design_tokens, etc.
- Call validate_code to check against real rules
- Fix any violations
- Call validate_code again until valid=true
Parameters:
- code (required): The code to validate
- intent: What the code is meant to do (enables intent route matching)
- filePath: File path context (enables context rule matching)
- autoCorrect: Return auto-corrected code where possible (default: false)
- layerId: Design system layer UUID for layer-specific rules
- includeDefaults: Also run @preset/core default patterns (default: false)
Source
Defined in packages/mcp/src/tools.ts.
The request handler lives alongside its registration in packages/mcp/src/tools/.