mcp-code-indexer 1.1.0__py3-none-any.whl → 1.1.1__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.
@@ -234,6 +234,21 @@ class DatabaseManager:
234
234
 
235
235
  return projects
236
236
 
237
+ async def get_branch_file_counts(self, project_id: str) -> Dict[str, int]:
238
+ """Get file counts per branch for a project."""
239
+ async with self.get_connection() as db:
240
+ cursor = await db.execute(
241
+ """
242
+ SELECT branch, COUNT(*) as file_count
243
+ FROM file_descriptions
244
+ WHERE project_id = ?
245
+ GROUP BY branch
246
+ """,
247
+ (project_id,)
248
+ )
249
+ rows = await cursor.fetchall()
250
+ return {row[0]: row[1] for row in rows}
251
+
237
252
  # File description operations
238
253
 
239
254
  async def create_file_description(self, file_desc: FileDescription) -> None:
@@ -369,13 +384,13 @@ class DatabaseManager:
369
384
  fd.branch,
370
385
  fd.file_path,
371
386
  fd.description,
372
- fts.rank
373
- FROM file_descriptions_fts fts
374
- JOIN file_descriptions fd ON fd.rowid = fts.rowid
375
- WHERE fts MATCH ?
387
+ bm25(file_descriptions_fts) as rank
388
+ FROM file_descriptions_fts
389
+ JOIN file_descriptions fd ON fd.rowid = file_descriptions_fts.rowid
390
+ WHERE file_descriptions_fts MATCH ?
376
391
  AND fd.project_id = ?
377
392
  AND fd.branch = ?
378
- ORDER BY fts.rank
393
+ ORDER BY bm25(file_descriptions_fts)
379
394
  LIMIT ?
380
395
  """,
381
396
  (query, project_id, branch, max_results)
@@ -473,6 +473,41 @@ class MCPCodeIndexServer:
473
473
  await self.db_manager.update_project(project)
474
474
  logger.debug(f"Updated project metadata for {project.name}")
475
475
 
476
+ async def _find_best_branch(self, project_id: str, requested_branch: str) -> Optional[str]:
477
+ """
478
+ Find the best available branch for a project when the requested branch has no files.
479
+ Returns the branch with the most files, or None if no branches have files.
480
+ """
481
+ try:
482
+ # Get all branches and their file counts for this project
483
+ branch_counts = await self.db_manager.get_branch_file_counts(project_id)
484
+
485
+ if not branch_counts:
486
+ return None
487
+
488
+ # First try common branch name variations
489
+ common_variations = {
490
+ 'main': ['master', 'develop', 'development', 'dev'],
491
+ 'master': ['main', 'develop', 'development', 'dev'],
492
+ 'develop': ['development', 'main', 'master', 'dev'],
493
+ 'development': ['develop', 'main', 'master', 'dev'],
494
+ 'dev': ['develop', 'development', 'main', 'master']
495
+ }
496
+
497
+ # Try variations of the requested branch
498
+ if requested_branch.lower() in common_variations:
499
+ for variation in common_variations[requested_branch.lower()]:
500
+ if variation in branch_counts and branch_counts[variation] > 0:
501
+ return variation
502
+
503
+ # Fall back to the branch with the most files
504
+ best_branch = max(branch_counts.items(), key=lambda x: x[1])
505
+ return best_branch[0] if best_branch[1] > 0 else None
506
+
507
+ except Exception as e:
508
+ logger.warning(f"Error finding best branch: {e}")
509
+ return None
510
+
476
511
  async def _handle_get_file_description(self, arguments: Dict[str, Any]) -> Dict[str, Any]:
477
512
  """Handle get_file_description tool calls."""
478
513
  project_id = await self._get_or_create_project_id(arguments)
@@ -523,13 +558,24 @@ class MCPCodeIndexServer:
523
558
  async def _handle_check_codebase_size(self, arguments: Dict[str, Any]) -> Dict[str, Any]:
524
559
  """Handle check_codebase_size tool calls."""
525
560
  project_id = await self._get_or_create_project_id(arguments)
561
+ requested_branch = arguments["branch"]
526
562
 
527
- # Get all file descriptions for this project/branch
563
+ # Get file descriptions for this project/branch
528
564
  file_descriptions = await self.db_manager.get_all_file_descriptions(
529
565
  project_id=project_id,
530
- branch=arguments["branch"]
566
+ branch=requested_branch
531
567
  )
532
568
 
569
+ # If no files found for requested branch, try to find the best available branch
570
+ if not file_descriptions:
571
+ available_branch = await self._find_best_branch(project_id, requested_branch)
572
+ if available_branch and available_branch != requested_branch:
573
+ file_descriptions = await self.db_manager.get_all_file_descriptions(
574
+ project_id=project_id,
575
+ branch=available_branch
576
+ )
577
+ logger.info(f"No files found for branch '{requested_branch}', using '{available_branch}' instead")
578
+
533
579
  # Calculate total tokens
534
580
  total_tokens = self.token_counter.calculate_codebase_tokens(file_descriptions)
535
581
  is_large = self.token_counter.is_large_codebase(total_tokens)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcp-code-indexer
3
- Version: 1.1.0
3
+ Version: 1.1.1
4
4
  Summary: MCP server that tracks file descriptions across codebases, enabling AI agents to efficiently navigate and understand code through searchable summaries and token-aware overviews.
5
5
  Author: MCP Code Indexer Contributors
6
6
  Maintainer: MCP Code Indexer Contributors
@@ -6,17 +6,17 @@ mcp_code_indexer/main.py,sha256=Rou-mAN9-12PPP8jC7dIs2_UNambJuC2F8BF--j-0m8,3715
6
6
  mcp_code_indexer/merge_handler.py,sha256=lJR8eVq2qSrF6MW9mR3Fy8UzrNAaQ7RsI2FMNXne3vQ,14692
7
7
  mcp_code_indexer/token_counter.py,sha256=WrifOkbF99nWWHlRlhCHAB2KN7qr83GOHl7apE-hJcE,8460
8
8
  mcp_code_indexer/database/__init__.py,sha256=aPq_aaRp0aSwOBIq9GkuMNjmLxA411zg2vhdrAuHm-w,38
9
- mcp_code_indexer/database/database.py,sha256=CqkGXkJLANr2qfxA2FLX1oYiNj0lTm1LyxD97dzJHSs,19650
9
+ mcp_code_indexer/database/database.py,sha256=eG2xY5cd-oxRZ6mgGkqqBiJJfGCPqJgzoFq6kR99WfA,20300
10
10
  mcp_code_indexer/database/models.py,sha256=3wOxHKb6j3zKPWFSwB5g1TLpI507vLNZcqsxZR4VuRs,5528
11
11
  mcp_code_indexer/middleware/__init__.py,sha256=p-mP0pMsfiU2yajCPvokCUxUEkh_lu4XJP1LyyMW2ug,220
12
12
  mcp_code_indexer/middleware/error_middleware.py,sha256=v6jaHmPxf3qerYdb85X1tHIXLxgcbybpitKVakFLQTA,10109
13
13
  mcp_code_indexer/server/__init__.py,sha256=16xMcuriUOBlawRqWNBk6niwrvtv_JD5xvI36X1Vsmk,41
14
- mcp_code_indexer/server/mcp_server.py,sha256=RNM-0tB_1Gm5P5Vz4rNTXQKcjOyIWa4s6nirZ1BNi-g,43208
14
+ mcp_code_indexer/server/mcp_server.py,sha256=LxYt6AQ2hifAZIrduyGGBz22kxfcMnCAsHPjih37X5k,45523
15
15
  mcp_code_indexer/tiktoken_cache/9b5ad71b2ce5302211f9c61530b329a4922fc6a4,sha256=Ijkht27pm96ZW3_3OFE-7xAPtR0YyTWXoRO8_-hlsqc,1681126
16
16
  mcp_code_indexer/tools/__init__.py,sha256=m01mxML2UdD7y5rih_XNhNSCMzQTz7WQ_T1TeOcYlnE,49
17
- mcp_code_indexer-1.1.0.dist-info/licenses/LICENSE,sha256=JN9dyPPgYwH9C-UjYM7FLNZjQ6BF7kAzpF3_4PwY4rY,1086
18
- mcp_code_indexer-1.1.0.dist-info/METADATA,sha256=n6fIk9JrhEmPG2LVpMCFI7XkP3Aey4dM1V_zKuhAkoA,11930
19
- mcp_code_indexer-1.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
- mcp_code_indexer-1.1.0.dist-info/entry_points.txt,sha256=8HqWOw1Is7jOP1bvIgaSwouvT9z_Boe-9hd4NzyJOhY,68
21
- mcp_code_indexer-1.1.0.dist-info/top_level.txt,sha256=yKYCM-gMGt-cnupGfAhnZaoEsROLB6DQ1KFUuyKx4rw,17
22
- mcp_code_indexer-1.1.0.dist-info/RECORD,,
17
+ mcp_code_indexer-1.1.1.dist-info/licenses/LICENSE,sha256=JN9dyPPgYwH9C-UjYM7FLNZjQ6BF7kAzpF3_4PwY4rY,1086
18
+ mcp_code_indexer-1.1.1.dist-info/METADATA,sha256=h8Kqpz8nH14e73F1AoBwXAy3BgnBYKh04igxTq2euKw,11930
19
+ mcp_code_indexer-1.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
20
+ mcp_code_indexer-1.1.1.dist-info/entry_points.txt,sha256=8HqWOw1Is7jOP1bvIgaSwouvT9z_Boe-9hd4NzyJOhY,68
21
+ mcp_code_indexer-1.1.1.dist-info/top_level.txt,sha256=yKYCM-gMGt-cnupGfAhnZaoEsROLB6DQ1KFUuyKx4rw,17
22
+ mcp_code_indexer-1.1.1.dist-info/RECORD,,