get_profile_context
Retrieve repository context using profile settings to analyze and process code files. Configurable with refresh option to update file selection for accurate, real-time insights.
Instructions
Get repository context based on current profile settings
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| refresh | No | Whether to refresh file selection before generating context |
Implementation Reference
- src/index.ts:388-400 (registration)Registration of the get_profile_context tool in the MCP server capabilities, including description and input schema.get_profile_context: { description: 'Get repository context based on current profile settings. Includes directory structure, file contents, and code outlines based on profile configuration.', inputSchema: { type: 'object', properties: { refresh: { type: 'boolean', description: 'Whether to refresh file selection before generating context', default: false } } } },
- src/index.ts:1044-1183 (handler)Main handler implementation for get_profile_context. Fetches active profile, refreshes file lists if needed, processes full content files and outline files with code analysis, generates project structure, stats, and returns enriched context.private async handleGetProfileContext(args: any) { try { const { refresh = false } = args; const spec = await this.profileService.getActiveProfile(); const state = this.profileService.getState(); if (refresh || !state.full_files) { await this.profileService.selectFiles(); } // Read full content files const files = await Promise.all(state.full_files.map(async (path) => { try { const metadata = await this.getFileMetadata(path); const content = await this.processFile(path, metadata); const analysis = await this.codeAnalysisService.analyzeCode(content.content, path); return { ...content, analysis: { metrics: analysis.metrics, complexity: analysis.complexity_metrics.cyclomaticComplexity, maintainability: analysis.complexity_metrics.maintainabilityIndex, quality_issues: analysis.metrics.quality.longLines + analysis.metrics.quality.duplicateLines + analysis.metrics.quality.complexFunctions } }; } catch (error) { await this.loggingService.error('Error processing file', error as Error, { filePath: path, operation: 'get_profile_context' }); return null; } })).then(results => results.filter((f): f is NonNullable<typeof f> => f !== null)); // Generate outlines for selected files const outlines = await Promise.all(state.outline_files.map(async (path) => { try { const metadata = await this.getFileMetadata(path); const content = await this.processFile(path, metadata); const analysis = await this.codeAnalysisService.analyzeCode(content.content, path); return { path, outline: analysis.outline, metadata, analysis: { metrics: analysis.metrics, complexity: analysis.complexity_metrics.cyclomaticComplexity, maintainability: analysis.complexity_metrics.maintainabilityIndex } }; } catch (error) { await this.loggingService.error('Error generating outline', error as Error, { filePath: path, operation: 'get_profile_context' }); return null; } })).then(results => results.filter((o): o is NonNullable<typeof o> => o !== null)); const structure = await this.generateStructure(spec.profile.settings.no_media); // Get prompt if profile specifies it let prompt = ''; if (spec.profile.prompt) { prompt = await this.templateService.getPrompt(); } // Enhanced context with LLM-friendly metadata const context = { project_name: path.basename(process.cwd()), project_root: process.cwd(), timestamp: new Date(state.timestamp).toISOString(), profile: { name: spec.profile.name, description: spec.profile.description || 'Default profile settings', settings: spec.profile.settings }, stats: { total_files: files.length + outlines.length, full_content_files: files.length, outline_files: outlines.length, excluded_files: state.excluded_files?.length || 0, code_metrics: { total_lines: files.reduce((sum, f) => sum + f.analysis.metrics.lineCount.total, 0), code_lines: files.reduce((sum, f) => sum + f.analysis.metrics.lineCount.code, 0), comment_lines: files.reduce((sum, f) => sum + f.analysis.metrics.lineCount.comment, 0), average_complexity: files.length > 0 ? files.reduce((sum, f) => sum + f.analysis.complexity, 0) / files.length : 0, quality_issues: files.reduce((sum, f) => sum + f.analysis.quality_issues, 0) } }, prompt, files: files.map(f => ({ ...f, language: path.extname(f.path).slice(1) || 'text', metadata: { ...f.metadata, relative_path: path.relative(process.cwd(), f.path), file_type: this.getFileType(f.path), last_modified_relative: this.getRelativeTime(new Date(f.metadata.modifiedTime)), analysis: f.analysis } })), highlights: outlines.map(o => ({ ...o, metadata: { ...o.metadata, relative_path: path.relative(process.cwd(), o.path), file_type: this.getFileType(o.path), last_modified_relative: this.getRelativeTime(new Date(o.metadata.modifiedTime)), analysis: o.analysis } })), folder_structure_diagram: structure, tools: { file_access: { name: 'lc-get-files', description: 'Retrieve specific file contents', example: { path: process.cwd(), files: ['example/path/file.ts'] } }, search: { name: 'search_context', description: 'Search for patterns in files', example: { pattern: 'searchTerm', path: process.cwd() } }, changes: { name: 'lc-list-modified-files', description: 'Track file changes since context generation', example: { timestamp: state.timestamp } } } }; return this.createJsonResponse(context); } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to get profile context: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
- Helper method in ProfileService used by the handler to select and filter files based on active profile settings when refresh is true.public async selectFiles(): Promise<void> { if (!this.activeProfile) { throw new Error('No active profile'); } const fullFiles = await this.getFilteredFiles( this.activeProfile.gitignores.full_files, this.activeProfile.only_includes.full_files ); const outlineFiles = await this.getFilteredFiles( this.activeProfile.gitignores.outline_files, this.activeProfile.only_includes.outline_files ); this.state = { ...this.state, full_files: fullFiles, outline_files: outlineFiles, timestamp: Date.now() }; await this.saveState(); }
- Helper method to retrieve the active profile, used in the handler.public async getActiveProfile(): Promise<{ profile: Profile }> { if (!this.activeProfile) { throw new Error('No active profile'); } return { profile: this.activeProfile }; }
- Helper method to get current profile state including selected full_files and outline_files, used in the handler.public getState(): ProfileState { return this.state; }