Skip to main content
Glama
wrale

mcp-server-tree-sitter

by wrale

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
NameRequiredDescriptionDefault
file_pathNo
projectNo

Implementation Reference

  • 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}
  • 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"}

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/wrale/mcp-server-tree-sitter'

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