create_lesson
Create structured lessons from errors and solutions to prevent recurrence, storing insights in a knowledge graph for future reference.
Instructions
Create a new lesson from an error and its solution
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lesson | Yes |
Implementation Reference
- index.ts:720-758 (handler)Core handler function in KnowledgeGraphManager that validates the lesson input, checks for duplicates, sets metadata, adds the lesson to the graph, persists it, and returns the created lesson.
async createLesson(lesson: LessonEntity): Promise<LessonEntity> { // Validate required fields if (!lesson.name || !lesson.errorPattern || !lesson.verificationSteps) { throw new Error('Missing required fields in lesson'); } // Validate error pattern if (!lesson.errorPattern.type || !lesson.errorPattern.message || !lesson.errorPattern.context) { throw new Error('Missing required fields in error pattern'); } // Validate verification steps if (!lesson.verificationSteps.every(step => step.command && step.expectedOutput && Array.isArray(step.successIndicators) )) { throw new Error('Invalid verification steps'); } const graph = await this.loadGraph(); // Check for duplicate lesson if (graph.entities.some(e => e.name === lesson.name)) { throw new Error(`Lesson with name ${lesson.name} already exists`); } // Set metadata timestamps and initial values lesson.metadata = { ...lesson.metadata, createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), frequency: 0, successRate: 0 }; // Add to entities graph.entities.push(lesson); await this.saveGraph(graph); return lesson; } - index.ts:1099-1164 (schema)Input schema definition for the create_lesson tool, specifying the structure and validation rules for the LessonEntity input.
inputSchema: { type: "object", properties: { lesson: { type: "object", properties: { name: { type: "string", description: "Unique identifier for the lesson" }, entityType: { type: "string", enum: ["lesson"], description: "Must be 'lesson'" }, observations: { type: "array", items: { type: "string" }, description: "List of observations about the error and solution" }, errorPattern: { type: "object", properties: { type: { type: "string", description: "Category of the error" }, message: { type: "string", description: "The error message" }, context: { type: "string", description: "Where the error occurred" }, stackTrace: { type: "string", description: "Optional stack trace" } }, required: ["type", "message", "context"] }, metadata: { type: "object", properties: { severity: { type: "string", enum: ["low", "medium", "high", "critical"], description: "Severity level of the error" }, environment: { type: "object", properties: { os: { type: "string" }, nodeVersion: { type: "string" }, dependencies: { type: "object", additionalProperties: { type: "string" } } } } } }, verificationSteps: { type: "array", items: { type: "object", properties: { command: { type: "string", description: "Command to run" }, expectedOutput: { type: "string", description: "Expected output" }, successIndicators: { type: "array", items: { type: "string" }, description: "Indicators of success" } }, required: ["command", "expectedOutput", "successIndicators"] } } }, required: ["name", "entityType", "observations", "errorPattern", "verificationSteps"] } }, required: ["lesson"] } - index.ts:1096-1165 (registration)Registration of the create_lesson tool in the ListTools response, including name, description, and schema.
{ name: "create_lesson", description: "Create a new lesson from an error and its solution", inputSchema: { type: "object", properties: { lesson: { type: "object", properties: { name: { type: "string", description: "Unique identifier for the lesson" }, entityType: { type: "string", enum: ["lesson"], description: "Must be 'lesson'" }, observations: { type: "array", items: { type: "string" }, description: "List of observations about the error and solution" }, errorPattern: { type: "object", properties: { type: { type: "string", description: "Category of the error" }, message: { type: "string", description: "The error message" }, context: { type: "string", description: "Where the error occurred" }, stackTrace: { type: "string", description: "Optional stack trace" } }, required: ["type", "message", "context"] }, metadata: { type: "object", properties: { severity: { type: "string", enum: ["low", "medium", "high", "critical"], description: "Severity level of the error" }, environment: { type: "object", properties: { os: { type: "string" }, nodeVersion: { type: "string" }, dependencies: { type: "object", additionalProperties: { type: "string" } } } } } }, verificationSteps: { type: "array", items: { type: "object", properties: { command: { type: "string", description: "Command to run" }, expectedOutput: { type: "string", description: "Expected output" }, successIndicators: { type: "array", items: { type: "string" }, description: "Indicators of success" } }, required: ["command", "expectedOutput", "successIndicators"] } } }, required: ["name", "entityType", "observations", "errorPattern", "verificationSteps"] } }, required: ["lesson"] } }, - index.ts:1244-1245 (handler)MCP CallToolRequestSchema handler case that dispatches to the createLesson function with tool arguments.
case "create_lesson": return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.createLesson(args.lesson as LessonEntity), null, 2) }] }; - index.ts:69-73 (schema)TypeScript interface definition for LessonEntity used in the create_lesson tool.
interface LessonEntity extends Entity { errorPattern: ErrorPattern; metadata: Metadata; verificationSteps: VerificationStep[]; }