Skip to main content
Glama
OpenLinkSoftware

mcp-sqlalchemy

podbc_execute_query

Execute SQL queries and retrieve results in JSONL format. Configure max rows, parameters, and connection URL for precise data extraction via SQLAlchemy connectivity.

Instructions

Execute a SQL query and return results in JSONL format.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_rowsNo
paramsNo
queryYes
urlNo

Implementation Reference

  • The handler function that executes the SQL query on a pyodbc connection, processes results into a list of dicts with truncated long values, and returns them as a JSONL string.
    def podbc_execute_query(query: str, max_rows: int = 100, params: Optional[Dict[str, Any]] = None,
                      user:Optional[str]=None, password:Optional[str]=None, dsn:Optional[str]=None) -> str:
        """
        Execute a SQL query and return results in JSONL format.
    
        Args:
            query (str): The SQL query to execute.
            max_rows (int): Maximum number of rows to return. Default is 100.
            params (Optional[Dict[str, Any]]): Optional dictionary of parameters to pass to the query.
            user (Optional[str]=None): Optional username.
            password (Optional[str]=None): Optional password.
            dsn (Optional[str]=None): Optional dsn name.
    
        Returns:
            str: Results in JSONL format.
        """
        try:
            with get_connection(True, user, password, dsn) as conn:
                cursor = conn.cursor()
                rs = cursor.execute(query) if params is None else cursor.execute(query, params)
                columns = [column[0] for column in rs.description]            
                results = []
                for row in rs:
                    rs_dict = dict(zip(columns, row))
                    truncated_row = {key: (str(value)[:MAX_LONG_DATA] if value is not None else None) for key, value in rs_dict.items()}
                    results.append(truncated_row)                
                    if len(results) >= max_rows:
                        break
                    
                # Convert the results to JSONL format
                jsonl_results = "\n".join(json.dumps(row) for row in results)
    
                # Return the JSONL formatted results
                return jsonl_results
        except pyodbc.Error as e:
            logging.error(f"Error executing query: {e}")
            raise
  • MCP decorator that registers the podbc_execute_query function as a tool with the specified name and description.
    @mcp.tool(
        name="podbc_execute_query",
        description="Execute a SQL query and return results in JSONL format."
    )
  • Imports the tool handler from server.py into the package namespace, exposing it for MCP registration.
    from .server import (
        podbc_get_schemas,
        podbc_get_tables,
        podbc_describe_table,
        podbc_filter_table_names,
        podbc_execute_query,
        podbc_execute_query_md,
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the output format (JSONL) but doesn't address critical aspects like whether this is a read-only or write operation, authentication requirements, rate limits, error handling, or what happens when max_rows is exceeded. For a SQL execution tool, this leaves significant gaps.

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 extremely concise - a single sentence that efficiently communicates the core functionality. There's no wasted verbiage, and the information is front-loaded with the essential action and output format.

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

Completeness2/5

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

For a SQL execution tool with 4 parameters, 0% schema coverage, no annotations, and no output schema, the description is inadequate. It doesn't explain parameter usage, behavioral constraints, or what the tool returns beyond format. The agent would struggle to use this tool correctly without significant trial and error.

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

Parameters2/5

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

With 0% schema description coverage and 4 parameters (query, max_rows, params, url), the description provides no information about any parameters. It doesn't explain what 'params' should contain, what 'url' refers to, or how 'max_rows' affects execution. The description fails to compensate for the complete lack of schema documentation.

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 action ('Execute a SQL query') and outcome ('return results in JSONL format'), which is specific and unambiguous. However, it doesn't differentiate itself from sibling tools like 'podbc_query_database' or 'podbc_execute_query_md', which likely have overlapping 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. With multiple sibling tools involving queries (podbc_query_database, podbc_execute_query_md, podbc_sparql_query, etc.), there's no indication of what makes this tool distinct or when it should be preferred over others.

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/OpenLinkSoftware/mcp-sqlalchemy-server'

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