Skip to main content
Glama

get_design_context

Retrieve the resolved design system context to inspect tokens, components, and conflicts. Use this first to understand existing design rules before building UI.

Instructions

Get the resolved design system context before building UI. Read-only, no side effects. Default (no category) returns a JSON summary of token counts, component names, conflict counts, and contract metadata. Pass category: 'all' | 'tokens' | 'components' | 'conflicts' to get full detail. Pass tokenCategory to filter tokens: colors, spacing, typography, borderRadius, shadows. Use this as the first call to understand what exists. For lookups by name, use get_token or get_component instead.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryYes
tokenCategoryYes

Implementation Reference

  • The main handler function for the 'get_design_context' tool. It reads the contract and returns design context based on category: 'summary' (default, returns token counts, component names, conflicts), 'all', 'tokens', 'components', or 'conflicts'. Also supports filtering tokens by tokenCategory.
    async (args) => {
      if (!this.contract) return this.noContract()
      const category = args.category || "summary"
    
      if (category === "summary") {
        const tokenCounts: Record<string, number> = {}
        for (const [cat, tokens] of Object.entries(this.contract.tokens)) {
          tokenCounts[cat] = Object.keys(tokens).length
        }
        const ageMs = Date.now() - new Date(this.contract.generatedAt).getTime()
        const contractAgeHours = Math.floor(ageMs / (1000 * 60 * 60))
        const warnings = this.getContractWarnings()
        return this.json({
          ...(warnings.length > 0 ? { warnings } : {}),
          sourceRoot: this.contract.sourceRoot ?? "(unknown — rebuild with latest primitiv)",
          generatedAt: this.contract.generatedAt,
          contractAgeHours,
          sources: this.contract.sources,
          tokenCounts,
          componentNames: Object.keys(this.contract.components),
          componentCount: Object.keys(this.contract.components).length,
          conflictCount: this.contract.conflicts.length,
          pendingConflicts: this.contract.conflicts.filter((c) => c.resolution === "pending").length
        })
      }
    
      const stripSource = (
        tokens: Record<string, { name: string; value: string; references?: string[]; rationale?: Rationale }>
      ) =>
        Object.fromEntries(
          Object.entries(tokens).map(([k, t]) => [
            k,
            {
              name: t.name,
              value: t.value,
              ...(t.references ? { references: t.references } : {}),
              ...(t.rationale ? { rationale: t.rationale } : {})
            }
          ])
        )
    
      const result: Record<string, unknown> = {}
      if (category === "all" || category === "tokens") {
        result.tokens = args.tokenCategory
          ? { [args.tokenCategory]: stripSource(this.contract.tokens[args.tokenCategory] || {}) }
          : Object.fromEntries(
              Object.entries(this.contract.tokens).map(([cat, tokens]) => [cat, stripSource(tokens)])
            )
      }
      if (category === "all" || category === "components") {
        result.components = Object.fromEntries(
          Object.entries(this.contract.components).map(([k, c]) => [
            k,
            {
              name: c.name,
              source: c.source,
              propCount: Object.keys(c.props ?? {}).length,
              ...(c.rationale ? { rationale: c.rationale } : {})
            }
          ])
        )
      }
      if (category === "all" || category === "conflicts") {
        result.conflicts = this.contract.conflicts
        result.conflictCount = this.contract.conflicts.length
        result.pendingConflicts = this.contract.conflicts.filter((c) => c.resolution === "pending").length
      }
      result.generatedAt = this.contract.generatedAt
      result.sources = this.contract.sources
      return this.json(result)
    }
  • The registerTools method registers 'get_design_context' (and other tools) via this.server.registerTool(). The registration includes the name 'get_design_context', description, inputSchema, and the async handler callback.
    private registerTools(): void {
      this.server.registerTool(
        "get_design_context",
        {
          description:
            "Get the resolved design system context before building UI. Read-only, no side effects. Default (no category) returns a JSON summary of token counts, component names, conflict counts, and contract metadata. Pass category: 'all' | 'tokens' | 'components' | 'conflicts' to get full detail. Pass tokenCategory to filter tokens: colors, spacing, typography, borderRadius, shadows. Use this as the first call to understand what exists. For lookups by name, use get_token or get_component instead.",
          inputSchema: {
            category: z.string(),
            tokenCategory: z.string()
          }
        },
        async (args) => {
          if (!this.contract) return this.noContract()
          const category = args.category || "summary"
    
          if (category === "summary") {
            const tokenCounts: Record<string, number> = {}
            for (const [cat, tokens] of Object.entries(this.contract.tokens)) {
              tokenCounts[cat] = Object.keys(tokens).length
            }
            const ageMs = Date.now() - new Date(this.contract.generatedAt).getTime()
            const contractAgeHours = Math.floor(ageMs / (1000 * 60 * 60))
            const warnings = this.getContractWarnings()
            return this.json({
              ...(warnings.length > 0 ? { warnings } : {}),
              sourceRoot: this.contract.sourceRoot ?? "(unknown — rebuild with latest primitiv)",
              generatedAt: this.contract.generatedAt,
              contractAgeHours,
              sources: this.contract.sources,
              tokenCounts,
              componentNames: Object.keys(this.contract.components),
              componentCount: Object.keys(this.contract.components).length,
              conflictCount: this.contract.conflicts.length,
              pendingConflicts: this.contract.conflicts.filter((c) => c.resolution === "pending").length
            })
          }
    
          const stripSource = (
            tokens: Record<string, { name: string; value: string; references?: string[]; rationale?: Rationale }>
          ) =>
            Object.fromEntries(
              Object.entries(tokens).map(([k, t]) => [
                k,
                {
                  name: t.name,
                  value: t.value,
                  ...(t.references ? { references: t.references } : {}),
                  ...(t.rationale ? { rationale: t.rationale } : {})
                }
              ])
            )
    
          const result: Record<string, unknown> = {}
          if (category === "all" || category === "tokens") {
            result.tokens = args.tokenCategory
              ? { [args.tokenCategory]: stripSource(this.contract.tokens[args.tokenCategory] || {}) }
              : Object.fromEntries(
                  Object.entries(this.contract.tokens).map(([cat, tokens]) => [cat, stripSource(tokens)])
                )
          }
          if (category === "all" || category === "components") {
            result.components = Object.fromEntries(
              Object.entries(this.contract.components).map(([k, c]) => [
                k,
                {
                  name: c.name,
                  source: c.source,
                  propCount: Object.keys(c.props ?? {}).length,
                  ...(c.rationale ? { rationale: c.rationale } : {})
                }
              ])
            )
          }
          if (category === "all" || category === "conflicts") {
            result.conflicts = this.contract.conflicts
            result.conflictCount = this.contract.conflicts.length
            result.pendingConflicts = this.contract.conflicts.filter((c) => c.resolution === "pending").length
          }
          result.generatedAt = this.contract.generatedAt
          result.sources = this.contract.sources
          return this.json(result)
        }
      )
  • Input schema for the tool: accepts 'category' (string) and 'tokenCategory' (string), both using zod validation.
    inputSchema: {
      category: z.string(),
      tokenCategory: z.string()
    }
  • The 'summary' branch of the handler calls getContractWarnings() (line 145) to check for stale contracts and mismatches, and uses helper methods like this.json() and this.err() for formatting responses.
    async (args) => {
      if (!this.contract) return this.noContract()
      const category = args.category || "summary"
    
      if (category === "summary") {
        const tokenCounts: Record<string, number> = {}
        for (const [cat, tokens] of Object.entries(this.contract.tokens)) {
          tokenCounts[cat] = Object.keys(tokens).length
        }
        const ageMs = Date.now() - new Date(this.contract.generatedAt).getTime()
        const contractAgeHours = Math.floor(ageMs / (1000 * 60 * 60))
        const warnings = this.getContractWarnings()
        return this.json({
          ...(warnings.length > 0 ? { warnings } : {}),
          sourceRoot: this.contract.sourceRoot ?? "(unknown — rebuild with latest primitiv)",
          generatedAt: this.contract.generatedAt,
          contractAgeHours,
          sources: this.contract.sources,
          tokenCounts,
          componentNames: Object.keys(this.contract.components),
          componentCount: Object.keys(this.contract.components).length,
          conflictCount: this.contract.conflicts.length,
          pendingConflicts: this.contract.conflicts.filter((c) => c.resolution === "pending").length
        })
Behavior4/5

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

States 'Read-only, no side effects' which clarifies safety. Although no annotations exist, the description discloses behavioral traits (no side effects) and output modes. It does not mention auth or rate limits, but these are not critical for this context tool.

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?

Five sentences, front-loaded with main purpose, then parameter details, and finally usage guidance. No redundant information; every sentence serves a purpose.

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

Completeness4/5

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

Given the absence of annotations and output schema, the description covers purpose, parameters, behavior, and usage context well. The only notable gap is the required parameter contradiction, but overall it provides sufficient context for an agent to use the tool correctly.

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

Parameters4/5

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

With 0% schema coverage, the description explains both parameters: category with allowed values ('all', 'tokens', 'components', 'conflicts') and default behavior, and tokenCategory with filter values (colors, spacing, etc.). This adds significant meaning beyond the bare schema. However, there is a minor contradiction: description implies category is optional ('Default (no category)') but schema marks it required.

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 verb 'Get' and resource 'resolved design system context'. It explains the default summary output and details how to get full detail with category values. It also distinguishes from sibling tools get_token and get_component.

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?

Explicitly advises using this as the first call to understand what exists, and provides an alternative: 'For lookups by name, use get_token or get_component instead.' This clarifies when and when not to use the tool.

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