Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
categoryYes

Implementation Reference

  • 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 })
      }
    )
  • 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[]
    }
  • 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[]
    }
  • 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
      }
    }
  • 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
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description discloses 'Read-only, no side effects,' which is crucial given no annotations. It also explains the return format (list of rules or error) and the filtering behavior, providing full behavioral transparency beyond schema and annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Three concise sentences: first states purpose, second details output and filtering, third gives usage and alternatives. No redundancy, front-loaded with key info, every sentence adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and one parameter, the description covers all necessary aspects: purpose, safety, return structure, error case, parameter usage, and alternatives. It is fully self-contained and complete for agent decision-making.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The single parameter 'category' is thoroughly explained: it lists valid values (spacing, color, etc.) and that an empty string retrieves all rules. This adds significant meaning beyond the schema which only specifies type 'string' with no enum or description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool gets 'design rules inferred from your codebase patterns,' specifying a unique resource. It explicitly distinguishes itself from sibling tools by noting alternatives like get_token for explicit tokens and get_conflicts for conflicts, making its purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It provides explicit usage context: 'Use this to understand implicit conventions the codebase follows.' It also names alternatives (get_token, get_conflicts) and implicitly when not to use them, offering clear guidance for tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/AI-by-design/primitiv'

If you have feedback or need assistance with the MCP directory API, please join our Discord server