Skip to main content
Glama
ajkeast

My Coding Buddy MCP Server

by ajkeast

execute_query

Run SQL queries and retrieve formatted results with each row on a new line, columns separated by tabs, for easy inspection.

Instructions

Execute a SQL query and return the results as a formatted string.

Args: query (str): The SQL query to execute

Returns: str: A formatted string representation of the query results Each row is on a new line, with columns separated by tabs

Raises: Error: If the query execution fails

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The execute_query method in the SQLTools class. It executes a SQL query, returns results as a tab-separated formatted string with column headers and rows, or returns an affected-row count for non-SELECT queries.
    def execute_query(self, query: str) -> str:
        """Execute a SQL query and return the results as a formatted string.
        
        Args:
            query (str): The SQL query to execute
            
        Returns:
            str: A formatted string representation of the query results
                  Each row is on a new line, with columns separated by tabs
                  
        Raises:
            Error: If the query execution fails
        """
        with self.get_connection() as conn:
            cursor = conn.cursor(dictionary=True, buffered=True)
            cursor.execute(query)
            conn.commit()
    
            if cursor.with_rows:
                results = cursor.fetchall()
                if not results:
                    return "No results found."
    
                columns = list(results[0].keys())
                output = "\t".join(columns) + "\n"
                for row in results:
                    output += "\t".join(str(row[col]) for col in columns) + "\n"
                return output
    
            return f"Query executed successfully. Rows affected: {cursor.rowcount}"
  • server.py:20-20 (registration)
    The tool is registered with the MCP server via mcp.tool()(sql_tools.execute_query) on line 20.
    mcp.tool()(sql_tools.execute_query)
  • Uses get_connection() (a context manager defined at line 19) to obtain a database connection with dictionary cursor and buffered mode.
    with self.get_connection() as conn:
        cursor = conn.cursor(dictionary=True, buffered=True)
  • Test case for execute_query with SELECT 1 to verify the results contain column names and values.
    def test_execute_query_select_one(sql_tools: SQLTools):
        result = sql_tools.execute_query("SELECT 1 AS test_column")
        assert isinstance(result, str)
        assert "test_column" in result
        assert "1" in result
  • Test case for execute_query with SELECT VERSION() to verify MySQL version retrieval.
    def test_execute_query_version(sql_tools: SQLTools):
        result = sql_tools.execute_query("SELECT VERSION() AS mysql_version")
        assert isinstance(result, str)
        assert "mysql_version" in result
Behavior3/5

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

No annotations are provided, so the description carries full behavioral disclosure. It mentions the return format (string, rows separated by newlines, columns by tabs) and error raising, but does not disclose potential side effects (e.g., whether it modifies data), permissions needed, or any constraints. This is adequate but not comprehensive.

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

Conciseness5/5

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

The description is highly concise and well-structured with clear sections for Args, Returns, and Raises. Every sentence contributes essential information, and the purpose is front-loaded.

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

Completeness4/5

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

Given the presence of an output schema and the simple nature of the tool (single parameter), the description adequately covers return format and error behavior. However, it could be more complete by addressing whether the query is read-only or has any restrictions, but overall it is sufficient for selection and invocation.

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

Parameters4/5

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

With only one parameter and 0% schema description coverage, the description adds value by explicitly documenting the parameter: 'query (str): The SQL query to execute'. This goes beyond the schema which only specifies type and title, making the parameter's purpose clear.

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

Purpose5/5

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

The description clearly states 'Execute a SQL query' which is a specific verb and resource. This distinguishes the tool from sibling tools that focus on metadata retrieval (e.g., list_tables, get_table_schema).

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 does not specify when not to use it, nor does it mention any exclusions or contexts where sibling tools would be more appropriate.

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

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/ajkeast/Coding-Buddy-MCP-Server'

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