Skip to main content
Glama

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
NameRequiredDescriptionDefault
adrRulesNoRules extracted from ADRs
authorNoAuthor of the rule setMCP ADR Analysis Server
descriptionNoDescription of the rule setGenerated architectural rule set
nameYesName of the rule set
outputFormatNoOutput format for rule setjson
patternRulesNoRules generated from code patterns
rulesNoAdditional 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' ); } }
  • 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; }
  • 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, }; }
  • 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'; }>; }

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/tosin2013/mcp-adr-analysis-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server