Skip to main content
Glama
wrale

mcp-server-tree-sitter

by wrale

adapt_query

Transform a query from one programming language to another using tree-sitter-based code analysis. Ideal for adapting code queries across different languages with accurate context management.

Instructions

Adapt a query from one language to another.

    Args:
        query: Original query string
        from_language: Source language
        to_language: Target language

    Returns:
        Adapted query
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
from_languageYes
queryYes
to_languageYes

Implementation Reference

  • MCP tool handler and registration for 'adapt_query'. This decorated function executes the tool logic by importing and calling the helper adapt_query_for_language from query_builder, returning a dictionary with original and adapted query.
    @mcp_server.tool()
    def adapt_query(query: str, from_language: str, to_language: str) -> Dict[str, str]:
        """Adapt a query from one language to another.
    
        Args:
            query: Original query string
            from_language: Source language
            to_language: Target language
    
        Returns:
            Adapted query
        """
        from ..tools.query_builder import adapt_query_for_language
    
        adapted = adapt_query_for_language(query, from_language, to_language)
        return {
            "original_language": from_language,
            "target_language": to_language,
            "original_query": query,
            "adapted_query": adapted,
        }
  • Core helper function that performs the actual query adaptation using a dictionary of node type translations between languages, applying simple string replacements.
    def adapt_query_for_language(query: str, from_language: str, to_language: str) -> str:
        """
        Try to adapt a query from one language to another.
    
        Args:
            query: Original query
            from_language: Source language
            to_language: Target language
    
        Returns:
            Adapted query string
    
        Note:
            This is a simplified implementation that assumes similar node types.
            A real implementation would need language-specific translations.
        """
        translations = {
            # Python -> JavaScript
            ("python", "javascript"): {
                "function_definition": "function_declaration",
                "class_definition": "class_declaration",
                "block": "statement_block",
                "parameters": "formal_parameters",
                "argument_list": "arguments",
                "import_statement": "import_statement",
                "call": "call_expression",
            },
            # JavaScript -> Python
            ("javascript", "python"): {
                "function_declaration": "function_definition",
                "class_declaration": "class_definition",
                "statement_block": "block",
                "formal_parameters": "parameters",
                "arguments": "argument_list",
                "call_expression": "call",
            },
            # Add more language pairs...
        }
    
        pair = (from_language, to_language)
        if pair in translations:
            trans_dict = translations[pair]
            for src, dst in trans_dict.items():
                # Simple string replacement
                query = query.replace(f"({src}", f"({dst}")
    
        return query
  • Wrapper helper function in query_builder that calls adapt_query_for_language and formats the response dictionary, similar to the tool handler.
    def adapt_query(query: str, from_language: str, to_language: str) -> Dict[str, str]:
        """
        Adapt a query from one language to another.
    
        Args:
            query: Original query string
            from_language: Source language
            to_language: Target language
    
        Returns:
            Dictionary with adapted query and metadata
        """
        adapted = adapt_query_for_language(query, from_language, to_language)
        return {
            "original_language": from_language,
            "target_language": to_language,
            "original_query": query,
            "adapted_query": adapted,
        }
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 adapts queries but doesn't explain how the adaptation works (e.g., translation, syntax conversion), what errors might occur, or any performance considerations. This leaves significant gaps in understanding the tool's behavior.

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, followed by structured parameter and return details. It's efficient with minimal waste, though the parameter explanations could be more integrated into the main text rather than in a separate Args/Returns block.

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?

For a 3-parameter tool with no annotations and no output schema, the description is minimally adequate. It covers the basic purpose and parameters but lacks details on adaptation mechanics, error handling, or output format. Given the complexity, it's incomplete but not entirely inadequate.

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 lists the three parameters (query, from_language, to_language) and their roles, adding meaning beyond the schema's 0% coverage. However, it doesn't specify language formats (e.g., SQL, Python) or query constraints, leaving some ambiguity. With low schema coverage, this partial compensation earns a baseline score.

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: 'Adapt a query from one language to another.' It specifies the verb ('adapt') and resource ('query'), making the function unambiguous. However, it doesn't explicitly distinguish this from sibling tools like 'build_query' or 'run_query', which prevents a perfect score.

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 choose 'adapt_query' over 'build_query' or 'run_query', nor does it specify prerequisites or exclusions. The usage context is implied but not articulated.

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