clear_cache
Clears the parse tree cache for a specific project or file, ensuring accurate code analysis by the MCP server-tree-sitter.
Instructions
Clear the parse tree cache.
Args:
project: Optional project to clear cache for
file_path: Optional specific file to clear cache for
Returns:
Status message
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | No | ||
| project | No |
Implementation Reference
- src/mcp_server_tree_sitter/tools/registration.py:628-655 (registration)Registers the clear_cache MCP tool with @mcp_server.tool() decorator and implements its handler. The function invalidates the tree cache for the specified project and/or file_path, or clears all caches if none specified.@mcp_server.tool() def clear_cache(project: Optional[str] = None, file_path: Optional[str] = None) -> Dict[str, str]: """Clear the parse tree cache. Args: project: Optional project to clear cache for file_path: Optional specific file to clear cache for Returns: Status message """ if project and file_path: # Clear cache for specific file project_obj = project_registry.get_project(project) abs_path = project_obj.get_file_path(file_path) tree_cache.invalidate(abs_path) message = f"Cache cleared for {file_path} in project {project}" elif project: # Clear cache for entire project # No direct way to clear by project, so invalidate entire cache tree_cache.invalidate() message = f"Cache cleared for project {project}" else: # Clear entire cache tree_cache.invalidate() message = "All caches cleared" return {"status": "success", "message": message}
- src/mcp_server_tree_sitter/api.py:91-108 (handler)Core API implementation of clear_cache logic, used by tests and helpers, accessing dependencies via get_container().def clear_cache(project: Optional[str] = None, file_path: Optional[str] = None) -> Dict[str, str]: """Clear the parse tree cache.""" tree_cache = get_tree_cache() if project and file_path: # Get file path project_registry = get_project_registry() project_obj = project_registry.get_project(project) abs_path = project_obj.get_file_path(file_path) # Clear cache tree_cache.invalidate(abs_path) return {"status": "success", "message": f"Cache cleared for {file_path} in {project}"} else: # Clear all tree_cache.invalidate() return {"status": "success", "message": "Cache cleared"}
- ServerContext method providing clear_cache functionality using injected dependencies.def clear_cache(self, project: Optional[str] = None, file_path: Optional[str] = None) -> Dict[str, str]: """Clear the parse tree cache.""" if project and file_path: # Get file path project_obj = self.project_registry.get_project(project) abs_path = project_obj.get_file_path(file_path) # Clear cache self.tree_cache.invalidate(abs_path) return {"status": "success", "message": f"Cache cleared for {file_path} in {project}"} else: # Clear all self.tree_cache.invalidate() return {"status": "success", "message": "Cache cleared"}