create_lesson
Generate structured lessons from errors by analyzing their patterns, context, and solutions. Store and manage lessons in a knowledge graph to improve future problem-solving and knowledge retention.
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)The core handler function `createLesson` in the KnowledgeGraphManager class. It validates the input lesson entity, checks for existing lessons with the same name, initializes metadata, adds the lesson to the knowledge graph entities, persists the graph, 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:1096-1165 (registration)The MCP tool registration for 'create_lesson' including its name, description, and comprehensive JSON input schema defining the expected LessonEntity structure.{ 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:69-73 (schema)TypeScript interface definition for LessonEntity, extending Entity with specific fields for lessons: errorPattern, metadata, and verificationSteps. Used for type safety in the handler.interface LessonEntity extends Entity { errorPattern: ErrorPattern; metadata: Metadata; verificationSteps: VerificationStep[]; }
- index.ts:1244-1245 (registration)Dispatch case in the CallToolRequestSchema handler that invokes the createLesson handler with parsed arguments and formats the response.case "create_lesson": return { content: [{ type: "text", text: JSON.stringify(await knowledgeGraphManager.createLesson(args.lesson as LessonEntity), null, 2) }] };