get_rules
Retrieve component rules documentation to understand existing guidelines and compliance requirements, with filtering by category options.
Instructions
Get component rules documentation. Use this to understand what rules exist and how to follow them. Can filter by category.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| category | No | Filter rules by category | |
| format | No | Output format |
Implementation Reference
- src/tools/index.ts:278-304 (handler)The handleGetRules function that executes the logic for the 'get_rules' MCP tool. It handles category filtering, format selection (markdown/json/summary), fetches rules using helpers, and constructs the ToolResult response.function handleGetRules(args: Record<string, unknown>): ToolResult { const category = args.category as string | undefined; const format = (args.format as string) || 'markdown'; let rules: Rule[]; if (category && category !== 'all') { rules = getRulesByCategory(category as Rule['category']); } else { rules = getAllRules(); } let text: string; if (format === 'json') { text = JSON.stringify(rules, null, 2); } else if (format === 'summary') { text = rules .map((r) => `- **${r.name}** (\`${r.id}\`): ${r.description}`) .join('\n'); } else { text = getRulesMarkdown(); } return { content: [{ type: 'text', text }], }; }
- src/tools/index.ts:60-74 (schema)The inputSchema defining parameters for the 'get_rules' tool: optional 'category' to filter rules and optional 'format' for output type.inputSchema: { type: 'object', properties: { category: { type: 'string', description: 'Filter rules by category', enum: ['types', 'styling', 'accessibility', 'composition', 'state', 'naming', 'all'], }, format: { type: 'string', description: 'Output format', enum: ['markdown', 'json', 'summary'], }, }, },
- src/tools/index.ts:58-75 (registration)Registration of the 'get_rules' tool in the getToolDefinitions() array, including name, description, and inputSchema.name: 'get_rules', description: 'Get component rules documentation. Use this to understand what rules exist and how to follow them. Can filter by category.', inputSchema: { type: 'object', properties: { category: { type: 'string', description: 'Filter rules by category', enum: ['types', 'styling', 'accessibility', 'composition', 'state', 'naming', 'all'], }, format: { type: 'string', description: 'Output format', enum: ['markdown', 'json', 'summary'], }, }, }, },
- src/tools/index.ts:237-238 (registration)Registration/dispatch of 'get_rules' in the executeTool switch statement.case 'get_rules': return handleGetRules(args);
- Helper function getRulesMarkdown() used by the handler to generate full Markdown documentation of all rules, grouped by category with examples.export function getRulesMarkdown(): string { let md = `# Component Rules Reference > Based on components.build specification by Hayden Bleasel and shadcn. --- `; const categories = [...new Set(RULES.map(r => r.category))]; for (const category of categories) { const categoryRules = RULES.filter(r => r.category === category); md += `## ${category.charAt(0).toUpperCase() + category.slice(1)} Rules\n\n`; for (const rule of categoryRules) { md += `### ${rule.name}\n`; md += `**ID:** \`${rule.id}\` | **Severity:** ${rule.severity} | **Weight:** ${rule.weight}\n\n`; md += `${rule.description}\n\n`; md += `**Bad:**\n\`\`\`tsx\n${rule.example.bad}\n\`\`\`\n\n`; md += `**Good:**\n\`\`\`tsx\n${rule.example.good}\n\`\`\`\n\n`; md += `---\n\n`; } } return md; }