add_code_examples
Extend existing coding patterns by adding new language-specific examples to enhance code generation and refactoring capabilities.
Instructions
Add new code examples to existing patterns
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| additions | Yes |
Implementation Reference
- src/index.ts:75-93 (handler)The addCodeExamples method in PatternsManager class - the core handler logic that loads the database, finds patterns by name, adds/updates code examples, saves the database, and returns results.
async addCodeExamples(additions: { patternName: string; examples: { [language: string]: string } }[]): Promise<{ patternName: string; addedExamples: { [language: string]: string } }[]> { const database = await this.loadDatabase(); const results = additions.map(a => { const pattern = database.patterns.find(p => p.name === a.patternName); if (!pattern) { throw new Error(`Pattern with name ${a.patternName} not found`); } const addedExamples: { [language: string]: string } = {}; for (const [language, code] of Object.entries(a.examples)) { if (!pattern.code_examples[language] || pattern.code_examples[language] !== code) { pattern.code_examples[language] = code; addedExamples[language] = code; } } return { patternName: a.patternName, addedExamples }; }); await this.saveDatabase(database); return results; } - src/index.ts:199-219 (schema)Input schema definition for add_code_examples tool, specifying the 'additions' array with patternName and examples properties.
inputSchema: { type: "object", properties: { additions: { type: "array", items: { type: "object", properties: { patternName: { type: "string", description: "The name of the pattern to add examples to" }, examples: { type: "object", additionalProperties: { type: "string" }, description: "Code examples keyed by programming language" }, }, required: ["patternName", "examples"], }, }, }, required: ["additions"], }, - src/index.ts:196-220 (registration)Tool registration in ListToolsRequestSchema handler, defining the tool name 'add_code_examples', description, and input schema.
{ name: "add_code_examples", description: "Add new code examples to existing patterns", inputSchema: { type: "object", properties: { additions: { type: "array", items: { type: "object", properties: { patternName: { type: "string", description: "The name of the pattern to add examples to" }, examples: { type: "object", additionalProperties: { type: "string" }, description: "Code examples keyed by programming language" }, }, required: ["patternName", "examples"], }, }, }, required: ["additions"], }, }, - src/index.ts:309-310 (handler)Switch case that dispatches 'add_code_examples' tool calls to patternsManager.addCodeExamples method with proper type casting.
case "add_code_examples": return { content: [{ type: "text", text: JSON.stringify(await patternsManager.addCodeExamples(args.additions as { patternName: string; examples: { [language: string]: string } }[]), null, 2) }] };