Skip to main content
Glama
PROJECT_STRUCTURE.mdβ€’13 kB
# Project Structure This document describes the organization of the MCP Codebase Index project. --- ## πŸ“ Directory Structure ``` mcp-codebase-index/ β”‚ β”œβ”€β”€ πŸ“š docs/ # All documentation β”‚ β”œβ”€β”€ README.md # Main documentation β”‚ β”œβ”€β”€ SETUP.md # Setup guide β”‚ β”œβ”€β”€ QUICK_REF.md # Quick reference β”‚ β”œβ”€β”€ CHANGELOG.md # Version history β”‚ β”œβ”€β”€ NAVIGATION.md # Navigation guide β”‚ β”œβ”€β”€ COPILOT_INSTRUCTIONS.md # Copilot usage guide β”‚ β”‚ β”‚ β”œβ”€β”€ guides/ # Detailed guides β”‚ β”‚ β”œβ”€β”€ QDRANT_CLOUD_SETUP.md # Qdrant setup β”‚ β”‚ β”œβ”€β”€ mcp-server-guide.md # MCP development β”‚ β”‚ └── TEST_SEARCH.md # Testing guide β”‚ β”‚ β”‚ └── planning/ # Development planning β”‚ β”œβ”€β”€ IMPROVEMENT_PLAN.md # Roadmap β”‚ β”œβ”€β”€ RAGxplore.md # Research notes β”‚ └── issues/ # Issue documentation β”‚ β”œβ”€β”€ issue-1-implementation.md β”‚ β”œβ”€β”€ issue-2-rate-limiting.md β”‚ └── ... β”‚ β”œβ”€β”€ πŸ’» src/ # Source code β”‚ β”œβ”€β”€ README.md # Source code documentation β”‚ β”‚ β”‚ β”œβ”€β”€ core/ # Core business logic β”‚ β”‚ β”œβ”€β”€ indexer.ts # Code parsing & chunking β”‚ β”‚ β”œβ”€β”€ embedder.ts # Gemini embedding β”‚ β”‚ └── fileWatcher.ts # File monitoring β”‚ β”‚ β”‚ β”œβ”€β”€ storage/ # Storage layer β”‚ β”‚ └── qdrantClient.ts # Qdrant vector DB β”‚ β”‚ β”‚ β”œβ”€β”€ enhancement/ # Prompt enhancement β”‚ β”‚ β”œβ”€β”€ promptEnhancer.ts # Enhancement logic β”‚ β”‚ └── templates.ts # Enhancement templates β”‚ β”‚ β”‚ β”œβ”€β”€ visualization/ # Vector visualization β”‚ β”‚ β”œβ”€β”€ visualizer.ts # Main visualizer β”‚ β”‚ β”œβ”€β”€ reducer.ts # UMAP dimensionality reduction β”‚ β”‚ β”œβ”€β”€ vectorRetriever.ts # Vector fetching β”‚ β”‚ β”œβ”€β”€ exporter.ts # Format exporters β”‚ β”‚ └── types.ts # Visualization types β”‚ β”‚ β”‚ β”œβ”€β”€ mcp/ # MCP server layer β”‚ β”‚ β”œβ”€β”€ server.ts # MCP server orchestration (1237 lines) β”‚ β”‚ β”œβ”€β”€ handlers/ # Modular handler functions β”‚ β”‚ β”‚ β”œβ”€β”€ search.handler.ts # Search functionality (74 lines) β”‚ β”‚ β”‚ β”œβ”€β”€ enhancement.handler.ts # Prompt enhancement (131 lines) β”‚ β”‚ β”‚ β”œβ”€β”€ visualization.handler.ts # Visualizations (296 lines) β”‚ β”‚ β”‚ └── indexing.handler.ts # Index management (544 lines) β”‚ β”‚ β”œβ”€β”€ templates/ # HTML templates β”‚ β”‚ β”‚ └── visualization.template.ts # Modern HTML UI β”‚ β”‚ └── types/ # Handler types β”‚ β”‚ └── handlers.types.ts # Context interfaces β”‚ β”‚ β”‚ β”œβ”€β”€ types/ # Type definitions β”‚ β”‚ └── index.ts # All TypeScript types β”‚ β”‚ β”‚ └── index.ts # Entry point β”‚ β”œβ”€β”€ βš™οΈ config/ # Configuration files β”‚ β”œβ”€β”€ README.md # Config documentation β”‚ └── vscode_settings.example.json # VS Code settings example β”‚ β”œβ”€β”€ πŸ“¦ .data/ # Runtime data (gitignored) β”‚ β”œβ”€β”€ memory/ # Index state & metadata β”‚ └── vector_storage/ # Local vector cache β”‚ β”œβ”€β”€ πŸ—οΈ dist/ # Build output (gitignored) β”‚ └── (compiled JavaScript files) β”‚ β”œβ”€β”€ πŸ“„ Root Files β”‚ β”œβ”€β”€ README.md # Project overview β”‚ β”œβ”€β”€ PROJECT_STRUCTURE.md # This file β”‚ β”œβ”€β”€ package.json # NPM package config β”‚ β”œβ”€β”€ package-lock.json # NPM lock file β”‚ β”œβ”€β”€ tsconfig.json # TypeScript config β”‚ β”œβ”€β”€ .gitignore # Git ignore rules β”‚ β”œβ”€β”€ .env.example # Environment variables example β”‚ └── vscode_settings.local.json # Local VS Code settings β”‚ └── πŸ“¦ node_modules/ # Dependencies (gitignored) ``` --- ## 🎯 Design Principles ### 1. **Separation of Concerns** Each directory has a clear, single responsibility: - `docs/` - All documentation - `src/core/` - Business logic - `src/storage/` - Data persistence - `src/enhancement/` - Optional features - `src/visualization/` - Vector visualization - `src/mcp/` - Protocol layer - `handlers/` - Modular handler functions - `templates/` - HTML templates - `types/` - Handler-specific types - `src/types/` - Shared type definitions ### 2. **Modular Handler Architecture (v1.5.4-beta.19)** The MCP server uses a **context injection pattern** for clean handler separation: **Structure:** ```typescript // Server orchestrates class CodebaseIndexMCPServer { private async handleSearch(args: any) { const context: SearchHandlerContext = { embedder: this.embedder, vectorStore: this.vectorStore }; return await handleSearch(args, context); } } // Handler executes export async function handleSearch( args: any, context: SearchHandlerContext ) { // Implementation with injected dependencies } ``` **Benefits:** - **Testability**: Handlers can be tested in isolation - **Maintainability**: Clear dependencies via context interfaces - **Scalability**: Easy to add new handlers - **Readability**: Reduced from 2060 to 1237 lines in server.ts **Handler Modules:** - `search.handler.ts` - Search functionality (74 lines) - `enhancement.handler.ts` - Prompt enhancement (131 lines) - `visualization.handler.ts` - Vector visualizations (296 lines) - `indexing.handler.ts` - Index management (544 lines) ### 3. **Clean Root Directory** Only essential files at root level: - Package management: `package.json`, `package-lock.json` - Configuration: `tsconfig.json`, `.gitignore`, `.env.example` - Documentation: `README.md`, `PROJECT_STRUCTURE.md` ### 4. **Documentation First** - Every major directory has a README.md - Navigation guide helps users find what they need - Examples and guides for common tasks ### 5. **Scalability** - Easy to add new features (create new folder in `src/`) - Easy to add new handlers (create new handler file) - Easy to add new docs (add to `docs/guides/`) - Easy to find files (logical grouping) --- ## πŸ“– Key Files ### Entry Points | File | Purpose | |------|---------| | `src/index.ts` | Application entry point | | `README.md` | Project overview | | `docs/README.md` | Main documentation | ### Configuration | File | Purpose | |------|---------| | `tsconfig.json` | TypeScript compiler config | | `package.json` | NPM package config | | `.env.example` | Environment variables template | | `config/vscode_settings.example.json` | VS Code MCP config | ### Documentation | File | Purpose | |------|---------| | `docs/SETUP.md` | Installation guide | | `docs/NAVIGATION.md` | Find any doc quickly | | `docs/QUICK_REF.md` | Command reference | | `src/README.md` | Source code guide | --- ## πŸ”„ Import Paths After restructuring, import paths follow this pattern: ```typescript // From src/index.ts import { CodebaseIndexMCPServer } from './mcp/server.js'; // From src/mcp/server.ts import { CodeIndexer } from '../core/indexer.js'; import { CodeEmbedder } from '../core/embedder.js'; import { QdrantVectorStore } from '../storage/qdrantClient.js'; import { PromptEnhancer } from '../enhancement/promptEnhancer.js'; import { VectorVisualizer } from '../visualization/visualizer.js'; import { IndexerConfig } from '../types/index.js'; // Import handlers (v1.5.4-beta.19+) import { handleSearch, SearchHandlerContext } from './handlers/search.handler.js'; import { handleEnhancePrompt, handleEnhancementTelemetry, EnhancementHandlerContext } from './handlers/enhancement.handler.js'; import { handleVisualizeCollection, handleVisualizeQuery, handleExportVisualizationHtml, VisualizationHandlerContext } from './handlers/visualization.handler.js'; import { handleIndexingStatus, handleCheckIndex, handleRepairIndex, IndexingHandlerContext } from './handlers/indexing.handler.js'; // From handlers import { CodeEmbedder } from '../../core/embedder.js'; import { QdrantVectorStore } from '../../storage/qdrantClient.js'; import { VectorVisualizer } from '../../visualization/visualizer.js'; // From src/core/indexer.ts import { CodeChunk } from '../types/index.js'; ``` **Note:** Always use `.js` extension (required for ES modules) --- ## πŸ—‚οΈ File Organization Rules ### Source Code (`src/`) - **One class per file** (e.g., `CodeIndexer` in `indexer.ts`) - **One handler per function** (e.g., `handleSearch` in `search.handler.ts`) - **Group by domain** (core, storage, enhancement, visualization, mcp) - **Handlers in mcp/handlers/** (modular functions with context injection) - **Types in separate folder** (`types/index.ts` for shared, `mcp/types/` for handlers) ### Handler Files (`src/mcp/handlers/`) - **Export context interface** (e.g., `SearchHandlerContext`) - **Export handler function** (e.g., `handleSearch`) - **Pure functions** (no state, dependencies via context) - **Descriptive names** (e.g., `search.handler.ts`, `indexing.handler.ts`) ### Documentation (`docs/`) - **Main docs at root** (README, SETUP, CHANGELOG) - **Guides in guides/** (detailed tutorials) - **Planning in planning/** (roadmap, issues) ### Configuration (`config/`) - **Example files only** (actual configs are gitignored) - **One config per file** (clear purpose) --- ## 🚫 Gitignored Directories These directories are created at runtime and not tracked by git: ``` .data/ # Runtime data β”œβ”€β”€ memory/ # Index state & metadata └── vector_storage/ # Local vector cache dist/ # Build output node_modules/ # Dependencies ``` --- ## πŸ“Š File Count by Type | Type | Count | Location | |------|-------|----------| | TypeScript Source | 9 | `src/` | | Documentation | 20+ | `docs/` | | Configuration | 3 | `config/`, root | | Build Output | Auto-generated | `dist/` | --- ## πŸ” Finding Files ### "Where is the MCP server implementation?" β†’ `src/mcp/server.ts` ### "Where is the indexing logic?" β†’ `src/core/indexer.ts` ### "Where is the setup guide?" β†’ `docs/SETUP.md` ### "Where are the type definitions?" β†’ `src/types/index.ts` ### "Where is the Qdrant client?" β†’ `src/storage/qdrantClient.ts` ### "Where is prompt enhancement?" β†’ `src/enhancement/promptEnhancer.ts` ### "Where are the enhancement templates?" β†’ `src/enhancement/templates.ts` --- ## πŸ› οΈ Build Process ``` src/ β†’ tsc β†’ dist/ β”œβ”€β”€ core/ β”œβ”€β”€ core/ β”œβ”€β”€ storage/ β”œβ”€β”€ storage/ β”œβ”€β”€ enhancement/ β”œβ”€β”€ enhancement/ β”œβ”€β”€ mcp/ β”œβ”€β”€ mcp/ β”œβ”€β”€ types/ β”œβ”€β”€ types/ └── index.ts └── index.js ``` **Command:** `npm run build` **Output:** JavaScript files in `dist/` with source maps and type declarations --- ## πŸ“ Adding New Features ### 1. Add Source Code ``` src/ └── new-feature/ β”œβ”€β”€ featureLogic.ts └── featureTypes.ts (if needed) ``` ### 2. Add Documentation ``` docs/ β”œβ”€β”€ planning/issues/ β”‚ └── issue-N-new-feature.md └── guides/ └── new-feature-guide.md (if needed) ``` ### 3. Update Types ```typescript // src/types/index.ts export interface NewFeatureConfig { // ... } ``` ### 4. Integrate ```typescript // src/mcp/server.ts import { NewFeature } from '../new-feature/featureLogic.js'; ``` --- ## πŸŽ“ Learning the Codebase **Recommended reading order:** 1. **[README.md](./README.md)** - Project overview 2. **[docs/SETUP.md](./docs/SETUP.md)** - How to set up 3. **[src/README.md](./src/README.md)** - Code structure 4. **[src/index.ts](./src/index.ts)** - Entry point 5. **[src/mcp/server.ts](./src/mcp/server.ts)** - Main server logic 6. **[src/types/index.ts](./src/types/index.ts)** - Type definitions 7. **Individual components** - Dive into specific features --- ## πŸ“ž Questions? - **Documentation:** [docs/NAVIGATION.md](./docs/NAVIGATION.md) - **Issues:** [GitHub Issues](https://github.com/NgoTaiCo/mcp-codebase-index/issues) - **Email:** ngotaico.flutter@gmail.com --- **Last Updated:** 2024-11-10

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/NgoTaiCo/mcp-codebase-index'

If you have feedback or need assistance with the MCP directory API, please join our Discord server