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,
    }

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