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"}
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool clears a cache, implying a destructive mutation, but doesn't specify if this requires special permissions, affects performance, or has side effects like temporary slowdowns. The return value is vaguely described as 'Status message' without detailing success/failure indicators or error handling.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence, followed by structured Args and Returns sections. It avoids unnecessary fluff, but the formatting with indentation and section headers could be more streamlined for an AI agent. Overall, it's efficient but not perfectly minimal.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (2 optional parameters, no annotations, no output schema), the description is partially complete. It covers the basic action and parameters but lacks details on behavioral traits, error cases, and integration with sibling tools. For a cache-clearing operation, more context on impact and usage scenarios would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It lists both parameters ('project' and 'file_path') and notes they are optional, adding meaning beyond the schema's basic titles. However, it doesn't explain what 'project' or 'file_path' refer to in context (e.g., project names vs. IDs, file path formats), leaving gaps in understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Clear the parse tree cache.' It specifies the verb ('clear') and resource ('parse tree cache'), making the action unambiguous. However, it doesn't explicitly differentiate from sibling tools like 'remove_project_tool' or 'configure', which might also involve cleanup operations, so it's not a perfect 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, such as whether a cache must exist first, or suggest other tools for related tasks like 'get_ast' or 'analyze_project'. The absence of usage context leaves the agent without clear decision-making criteria.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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