Skip to main content
Glama
wrale

mcp-server-tree-sitter

by wrale

get_query_template_tool

Retrieve predefined tree-sitter query templates for code analysis. Specify the language and template type (e.g., functions, classes) to obtain structured query information for enhanced code context management.

Instructions

Get a predefined tree-sitter query template.

    Args:
        language: Language name
        template_name: Template name (e.g., "functions", "classes")

    Returns:
        Query template information
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
languageYes
template_nameYes

Implementation Reference

  • The handler function for 'get_query_template_tool', decorated with @mcp_server.tool() for registration. It fetches the query template using the helper function and returns it in a structured format, including error handling if the template does not exist.
    @mcp_server.tool()
    def get_query_template_tool(language: str, template_name: str) -> Dict[str, Any]:
        """Get a predefined tree-sitter query template.
    
        Args:
            language: Language name
            template_name: Template name (e.g., "functions", "classes")
    
        Returns:
            Query template information
        """
        from ..language.query_templates import get_query_template
    
        template = get_query_template(language, template_name)
        if not template:
            raise ValueError(f"No template '{template_name}' for language '{language}'")
    
        return {
            "language": language,
            "name": template_name,
            "query": template,
        }
  • Core helper function that retrieves the specific query template string from the QUERY_TEMPLATES dictionary based on language and template name.
    def get_query_template(language: str, template_name: str) -> Optional[str]:
        """
        Get a query template for a language.
    
        Args:
            language: Language identifier
            template_name: Template name
    
        Returns:
            Query string or None if not found
        """
        language_templates = QUERY_TEMPLATES.get(language)
        if language_templates:
            return language_templates.get(template_name)
        return None
  • Central data structure aggregating query templates from all language-specific template modules, used by the get_query_template helper.
    # Combine all language templates
    QUERY_TEMPLATES: Dict[str, Dict[str, str]] = {
        "python": python.TEMPLATES,
        "javascript": javascript.TEMPLATES,
        "typescript": typescript.TEMPLATES,
        "go": go.TEMPLATES,
        "rust": rust.TEMPLATES,
        "c": c.TEMPLATES,
        "cpp": cpp.TEMPLATES,
        "swift": swift.TEMPLATES,
        "java": java.TEMPLATES,
        "kotlin": kotlin.TEMPLATES,
        "julia": julia.TEMPLATES,
        "apl": apl.TEMPLATES,
    }
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 it 'Get[s]' information, implying a read-only operation, but doesn't clarify if it requires authentication, has rate limits, or what happens if the template doesn't exist. For a tool with no annotation coverage, this leaves significant behavioral gaps.

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 appropriately sized and front-loaded with the core purpose in the first sentence. The Args and Returns sections are structured clearly, though the Returns section is vague ('Query template information'). Overall, it's efficient with minimal waste.

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 has 2 parameters, no annotations, and no output schema, the description is moderately complete. It covers the purpose and parameters but lacks usage guidelines, behavioral details, and specifics on return values. For a simple read tool, this is adequate but leaves room for improvement in guiding the agent.

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?

The description includes parameter semantics in the Args section, explaining that 'language' is a language name and 'template_name' is a template name with examples. However, schema description coverage is 0%, so the schema provides no additional details. The description compensates adequately but doesn't specify allowed values or constraints beyond the examples.

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 verb 'Get' and the resource 'predefined tree-sitter query template', making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'list_query_templates_tool' or 'build_query', which might offer related functionality.

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 when to prefer this over 'list_query_templates_tool' for listing templates or 'build_query' for creating custom queries, leaving the agent to infer usage from context alone.

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