Skip to main content
Glama

create_rule_set

Generate machine-readable architectural rule sets in JSON or YAML format from ADR analysis and code patterns to enforce consistent software architecture decisions.

Instructions

Create machine-readable rule set in JSON/YAML format

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName of the rule set
descriptionNoDescription of the rule setGenerated architectural rule set
adrRulesNoRules extracted from ADRs
patternRulesNoRules generated from code patterns
rulesNoAdditional rules to include
outputFormatNoOutput format for rule setjson
authorNoAuthor of the rule setMCP ADR Analysis Server

Implementation Reference

  • The primary handler function for the 'create_rule_set' MCP tool. It combines input rules (ADR, pattern, or general), creates a structured RuleSet using the helper, serializes to JSON/YAML/both, and returns formatted content 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 function parameters.
    export interface CreateRuleSetArgs { name: string; description?: string; adrRules?: any[]; patternRules?: any[]; rules?: any[]; outputFormat?: 'json' | 'yaml' | 'both'; author?: string; }
  • Core helper function that transforms raw rules into a structured RuleSet object with metadata, categories, and dependencies. Called by the tool 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, }; }
  • Usage of the createRuleSet tool function within the rule-generation-resource MCP resource implementation.
    const { createRuleSet } = await import('../tools/rule-generation-tool.js'); toolResult = await createRuleSet({ name: 'Generated Rule Set', description: 'AI-generated architectural rules from ADRs and patterns', rules: [], // TODO: Provide actual rules for the set outputFormat, }); }

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