refresh_index
Manually refresh the project index after file system changes to ensure search results are complete and current.
Instructions
Manually refresh the project index when files have been added/removed/moved.
Use when:
- File watcher is disabled or unavailable
- After large-scale operations (git checkout, merge, pull) that change many files
- When you want immediate index rebuild without waiting for file watcher debounce
- When find_files results seem incomplete or outdated
- For troubleshooting suspected index synchronization issues
Important notes for LLMs:
- Always available as backup when file watcher is not working
- Performs full project re-indexing for complete accuracy
- Use when you suspect the index is stale after file system changes
- **Call this after programmatic file modifications if file watcher seems unresponsive**
- Complements the automatic file watcher system
Returns:
Success message with total file count
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/code_index_mcp/server.py:247-270 (handler)The main handler function for the 'refresh_index' MCP tool. It is decorated with @mcp.tool() which registers it as a tool named 'refresh_index'. The function delegates the actual index rebuilding to IndexManagementService.rebuild_index().@mcp.tool() @handle_mcp_tool_errors(return_type='str') def refresh_index(ctx: Context) -> str: """ Manually refresh the project index when files have been added/removed/moved. Use when: - File watcher is disabled or unavailable - After large-scale operations (git checkout, merge, pull) that change many files - When you want immediate index rebuild without waiting for file watcher debounce - When find_files results seem incomplete or outdated - For troubleshooting suspected index synchronization issues Important notes for LLMs: - Always available as backup when file watcher is not working - Performs full project re-indexing for complete accuracy - Use when you suspect the index is stale after file system changes - **Call this after programmatic file modifications if file watcher seems unresponsive** - Complements the automatic file watcher system Returns: Success message with total file count """ return IndexManagementService(ctx).rebuild_index()
- Supporting method in IndexManagementService called by the refresh_index tool handler. Implements the shallow index rebuild logic.def rebuild_index(self) -> str: """ Rebuild the project index (DEFAULT: shallow file list). For deep/symbol rebuilds, use build_deep_index() tool instead. Returns: Success message with rebuild information Raises: ValueError: If project not set up or rebuild fails """ # Business validation self._validate_rebuild_request() # Get user-configured exclude patterns excludes = self._get_exclude_patterns() # Shallow rebuild only (fast path) if not self._shallow_manager.set_project_path(self.base_path, excludes): raise RuntimeError("Failed to set project path (shallow) in index manager") if not self._shallow_manager.build_index(): raise RuntimeError("Failed to rebuild shallow index") try: count = len(self._shallow_manager.get_file_list()) except Exception: count = 0 return f"Shallow index re-built with {count} files."