UNPKG

@codewithdan/ai-repo-adventure-mcp

Version:

MCP server for AI-powered code repository exploration through interactive storytelling

63 lines β€’ 2.8 kB
/** * Explore Quest Tool * * Delivers deep, workshop-style code exploration through LLM-generated * themed content with adventure.config.json guidance. */ import { z } from 'zod'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; import { validateAdventureChoice } from '@codewithdan/ai-repo-adventures-core/shared'; import { adventureManager } from '@codewithdan/ai-repo-adventures-core/adventure'; // Schema const exploreQuestSchema = z.object({ choice: z.string().describe('The quest choice - can be quest number (1, 2, 3) or quest title') }); // Tool Definition export const exploreQuest = { description: `Explore specific quest with detailed code analysis and themed narrative. Accepts quest numbers or titles for guided codebase learning.`, schema: exploreQuestSchema, handler: async (args) => { if (!adventureManager) { throw new McpError(ErrorCode.InternalError, 'Adventure manager not initialized'); } try { // Validate choice input let validatedChoice; try { validatedChoice = validateAdventureChoice(args.choice); } catch (error) { throw new McpError(ErrorCode.InvalidParams, error instanceof Error ? error.message : 'Invalid quest choice'); } // AdventureManager now handles numbered choices, titles, and IDs automatically const result = await adventureManager.exploreQuest(validatedChoice); let responseText = result.narrative; // Add progress update if available if (result.progressUpdate) { responseText += `\n\n**${result.progressUpdate}**`; } // Add available choices if (result.choices && result.choices.length > 0) { const questChoices = result.choices.filter(c => !c.includes('View progress')); const hasProgress = result.choices.includes('View progress'); responseText += `\n\n**πŸ—ΊοΈ Available Quests:**\n${questChoices.join('\n')}`; if (hasProgress) { responseText += `\n\n**πŸ“Š Other Options:**\n View progress`; } responseText += `\n\nUse \`explore_quest\` with your choice to continue your journey!`; } return { content: [ { type: 'text', text: responseText } ] }; } catch (error) { throw new McpError(ErrorCode.InternalError, `Failed to explore path: ${error instanceof Error ? error.message : String(error)}`); } } }; //# sourceMappingURL=explore-quest.js.map