mcp-code-indexer 2.4.0__py3-none-any.whl → 3.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -307,17 +307,12 @@ Return ONLY a JSON object:
307
307
  except subprocess.CalledProcessError:
308
308
  pass # No upstream remote
309
309
 
310
- # Get current branch
311
- branch_result = await self._run_git_command(["rev-parse", "--abbrev-ref", "HEAD"])
312
- branch = branch_result.strip() if branch_result else "main"
313
-
314
310
  # Extract project name from remote URL or use directory name
315
311
  project_name = self._extract_project_name(remote_origin, project_root)
316
312
 
317
313
  return {
318
314
  "projectName": project_name,
319
315
  "folderPath": str(project_root),
320
- "branch": branch,
321
316
  "remoteOrigin": remote_origin,
322
317
  "upstreamOrigin": upstream_origin
323
318
  }
@@ -515,7 +510,7 @@ Return ONLY a JSON object:
515
510
 
516
511
  if project:
517
512
  overview = await self.db_manager.get_project_overview(
518
- project.id, project_info["branch"]
513
+ project.id
519
514
  )
520
515
  return overview.overview if overview else ""
521
516
 
@@ -538,7 +533,7 @@ Return ONLY a JSON object:
538
533
 
539
534
  if project:
540
535
  descriptions = await self.db_manager.get_all_file_descriptions(
541
- project.id, project_info["branch"]
536
+ project.id
542
537
  )
543
538
  return {desc.file_path: desc.description for desc in descriptions}
544
539
 
@@ -883,7 +878,6 @@ Return ONLY a JSON object:
883
878
 
884
879
  file_desc = FileDescription(
885
880
  project_id=project.id,
886
- branch=project_info["branch"],
887
881
  file_path=file_path,
888
882
  description=description,
889
883
  file_hash=None,
@@ -901,7 +895,6 @@ Return ONLY a JSON object:
901
895
 
902
896
  overview = ProjectOverview(
903
897
  project_id=project.id,
904
- branch=project_info["branch"],
905
898
  overview=overview_update,
906
899
  last_modified=datetime.utcnow(),
907
900
  total_files=len(file_updates),
@@ -0,0 +1,100 @@
1
+ -- Initial database schema for MCP Code Indexer
2
+ -- Creates tables for projects, file descriptions, and search functionality
3
+
4
+ -- Enable WAL mode for better concurrency
5
+ PRAGMA journal_mode=WAL;
6
+
7
+ -- Enable foreign key support
8
+ PRAGMA foreign_keys=ON;
9
+
10
+ -- Projects table: stores project metadata and identification
11
+ CREATE TABLE IF NOT EXISTS projects (
12
+ id TEXT PRIMARY KEY,
13
+ name TEXT NOT NULL,
14
+ remote_origin TEXT,
15
+ upstream_origin TEXT,
16
+ aliases TEXT DEFAULT '[]', -- JSON array of aliases
17
+ created DATETIME DEFAULT CURRENT_TIMESTAMP,
18
+ last_accessed DATETIME DEFAULT CURRENT_TIMESTAMP
19
+ );
20
+
21
+ -- Index for project lookups by various identifiers
22
+ CREATE INDEX IF NOT EXISTS idx_projects_remote_origin ON projects(remote_origin);
23
+ CREATE INDEX IF NOT EXISTS idx_projects_upstream_origin ON projects(upstream_origin);
24
+ CREATE INDEX IF NOT EXISTS idx_projects_name ON projects(name);
25
+
26
+ -- File descriptions table: stores file content descriptions
27
+ CREATE TABLE IF NOT EXISTS file_descriptions (
28
+ project_id TEXT NOT NULL,
29
+ branch TEXT NOT NULL,
30
+ file_path TEXT NOT NULL,
31
+ description TEXT NOT NULL,
32
+ file_hash TEXT,
33
+ last_modified DATETIME DEFAULT CURRENT_TIMESTAMP,
34
+ version INTEGER DEFAULT 1,
35
+ source_project_id TEXT,
36
+ PRIMARY KEY (project_id, branch, file_path),
37
+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
38
+ FOREIGN KEY (source_project_id) REFERENCES projects(id) ON DELETE SET NULL
39
+ );
40
+
41
+ -- Indexes for file description queries
42
+ CREATE INDEX IF NOT EXISTS idx_file_descriptions_project_branch ON file_descriptions(project_id, branch);
43
+ CREATE INDEX IF NOT EXISTS idx_file_descriptions_file_hash ON file_descriptions(file_hash);
44
+ CREATE INDEX IF NOT EXISTS idx_file_descriptions_last_modified ON file_descriptions(last_modified);
45
+
46
+ -- Full-text search table for file descriptions
47
+ CREATE VIRTUAL TABLE IF NOT EXISTS file_descriptions_fts USING fts5(
48
+ project_id,
49
+ branch,
50
+ file_path,
51
+ description,
52
+ content='file_descriptions',
53
+ content_rowid='rowid'
54
+ );
55
+
56
+ -- Triggers to keep FTS table in sync with file_descriptions
57
+ CREATE TRIGGER IF NOT EXISTS file_descriptions_ai AFTER INSERT ON file_descriptions BEGIN
58
+ INSERT INTO file_descriptions_fts(rowid, project_id, branch, file_path, description)
59
+ VALUES (new.rowid, new.project_id, new.branch, new.file_path, new.description);
60
+ END;
61
+
62
+ CREATE TRIGGER IF NOT EXISTS file_descriptions_ad AFTER DELETE ON file_descriptions BEGIN
63
+ INSERT INTO file_descriptions_fts(file_descriptions_fts, rowid, project_id, branch, file_path, description)
64
+ VALUES ('delete', old.rowid, old.project_id, old.branch, old.file_path, old.description);
65
+ END;
66
+
67
+ CREATE TRIGGER IF NOT EXISTS file_descriptions_au AFTER UPDATE ON file_descriptions BEGIN
68
+ INSERT INTO file_descriptions_fts(file_descriptions_fts, rowid, project_id, branch, file_path, description)
69
+ VALUES ('delete', old.rowid, old.project_id, old.branch, old.file_path, old.description);
70
+ INSERT INTO file_descriptions_fts(rowid, project_id, branch, file_path, description)
71
+ VALUES (new.rowid, new.project_id, new.branch, new.file_path, new.description);
72
+ END;
73
+
74
+ -- Merge conflicts table: temporary storage for merge conflicts
75
+ CREATE TABLE IF NOT EXISTS merge_conflicts (
76
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
77
+ project_id TEXT NOT NULL,
78
+ file_path TEXT NOT NULL,
79
+ source_branch TEXT NOT NULL,
80
+ target_branch TEXT NOT NULL,
81
+ source_description TEXT NOT NULL,
82
+ target_description TEXT NOT NULL,
83
+ resolution TEXT,
84
+ created DATETIME DEFAULT CURRENT_TIMESTAMP,
85
+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
86
+ );
87
+
88
+ -- Index for merge conflict lookups
89
+ CREATE INDEX IF NOT EXISTS idx_merge_conflicts_project ON merge_conflicts(project_id, source_branch, target_branch);
90
+
91
+ -- Token cache table: cache token counts for performance
92
+ CREATE TABLE IF NOT EXISTS token_cache (
93
+ cache_key TEXT PRIMARY KEY,
94
+ token_count INTEGER NOT NULL,
95
+ created DATETIME DEFAULT CURRENT_TIMESTAMP,
96
+ expires DATETIME
97
+ );
98
+
99
+ -- Index for token cache cleanup
100
+ CREATE INDEX IF NOT EXISTS idx_token_cache_expires ON token_cache(expires);
@@ -0,0 +1,61 @@
1
+ -- Performance optimization migration for MCP Code Indexer
2
+ -- Adds additional indexes and optimizations for common query patterns
3
+
4
+ -- Additional composite indexes for performance optimization
5
+ CREATE INDEX IF NOT EXISTS idx_file_descriptions_project_branch_path ON file_descriptions(project_id, branch, file_path);
6
+ CREATE INDEX IF NOT EXISTS idx_file_descriptions_project_modified ON file_descriptions(project_id, last_modified DESC);
7
+ CREATE INDEX IF NOT EXISTS idx_file_descriptions_source_project ON file_descriptions(source_project_id) WHERE source_project_id IS NOT NULL;
8
+
9
+ -- Index for merge conflicts by project and branches
10
+ CREATE INDEX IF NOT EXISTS idx_merge_conflicts_project_branches ON merge_conflicts(project_id, source_branch, target_branch, created DESC);
11
+
12
+ -- Index for token cache expiration cleanup
13
+ CREATE INDEX IF NOT EXISTS idx_token_cache_created ON token_cache(created DESC);
14
+
15
+ -- Optimize FTS5 for prefix searches and ranking
16
+ DROP TRIGGER IF EXISTS file_descriptions_ai;
17
+ DROP TRIGGER IF EXISTS file_descriptions_ad;
18
+ DROP TRIGGER IF EXISTS file_descriptions_au;
19
+ DROP TABLE IF EXISTS file_descriptions_fts;
20
+
21
+ -- Recreate FTS table with better configuration
22
+ CREATE VIRTUAL TABLE file_descriptions_fts USING fts5(
23
+ project_id UNINDEXED,
24
+ branch UNINDEXED,
25
+ file_path,
26
+ description,
27
+ content='file_descriptions',
28
+ content_rowid='rowid',
29
+ prefix='2 3 4' -- Enable prefix searching for 2-4 character prefixes
30
+ );
31
+
32
+ -- Recreate triggers for FTS sync
33
+ CREATE TRIGGER file_descriptions_ai AFTER INSERT ON file_descriptions BEGIN
34
+ INSERT INTO file_descriptions_fts(rowid, project_id, branch, file_path, description)
35
+ VALUES (new.rowid, new.project_id, new.branch, new.file_path, new.description);
36
+ END;
37
+
38
+ CREATE TRIGGER file_descriptions_ad AFTER DELETE ON file_descriptions BEGIN
39
+ INSERT INTO file_descriptions_fts(file_descriptions_fts, rowid, project_id, branch, file_path, description)
40
+ VALUES ('delete', old.rowid, old.project_id, old.branch, old.file_path, old.description);
41
+ END;
42
+
43
+ CREATE TRIGGER file_descriptions_au AFTER UPDATE ON file_descriptions BEGIN
44
+ INSERT INTO file_descriptions_fts(file_descriptions_fts, rowid, project_id, branch, file_path, description)
45
+ VALUES ('delete', old.rowid, old.project_id, old.branch, old.file_path, old.description);
46
+ INSERT INTO file_descriptions_fts(rowid, project_id, branch, file_path, description)
47
+ VALUES (new.rowid, new.project_id, new.branch, new.file_path, new.description);
48
+ END;
49
+
50
+ -- Rebuild FTS index if there's existing data
51
+ INSERT INTO file_descriptions_fts(file_descriptions_fts) VALUES('rebuild');
52
+
53
+ -- Set SQLite optimizations
54
+ PRAGMA optimize;
55
+ PRAGMA auto_vacuum = INCREMENTAL;
56
+ PRAGMA temp_store = MEMORY;
57
+ PRAGMA mmap_size = 268435456; -- 256MB memory mapping
58
+ PRAGMA cache_size = -64000; -- 64MB cache
59
+
60
+ -- Update statistics for query planner
61
+ ANALYZE;
@@ -0,0 +1,20 @@
1
+ -- Migration 003: Add project_overviews table for condensed codebase overviews
2
+ -- This table stores comprehensive narrative overviews of entire codebases
3
+ -- as an alternative to file-by-file descriptions
4
+
5
+ CREATE TABLE IF NOT EXISTS project_overviews (
6
+ project_id TEXT NOT NULL,
7
+ branch TEXT NOT NULL,
8
+ overview TEXT NOT NULL,
9
+ last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
10
+ total_files INTEGER NOT NULL DEFAULT 0,
11
+ total_tokens INTEGER NOT NULL DEFAULT 0,
12
+ PRIMARY KEY (project_id, branch),
13
+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
14
+ ) WITHOUT ROWID;
15
+
16
+ -- Index for temporal queries and overview management
17
+ CREATE INDEX IF NOT EXISTS idx_project_overviews_last_modified ON project_overviews(last_modified);
18
+
19
+ -- Index for project-based queries
20
+ CREATE INDEX IF NOT EXISTS idx_project_overviews_project_id ON project_overviews(project_id);
@@ -0,0 +1,166 @@
1
+ -- Migration 004: Remove branch dependency from database schema
2
+ -- This migration consolidates multi-branch data and simplifies the schema
3
+ -- by removing branch columns from file_descriptions and project_overviews tables
4
+
5
+ -- Ensure WAL mode is enabled for safe migrations
6
+ PRAGMA journal_mode=WAL;
7
+
8
+ -- Enable foreign key support
9
+ PRAGMA foreign_keys=ON;
10
+
11
+ -- Start transaction for atomic migration
12
+ BEGIN TRANSACTION;
13
+
14
+ -- Create new file_descriptions table without branch dependency
15
+ CREATE TABLE file_descriptions_new (
16
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
17
+ project_id TEXT NOT NULL,
18
+ file_path TEXT NOT NULL,
19
+ description TEXT NOT NULL,
20
+ file_hash TEXT,
21
+ last_modified DATETIME DEFAULT CURRENT_TIMESTAMP,
22
+ version INTEGER DEFAULT 1,
23
+ source_project_id TEXT,
24
+ to_be_cleaned INTEGER DEFAULT NULL, -- UNIX timestamp for cleanup, NULL = active
25
+ UNIQUE(project_id, file_path),
26
+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
27
+ FOREIGN KEY (source_project_id) REFERENCES projects(id) ON DELETE SET NULL
28
+ );
29
+
30
+ -- Create indexes for the new table
31
+ CREATE INDEX idx_file_descriptions_new_project_id ON file_descriptions_new(project_id);
32
+ CREATE INDEX idx_file_descriptions_new_file_hash ON file_descriptions_new(file_hash);
33
+ CREATE INDEX idx_file_descriptions_new_last_modified ON file_descriptions_new(last_modified);
34
+ CREATE INDEX idx_file_descriptions_new_to_be_cleaned ON file_descriptions_new(to_be_cleaned);
35
+
36
+ -- Consolidate data from old table - keep most recent description per file
37
+ -- This handles multi-branch scenarios by selecting the newest data
38
+ INSERT INTO file_descriptions_new (
39
+ project_id, file_path, description, file_hash, last_modified, version, source_project_id
40
+ )
41
+ SELECT
42
+ project_id,
43
+ file_path,
44
+ description,
45
+ file_hash,
46
+ last_modified,
47
+ version,
48
+ source_project_id
49
+ FROM (
50
+ SELECT
51
+ project_id,
52
+ file_path,
53
+ description,
54
+ file_hash,
55
+ last_modified,
56
+ version,
57
+ source_project_id,
58
+ ROW_NUMBER() OVER (
59
+ PARTITION BY project_id, file_path
60
+ ORDER BY last_modified DESC
61
+ ) as rn
62
+ FROM file_descriptions
63
+ ) ranked_descriptions
64
+ WHERE rn = 1;
65
+
66
+ -- Create new project_overviews table without branch dependency
67
+ CREATE TABLE project_overviews_new (
68
+ project_id TEXT PRIMARY KEY,
69
+ overview TEXT NOT NULL,
70
+ last_modified TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
71
+ total_files INTEGER NOT NULL DEFAULT 0,
72
+ total_tokens INTEGER NOT NULL DEFAULT 0,
73
+ FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE
74
+ );
75
+
76
+ -- Create indexes for the new table
77
+ CREATE INDEX idx_project_overviews_new_last_modified ON project_overviews_new(last_modified);
78
+
79
+ -- Consolidate project overviews - keep the one with most tokens (most comprehensive)
80
+ INSERT INTO project_overviews_new (
81
+ project_id, overview, last_modified, total_files, total_tokens
82
+ )
83
+ SELECT
84
+ project_id,
85
+ overview,
86
+ last_modified,
87
+ total_files,
88
+ total_tokens
89
+ FROM (
90
+ SELECT
91
+ project_id,
92
+ overview,
93
+ last_modified,
94
+ total_files,
95
+ total_tokens,
96
+ ROW_NUMBER() OVER (
97
+ PARTITION BY project_id
98
+ ORDER BY total_tokens DESC, last_modified DESC
99
+ ) as rn
100
+ FROM project_overviews
101
+ ) ranked_overviews
102
+ WHERE rn = 1;
103
+
104
+ -- Drop FTS5 triggers for old table
105
+ DROP TRIGGER IF EXISTS file_descriptions_ai;
106
+ DROP TRIGGER IF EXISTS file_descriptions_ad;
107
+ DROP TRIGGER IF EXISTS file_descriptions_au;
108
+
109
+ -- Drop FTS5 virtual table
110
+ DROP TABLE IF EXISTS file_descriptions_fts;
111
+
112
+ -- Drop old tables
113
+ DROP TABLE file_descriptions;
114
+ DROP TABLE project_overviews;
115
+
116
+ -- Rename new tables to original names
117
+ ALTER TABLE file_descriptions_new RENAME TO file_descriptions;
118
+ ALTER TABLE project_overviews_new RENAME TO project_overviews;
119
+
120
+ -- Create new FTS5 virtual table without branch column
121
+ CREATE VIRTUAL TABLE file_descriptions_fts USING fts5(
122
+ project_id,
123
+ file_path,
124
+ description,
125
+ content='file_descriptions',
126
+ content_rowid='id'
127
+ );
128
+
129
+ -- Populate FTS5 table with existing data (only active records)
130
+ INSERT INTO file_descriptions_fts(rowid, project_id, file_path, description)
131
+ SELECT id, project_id, file_path, description
132
+ FROM file_descriptions
133
+ WHERE to_be_cleaned IS NULL;
134
+
135
+ -- Create new FTS5 triggers for the updated schema
136
+ CREATE TRIGGER file_descriptions_ai AFTER INSERT ON file_descriptions BEGIN
137
+ -- Only index active records (not marked for cleanup)
138
+ INSERT INTO file_descriptions_fts(rowid, project_id, file_path, description)
139
+ SELECT new.id, new.project_id, new.file_path, new.description
140
+ WHERE new.to_be_cleaned IS NULL;
141
+ END;
142
+
143
+ CREATE TRIGGER file_descriptions_ad AFTER DELETE ON file_descriptions BEGIN
144
+ INSERT INTO file_descriptions_fts(file_descriptions_fts, rowid, project_id, file_path, description)
145
+ VALUES ('delete', old.id, old.project_id, old.file_path, old.description);
146
+ END;
147
+
148
+ CREATE TRIGGER file_descriptions_au AFTER UPDATE ON file_descriptions BEGIN
149
+ -- Remove old record from FTS
150
+ INSERT INTO file_descriptions_fts(file_descriptions_fts, rowid, project_id, file_path, description)
151
+ VALUES ('delete', old.id, old.project_id, old.file_path, old.description);
152
+
153
+ -- Add new record only if it's active (not marked for cleanup)
154
+ INSERT INTO file_descriptions_fts(rowid, project_id, file_path, description)
155
+ SELECT new.id, new.project_id, new.file_path, new.description
156
+ WHERE new.to_be_cleaned IS NULL;
157
+ END;
158
+
159
+ -- Update merge_conflicts table to remove branch references (optional cleanup)
160
+ -- This table structure can remain as-is since it's used for temporary conflict resolution
161
+ -- but we'll remove unused indexes that reference branches
162
+ DROP INDEX IF EXISTS idx_merge_conflicts_project;
163
+ CREATE INDEX idx_merge_conflicts_project ON merge_conflicts(project_id, created);
164
+
165
+ -- Commit the migration
166
+ COMMIT;