get_inferred_rules
Infer design rules from codebase patterns by category, returning structured JSON with pattern and confidence to understand implicit conventions.
Instructions
Get the design rules inferred from your codebase patterns. Read-only, no side effects. Returns JSON with a list of rules including category, pattern, and confidence, or an error if no rules have been generated yet. Pass category to filter: spacing, color, typography, border-radius, naming, components. Pass empty string to get all. Use this to understand implicit conventions the codebase follows. For explicit design token values, use get_token. For source conflicts, use get_conflicts.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | Yes |
Implementation Reference
- src/mcp/server.ts:290-310 (handler)The MCP tool handler for 'get_inferred_rules'. Registered via this.server.registerTool with inputSchema (category filter), it reads contract.inferredRules, filters by category if provided, and returns JSON with count, generatedAt, and rules. Returns error if no contract or no inferred rules exist.
this.server.registerTool( "get_inferred_rules", { description: "Get the design rules inferred from your codebase patterns. Read-only, no side effects. Returns JSON with a list of rules including category, pattern, and confidence, or an error if no rules have been generated yet. Pass category to filter: spacing, color, typography, border-radius, naming, components. Pass empty string to get all. Use this to understand implicit conventions the codebase follows. For explicit design token values, use get_token. For source conflicts, use get_conflicts.", inputSchema: { category: z.string() } }, async (args) => { if (!this.contract) return this.noContract() const inferredRules = this.contract.inferredRules if (!inferredRules || inferredRules.rules.length === 0) { return this.err("No inferred rules found. Run `primitiv build` to generate them.") } const rules = args.category ? inferredRules.rules.filter((r) => r.category === args.category) : inferredRules.rules return this.json({ count: rules.length, generatedAt: inferredRules.generatedAt, rules }) } ) - src/types.ts:133-144 (schema)Type definitions for InferredRule (id, category, rule, confidence, evidence) and InferredRules (generatedAt, rules array). The InferredRules is an optional field on PrimitivContract.
export interface InferredRule { id: string category: "spacing" | "color" | "typography" | "border-radius" | "naming" | "components" rule: string confidence: "high" | "medium" | "low" evidence: string[] } export interface InferredRules { generatedAt: string rules: InferredRule[] } - src/inferrer/inferrer.ts:3-14 (schema)Duplicate type definitions for InferredRule and InferredRules used locally in the inferrer module. Same shape as types.ts.
export interface InferredRule { id: string category: "spacing" | "color" | "typography" | "border-radius" | "naming" | "components" rule: string confidence: "high" | "medium" | "low" evidence: string[] } export interface InferredRules { generatedAt: string rules: InferredRule[] } - src/inferrer/inferrer.ts:23-40 (helper)The core inferRules() function that takes TokenMap and ComponentMap, flattens them, and runs all category-specific inference functions (spacing, color, border-radius, typography, naming, components) to produce the InferredRules object with generated timestamp.
export function inferRules(tokenMap: TokenMap, componentMap: ComponentMap): InferredRules { const tokens = flattenTokens(tokenMap) const components = Object.values(componentMap) const rules: InferredRule[] = [ ...inferSpacingRules(tokens), ...inferColorRules(tokens), ...inferBorderRadiusRules(tokens), ...inferTypographyRules(tokens), ...inferNamingRules(tokens), ...inferComponentRules(components) ] return { generatedAt: new Date().toISOString(), rules } } - src/contract/contract.ts:18-29 (registration)Where inferRules is called during contract build (ContractBuilder.build). The result is stored on the PrimitivContract object under the inferredRules field, which the MCP server later reads at runtime.
const inferredRules = inferRules(mergedTokens, mergedComponents) const contract: PrimitivContract = { version: "0.2.0", generatedAt: new Date().toISOString(), sources: sources.map((s) => s.name), sourceRoot: "", configPath: "", tokens: mergedTokens, components: mergedComponents, conflicts, inferredRules