create_patterns
Add multiple coding patterns to a database for AI agents to reference, enabling personalized code generation and project refactoring based on user-specific styles and conventions.
Instructions
Create multiple new coding patterns in the database
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| patterns | Yes |
Implementation Reference
- src/index.ts:66-73 (handler)The createPatterns method in PatternsManager class - this is the actual handler that executes the tool logic. It loads the database, filters out duplicates, adds new patterns, saves the database, and returns the newly created patterns.
async createPatterns(patterns: Pattern[]): Promise<Pattern[]> { const database = await this.loadDatabase(); const newPatterns = patterns.filter(p => !database.patterns.some(existingPattern => existingPattern.name === p.name)); database.patterns.push(...newPatterns); await this.saveDatabase(database); return newPatterns; } - src/index.ts:24-31 (schema)The Pattern interface defines the type/structure for pattern objects, including name, category, description, use_cases, technologies, and code_examples fields.
interface Pattern { name: string; category: string; description: string; use_cases: string[]; technologies: string[]; code_examples: { [language: string]: string }; } - src/index.ts:159-195 (registration)Tool registration in the ListToolsRequestSchema handler. Defines the tool name 'create_patterns', its description, and the complete inputSchema with validation for the patterns array and all required fields.
{ name: "create_patterns", description: "Create multiple new coding patterns in the database", inputSchema: { type: "object", properties: { patterns: { type: "array", items: { type: "object", properties: { name: { type: "string", description: "The unique name of the pattern" }, category: { type: "string", description: "The category of the pattern (e.g., Backend, Frontend, Database)" }, description: { type: "string", description: "A description of what this pattern does" }, use_cases: { type: "array", items: { type: "string" }, description: "An array of use cases where this pattern applies" }, technologies: { type: "array", items: { type: "string" }, description: "An array of technologies this pattern uses" }, code_examples: { type: "object", additionalProperties: { type: "string" }, description: "Code examples keyed by programming language" }, }, required: ["name", "category", "description", "use_cases", "technologies", "code_examples"], }, }, }, required: ["patterns"], }, }, - src/index.ts:306-308 (handler)The switch case handler in CallToolRequestSchema that routes 'create_patterns' tool calls to the patternsManager.createPatterns method and returns the result as JSON.
switch (name) { case "create_patterns": return { content: [{ type: "text", text: JSON.stringify(await patternsManager.createPatterns(args.patterns as Pattern[]), null, 2) }] };