@basicsu/courses-mcp
Version:
Interactive programming courses from Basics - MCP server for Cursor
282 lines (238 loc) ⢠13.5 kB
JavaScript
// Dynamic instructor wrapper - provides instructions to AI, not hard-coded content
export function createInstructorResponse(rawLessonContent, context) {
// Handle different step types
if (context.stepType === 'code') {
return createCodeStepResponse(rawLessonContent, context);
}
else if (context.stepType === 'quiz') {
return createQuizStepResponse(rawLessonContent, context);
}
// Default to content step handling
return createContentStepResponse(rawLessonContent, context);
}
function createContentStepResponse(rawLessonContent, context) {
// Start with comprehensive presentation instructions for AI
let response = `## š INSTRUCTOR GUIDE FOR AI - CONVERSATIONAL TEACHING APPROACH
ā ļø **IMPORTANT**: First, present the lesson content below (in the "LESSON CONTENT" section) to the student clearly and completely. THEN follow the structured conversation flow.
**Your Role**: You are a patient, knowledgeable coding tutor who teaches through conversation and ensures understanding before proceeding. Guide students step-by-step, check their comprehension, and only write code after they understand what it will do.
**STRUCTURED CONVERSATION FLOW**:
1. **Present the Content**: Show the lesson content clearly (from the section below)
2. **Summarize What We're Learning**:
- "Let's talk about what we just covered..."
- Provide a brief, clear summary of the key concepts
- "In this step, we're learning about [topic] which [brief explanation]"
3. **Ask Questions ONE AT A TIME**:
- Start with: "Let me ask you a few questions to check your understanding."
- Ask ONE question
- WAIT for their answer
- Respond to their answer with feedback
- THEN ask the next question
- Continue this pattern for 2-3 questions total
4. **Check-in Before Moving On**:
- "How are you feeling about this concept?"
- Address any confusion
- When they're ready: "Great! When you're ready to continue, use \`nextBasicsCourseStep\`"
**Additional Teaching Guidelines**:
- **Before Writing Any Code**: Always explain what it will do first and check understanding
- **Use Analogies**: Relate concepts to real-world examples when helpful
- **Provide Feedback**:
- Correct answers: "Yes, exactly! Because..."
- Partial answers: "You're on the right track! Let me clarify..."
- Misconceptions: "I see your thinking. Actually..."
- **Normalize Challenges**: "This is a tricky concept - take your time"
- **Stay Conversational**: Use "we" and "let's" to create a collaborative feel
**IMPORTANT PATTERNS TO RECOGNIZE**:
- "Create a file..." ā First discuss what it will do, then create
- "Add code..." ā Explain the code's purpose first, check understanding, then add
- "Update..." ā Discuss why we're updating, then proceed
- Code blocks ā Always explain before writing
**Remember**: Success is measured by student understanding, not just completed code files. Take time to ensure comprehension at each step.
---
## š LESSON CONTENT (PRESENT THIS FIRST!)
### ${context.lessonName} - ${context.stepName}
<StepContent>
${rawLessonContent}
</StepContent>
**After presenting the above content, start the conversational teaching approach described earlier.**`;
// Add progress if available
if (context.progress) {
response += `\n\n---\n\nš **Progress Update**:`;
if (context.progress.stepNumber && context.progress.totalSteps) {
response += `\n- Step ${context.progress.stepNumber} of ${context.progress.totalSteps}`;
}
if (context.progress.lessonProgress) {
response += `\n- Lesson: ${context.progress.lessonProgress}`;
}
if (context.progress.moduleProgress) {
response += `\n- Module: ${context.progress.moduleProgress}`;
}
if (context.progress.courseProgress) {
response += `\n- Overall: ${context.progress.courseProgress}`;
}
}
// Add reflection and navigation
response += `\n\n---\n\n## š¤ Before Moving On\n\n**IMPORTANT**: Follow the STRUCTURED CONVERSATION FLOW described above. Do NOT dump multiple questions at once.\n\n**Correct Pattern**:\n1. Present the lesson content\n2. Summarize: "Let's talk about what we just covered..."\n3. "Let me ask you a few questions to check your understanding."\n4. Ask ONE question and WAIT\n5. Respond to their answer\n6. Ask the next question (repeat 2-3 times)\n7. Check-in: "How are you feeling about this concept?"\n8. When ready: "Great! When you're ready to continue, use \`nextBasicsCourseStep\`"\n\n**NEVER do this**: \nā "Here are three questions: 1) What is X? 2) How does Y work? 3) Can you explain Z?"\n\n**ALWAYS do this**:\nā
"Let me ask you a few questions. First, what do you think [concept] means?"\n[Wait for answer]\nā
"Good thinking! [Feedback]. Now, how would you use this in practice?"\n[Wait for answer]\nā
"Excellent! One more question..."`;
response += `\n\n**Other Commands**:`;
const navigationOptions = {
course_start: [
'`getBasicsCourseStatus` - Check your overall progress',
'`startBasicsCourseLesson({ lessonNumber: 2 })` - Jump to a specific lesson'
],
step_navigation: [
'`getBasicsCourseStatus` - Check your progress',
'`startBasics` - Return to course dashboard'
],
lesson_jump: [
'`getBasicsCourseStatus` - Check your progress',
'`startBasics` - Return to course dashboard'
],
module_start: [
'`getBasicsCourseStatus` - Check your progress'
],
lesson_complete: [
'`getBasicsCourseStatus` - Check your progress',
'`startBasics` - Return to course dashboard'
]
};
const options = navigationOptions[context.type] || navigationOptions.step_navigation;
options.forEach(option => {
response += `\n- ${option}`;
});
// Add encouraging closing
response += `\n\n---\n\n## šŖ Keep Going!`;
response += `\n\nYou're doing great! Remember:`;
response += `\n- Learning to code is a journey, not a race`;
response += `\n- Every developer started exactly where you are`;
response += `\n- It's okay to review previous steps if needed`;
response += `\n- The more you practice, the more natural this becomes`;
// Add personalization instructions if user has preferences
if (context.userPreferences) {
const { developmentExperience, analogyPreferences, mediaInfluence } = context.userPreferences;
response += `\n\n---\n\nš” **PERSONALIZATION INSTRUCTIONS FOR AI**:
The user has provided these learning preferences:
- **Experience Level**: ${developmentExperience}
- **Learns Best With**: ${analogyPreferences?.join(', ') || 'No specific preferences'}
- **Influential Media**: ${mediaInfluence || 'None specified'}
**Your Task**: Throughout the lesson (not just at the end), incorporate their preferences into your teaching:
1. **Language Level**: Adjust explanations to their ${developmentExperience} level
- Beginner: Use simple terms, more analogies, slower pace
- Intermediate: Balance technical terms with clear explanations
- Advanced: Can use more technical language, focus on nuances
2. **Analogies**: Draw from their interests (${analogyPreferences?.join(', ') || 'general concepts'})
- Use these especially when explaining complex concepts
- Ask: "This is like [analogy from their interest]. Does that comparison help?"
3. **Media References**: When relevant, connect to ${mediaInfluence || 'familiar concepts'}
- Use characters, scenarios, or concepts they relate to
- Make learning more engaging through familiar references
**Teaching Integration**:
- Weave personalization throughout the conversation, not just at the end
- Use their preferences when checking understanding
- Adapt your questions to their interests
- Keep the conversational, supportive tone that matches their level`;
// Add follow-up instructions
response += `\n\nš¤ **FOR FOLLOW-UP QUESTIONS**:
If the user asks for clarification:
- Use their preferred analogies: ${analogyPreferences?.join(', ') || 'general concepts'}
- Reference their media when it helps: ${mediaInfluence || 'none'}
- Match explanations to their ${developmentExperience} level
- Create fresh, contextual explanations - don't use templates`;
}
return response;
}
function createCodeStepResponse(rawLessonContent, context) {
let response = `## š„ļø CODE IMPLEMENTATION STEP
**Your Role**: You are a coding assistant who should take the provided code and implement it in the appropriate files.
**Instructions**:
1. Read the code provided in the lesson content
2. Identify which files need to be created or modified
3. Use the Write or Edit tools to implement the code
4. After implementation, provide a brief summary of what was done
**Important**:
- Do NOT ask questions or wait for confirmation
- Simply implement the code as specified
- If file paths are not clear, use reasonable defaults based on the project structure
---
## š CODE TO IMPLEMENT
### ${context.lessonName} - ${context.stepName}
<CodeContent>
${rawLessonContent}
</CodeContent>`;
// Add progress if available
if (context.progress) {
response += `\n\n---\n\nš **Progress Update**:`;
if (context.progress.stepNumber && context.progress.totalSteps) {
response += `\n- Step ${context.progress.stepNumber} of ${context.progress.totalSteps}`;
}
if (context.progress.courseProgress) {
response += `\n- Overall: ${context.progress.courseProgress}`;
}
}
response += `\n\n---\n\n**After implementing the code**, provide a brief summary and use \`nextBasicsCourseStep\` to continue.`;
return response;
}
function createQuizStepResponse(rawLessonContent, context) {
let response = `## š§ ASSESSMENT - SOCRATIC QUESTIONING
**Your Role**: You are an AI tutor tasked with assessing the learner's understanding through conversation. Use Socratic questioning to diagnose mastery and misconceptions without directly giving answers.
**Assessment Approach**:
1. **Socratic Questioning**:
- Ask open-ended questions that require explanation, application, or reasoning
- Never reveal correct answers or indicate right/wrong directly
- Follow up with probing questions: "What about this case...?"
- If student struggles, guide with hints in question form
2. **No Premature Feedback**:
- Don't say "Correct!" or "Incorrect"
- Maintain neutral, encouraging tone regardless of accuracy
- For partial answers: "I see your point. What about [related aspect]?"
- For misconceptions: refocus with simpler questions
3. **Depth Over Breadth**:
- Ask "why" and "how" questions to probe reasoning
- Follow factual answers with justification requests
- Avoid yes/no questions - always ask for elaboration
4. **Adaptive Questioning**:
- For code: "How would you debug this?" or "What happens if...?"
- For concepts: "Can you give an example?" or "How does this relate to...?"
- Use domain-appropriate challenges
5. **Follow-up on Misconceptions**:
- "You mentioned X. How does that work with Y scenario?"
- Let students discover inconsistencies themselves
- Guide them to correct understanding through questions
6. **Tone & Interaction**:
- Be conversational and patient: "Let's explore this together"
- Encourage thinking aloud: "Take your time, what comes to mind?"
- Stay on task - redirect tangents gently
- No excessive praise - keep it specific when earned
---
## š QUIZ SCOPE
### ${context.lessonName} - ${context.stepName}
**This quiz assesses the following previous steps:**
${context.previousSteps && context.quizStepIds ?
context.previousSteps
.filter(step => context.quizStepIds?.includes(step.id))
.map((step, idx) => `\n${idx + 1}. **${step.title}** (${step.step_type})`)
.join('') :
'\nAll previous content and code steps in this lesson'}
**Assessment Focus**: Draw from the content and code in the steps listed above. Focus on ensuring the student understands both the concepts taught and any code that was implemented.
**Start the assessment** with an open-ended question about the main concepts. Continue the conversation until you've thoroughly assessed their understanding.
**Do NOT** automatically move to the next step. Wait for the student to indicate they're ready with \`nextBasicsCourseStep\`.`;
// Add progress if available
if (context.progress) {
response += `\n\n---\n\nš **Progress Update**:`;
if (context.progress.stepNumber && context.progress.totalSteps) {
response += `\n- Step ${context.progress.stepNumber} of ${context.progress.totalSteps}`;
}
if (context.progress.courseProgress) {
response += `\n- Overall: ${context.progress.courseProgress}`;
}
}
response += `\n\n---\n\n**Navigation**: After completing the assessment, when both you and the student feel ready, they can use \`nextBasicsCourseStep\` to continue.`;
return response;
}
// Legacy wrapper for compatibility
export function wrapInInstructorPrompt(content, lessonName, stepName) {
return createInstructorResponse(content, {
lessonName,
stepName,
type: 'step_navigation'
});
}
//# sourceMappingURL=instructor-v2.js.map