search_design_rules
Search design rules by keyword to retrieve specific design guidelines for components, colors, spacing, and icons within the Modus design system.
Instructions
Search across all design rules by keyword or term.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query for design rules (e.g., "primary color", "icon size", "spacing scale") |
Implementation Reference
- src/index.ts:581-639 (handler)The searchDesignRules method (lines 581-639) is the handler that executes the 'search_design_rules' tool logic. It normalizes the query, iterates over all loaded rules, checks if the query matches category name or content, extracts a description, and returns formatted results (or a 'not found' message).
private async searchDesignRules(query: string): Promise<any> { const normalizedQuery = query.toLowerCase(); const results: Array<{ category: string; filename: string; relevance: string; }> = []; for (const rule of this.rules) { const content = rule.content.toLowerCase(); const categoryName = rule.category.toLowerCase(); if ( categoryName.includes(normalizedQuery) || content.includes(normalizedQuery) ) { // Extract the first meaningful line as description const lines = rule.content.split("\n"); let description = ""; for (const line of lines) { if (line.trim() && !line.startsWith("#") && !line.startsWith("---")) { description = line.trim(); break; } } results.push({ category: rule.category, filename: rule.filename, relevance: description || "Design rule documentation", }); } } if (results.length === 0) { return { content: [ { type: "text", text: `No design rules found matching "${query}". Try searching for terms like "color", "icon", "spacing", "typography", etc.`, }, ], }; } const resultText = results .map((r) => `**${r.category}**\n${r.relevance}\n`) .join("\n"); return { content: [ { type: "text", text: `Found ${results.length} design rule(s) matching "${query}":\n\n${resultText}`, }, ], }; } - src/index.ts:238-252 (schema)The tool registration schema for 'search_design_rules' (lines 238-252) defines the tool's name, description, and input schema with a required 'query' string property.
{ name: "search_design_rules", description: "Search across all design rules by keyword or term.", inputSchema: { type: "object", properties: { query: { type: "string", description: 'Search query for design rules (e.g., "primary color", "icon size", "spacing scale")', }, }, required: ["query"], }, }, - src/index.ts:238-252 (registration)The tool is registered in the ListToolsRequestSchema handler (line 238-252) as part of the tools array, and its case branch in the CallToolRequestSchema handler (lines 323-324) dispatches to searchDesignRules.
{ name: "search_design_rules", description: "Search across all design rules by keyword or term.", inputSchema: { type: "object", properties: { query: { type: "string", description: 'Search query for design rules (e.g., "primary color", "icon size", "spacing scale")', }, }, required: ["query"], }, }, - src/index.ts:323-324 (registration)The switch-case branch (lines 323-324) in the CallToolRequestSchema handler dispatches the 'search_design_rules' tool call to the searchDesignRules method with the query argument.
case "search_design_rules": return await this.searchDesignRules((args?.query as string) || ""); - src/index.ts:112-133 (helper)The loadRules method (lines 112-133) loads the design rule markdown files from the rules directory into this.rules, which searchDesignRules iterates over to find matches.
private loadRules(): void { if (!existsSync(this.rulesPath)) { console.error(`Rules directory not found at: ${this.rulesPath}`); console.error("Please run: node download-docs.js"); return; } const files = readdirSync(this.rulesPath).filter((f) => f.endsWith(".md")); for (const file of files) { const content = readFileSync(join(this.rulesPath, file), "utf-8"); const category = file.replace(".md", "").replace("modus_", ""); this.rules.push({ filename: file, category, content, }); } console.error(`Loaded ${this.rules.length} design rules files`); }