get_tokens
Export design tokens as CSS custom properties, SCSS variables, Tailwind config, W3C or JSON. Specify context and category for targeted output.
Instructions
Export design tokens in a specific format: CSS custom properties, SCSS variables, Tailwind config, W3C Design Tokens format, or JSON.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | Design context to query | all |
| format | Yes | Output format (required) | |
| category | No | Token category to export | all |
Implementation Reference
- src/tools/get-tokens.ts:34-65 (handler)The handler function that executes the get_tokens tool logic. It resolves the design context, filters by category (colors/typography), and delegates to the appropriate formatter (CSS, SCSS, Tailwind, W3C, or JSON).
export function handler(index: DesignSystemIndex, args: GetTokensArgs) { const ctx = args.context ?? 'all'; const resolved = ctx === 'all' ? index.resolved.all : ctx === 'marketing' ? index.resolved.marketing : ctx === 'product' ? index.resolved.product : index.resolved.all; const colors = args.category === 'typography' ? [] : resolved.colors; const typography = args.category === 'colors' ? [] : resolved.typography; let output: string; switch (args.format) { case 'css': output = toCSSFormat(colors, typography); break; case 'scss': output = toSCSSFormat(colors, typography); break; case 'tailwind': output = toTailwindFormat(colors, typography); break; case 'w3c': output = toW3CFormat(colors, typography); break; case 'json': default: output = toJSONFormat(colors, typography); break; } return [{ type: 'text' as const, text: output }]; } - src/tools/get-tokens.ts:21-29 (schema)Input schema for the get_tokens tool, defining the context, format (required), and category parameters with their allowed values.
export const INPUT_SCHEMA = { type: 'object' as const, properties: { context: { type: 'string', enum: ['marketing', 'product', 'shared', 'all'], default: 'all', description: 'Design context to query' }, format: { type: 'string', enum: ['css', 'scss', 'tailwind', 'w3c', 'json'], description: 'Output format (required)' }, category: { type: 'string', enum: ['colors', 'typography', 'all'], default: 'all', description: 'Token category to export' }, }, required: ['format'], }; - src/types/mcp.ts:90-106 (schema)TypeScript type definition (GetTokensArgs) for the get_tokens tool arguments, with typed context, format, and category fields.
export interface GetTokensArgs { /** Filter tokens to a specific design context */ context?: 'marketing' | 'product' | 'shared' | 'all'; /** * Output format: * - "css": CSS custom properties * - "scss": SCSS variables * - "tailwind": Tailwind CSS theme extension * - "w3c": W3C Design Tokens Community Group format * - "json": Plain JSON key-value pairs */ format: 'css' | 'scss' | 'tailwind' | 'w3c' | 'json'; /** Restrict output to a specific token category */ category?: 'colors' | 'typography' | 'spacing' | 'all'; } - src/tools/index.ts:90-91 (registration)Registration of the get_tokens tool in the request handler switch statement, dispatching calls to tokens.handler(index, args).
case tokens.TOOL_NAME: return { content: tokens.handler(index, args as never) }; - src/tools/index.ts:43-49 (registration)The tokens module is included as one of the ALL_TOOLS in the registration list (line 43), and imported as 'import * as tokens from './get-tokens.js' (line 25).
tokens, textures, css, searchBrand, contextDiff, validateUsage, ] as const;