create_rule_set
Generate machine-readable rule sets in JSON or YAML format for architectural decision records, combining ADR, code pattern, and custom rules for consistent analysis.
Instructions
Create machine-readable rule set in JSON/YAML format
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| adrRules | No | Rules extracted from ADRs | |
| author | No | Author of the rule set | MCP ADR Analysis Server |
| description | No | Description of the rule set | Generated architectural rule set |
| name | Yes | Name of the rule set | |
| outputFormat | No | Output format for rule set | json |
| patternRules | No | Rules generated from code patterns | |
| rules | No | Additional rules to include |
Implementation Reference
- The primary handler function for the 'create_rule_set' MCP tool. It processes input arguments, combines rules, delegates to the core createRuleSet helper, serializes to JSON/YAML, and returns a formatted MCP response with usage instructions.export async function createRuleSet(args: { name: string; description?: string; adrRules?: any[]; patternRules?: any[]; rules?: any[]; outputFormat?: 'json' | 'yaml' | 'both'; author?: string; }): Promise<any> { const { name, description = 'Generated architectural rule set', adrRules = [], patternRules = [], rules = [], outputFormat = 'json', author = 'MCP ADR Analysis Server', } = args; try { const { createRuleSet, serializeRuleSetToJson, serializeRuleSetToYaml } = await import( '../utils/rule-format.js' ); // Combine all rules const allRules = [...adrRules, ...patternRules, ...rules]; if (allRules.length === 0) { throw new McpAdrError('At least one rule must be provided', 'INVALID_INPUT'); } // Create rule set const ruleSet = createRuleSet(name, description, allRules, author); // Serialize based on output format let jsonOutput = ''; let yamlOutput = ''; if (outputFormat === 'json' || outputFormat === 'both') { jsonOutput = serializeRuleSetToJson(ruleSet); } if (outputFormat === 'yaml' || outputFormat === 'both') { yamlOutput = serializeRuleSetToYaml(ruleSet); } return { content: [ { type: 'text', text: `# Machine-Readable Rule Set Created ## Rule Set Details - **Name**: ${name} - **Description**: ${description} - **Total Rules**: ${allRules.length} - **Author**: ${author} - **Format**: ${outputFormat.toUpperCase()} - **Version**: ${ruleSet.metadata.version} ## Rule Categories ${ruleSet.categories.map(cat => `- **${cat.name}**: ${cat.ruleCount} rules (${cat.priority} priority)`).join('\n')} ## Rule Distribution - **ADR-based Rules**: ${adrRules.length} - **Pattern-based Rules**: ${patternRules.length} - **Other Rules**: ${rules.length} ${ outputFormat === 'json' || outputFormat === 'both' ? ` ## JSON Format \`\`\`json ${jsonOutput} \`\`\` ` : '' } ${ outputFormat === 'yaml' || outputFormat === 'both' ? ` ## YAML Format \`\`\`yaml ${yamlOutput} \`\`\` ` : '' } ## Usage Instructions ### Save Rule Set Save the rule set to your project: - **JSON**: \`rules/architectural-rules.json\` - **YAML**: \`rules/architectural-rules.yaml\` ### Integrate with Tools Use the rule set with validation tools: \`\`\`json { "tool": "validate_rules", "args": { "filePath": "src/components/MyComponent.tsx", "rules": [rules from this rule set] } } \`\`\` ### Version Control - Commit rule sets to version control - Track changes to rules over time - Use semantic versioning for rule set updates - Document rule changes in release notes ### Team Adoption - Share rule sets across team members - Integrate with CI/CD pipelines - Set up automated validation checks - Provide training on rule compliance ## Quality Assurance This rule set includes: - **Validation Patterns**: Automated checking capabilities - **Examples**: Valid and invalid code examples - **Severity Levels**: Appropriate priority for each rule - **Traceability**: Links to source ADRs and patterns - **Metadata**: Complete rule set documentation `, }, ], }; } catch (error) { throw new McpAdrError( `Failed to create rule set: ${error instanceof Error ? error.message : String(error)}`, 'RULE_SET_CREATION_ERROR' ); } }
- src/types/tool-arguments.ts:97-105 (schema)TypeScript interface defining the input arguments for the create_rule_set tool, matching the handler parameters.export interface CreateRuleSetArgs { name: string; description?: string; adrRules?: any[]; patternRules?: any[]; rules?: any[]; outputFormat?: 'json' | 'yaml' | 'both'; author?: string; }
- src/utils/rule-format.ts:60-103 (helper)Core utility function that constructs the RuleSet object, including metadata, categorizing rules, generating summaries, and extracting dependencies and tags. Called by the handler.export function createRuleSet( name: string, description: string, rules: ArchitecturalRule[], author: string = 'MCP ADR Analysis Server' ): RuleSet { const now = new Date().toISOString(); // Group rules by category const categoryMap = new Map<string, ArchitecturalRule[]>(); rules.forEach(rule => { const category = rule.category; if (!categoryMap.has(category)) { categoryMap.set(category, []); } categoryMap.get(category)!.push(rule); }); // Create category summaries const categories = Array.from(categoryMap.entries()).map(([name, categoryRules]) => ({ name, description: getCategoryDescription(name), priority: getCategoryPriority(name), ruleCount: categoryRules.length, })); // Extract rule dependencies const dependencies = extractRuleDependencies(rules); return { metadata: { version: '1.0.0', name, description, created: now, lastModified: now, author, tags: extractRuleTags(rules), }, rules, categories, dependencies, }; }
- src/utils/rule-format.ts:9-32 (schema)Type definition for the RuleSet structure output by the createRuleSet functions.export interface RuleSet { metadata: { version: string; name: string; description: string; created: string; lastModified: string; author: string; tags: string[]; }; rules: ArchitecturalRule[]; categories: Array<{ name: string; description: string; priority: 'low' | 'medium' | 'high' | 'critical'; ruleCount: number; }>; dependencies: Array<{ ruleId: string; dependsOn: string[]; conflictsWith: string[]; relationship: 'requires' | 'enhances' | 'conflicts' | 'supersedes'; }>; }