UNPKG

@codewithdan/ai-repo-adventure-mcp

Version:

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

53 lines 2.35 kB
/** * Start Adventure Tool * * Transforms any codebase into an interactive adventure using repomix analysis * and LLM-powered storytelling. */ import { z } from 'zod'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; import { repoAnalyzer } from '@ai-repo-adventures/core/analyzer'; import { formatErrorForUser, validateProjectPath, extractUniqueFilePaths } from '@ai-repo-adventures/core/shared'; import { createProjectInfo } from '@ai-repo-adventures/core'; import { formatInitialResponse } from './shared.js'; // Schema const startAdventureSchema = z.object({ projectPath: z.string().optional().describe('Path to the project directory (defaults to current directory)') }); // Tool Definition export const startAdventure = { description: `Analyze codebase and present 5 themed adventure options (🚀 Space, 🏰 Medieval, 🏛️ Ancient, 📚 Developer, ✨ Custom) for gamified code exploration.`, schema: startAdventureSchema, handler: async (args) => { // Validate project path input let projectPath; try { projectPath = validateProjectPath(args.projectPath); } catch (error) { throw new McpError(ErrorCode.InvalidParams, error instanceof Error ? error.message : 'Invalid project path'); } try { // Check if we're using targeted analysis const configuredFiles = extractUniqueFilePaths(projectPath); const isUsingConfig = configuredFiles.length > 0; // Generate repomix content and create minimal ProjectInfo const repomixContent = await repoAnalyzer.generateRepomixContext(projectPath); const projectInfo = createProjectInfo(repomixContent); return { content: [ { type: 'text', text: formatInitialResponse(projectInfo, isUsingConfig) } ] }; } catch (error) { const context = { projectPath, step: 'project_analysis' }; const formattedError = formatErrorForUser(error instanceof Error ? error : new Error(String(error)), context); throw new McpError(ErrorCode.InternalError, formattedError); } } }; //# sourceMappingURL=start-adventure.js.map