Skip to main content
Glama
cemalturkcan

MariaDB MCP Server

by cemalturkcan

execute_select

Run read-only SQL queries (SELECT, SHOW, DESCRIBE, EXPLAIN) on MariaDB/MySQL databases with enforced row limits for safe data exploration.

Instructions

Executes a read-only SELECT/SHOW/DESCRIBE/EXPLAIN query. Row limit is enforced.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connectionYes
queryYes
databaseNo
row_limitNo

Implementation Reference

  • Input schema/definition for the 'execute_select' tool. Defines the name, description, and inputSchema (connection, query, database, row_limit).
    {
      name: "execute_select",
      description:
        "Executes a read-only SELECT/SHOW/DESCRIBE/EXPLAIN query. Row limit is enforced.",
      inputSchema: {
        type: "object",
        properties: {
          connection: { type: "string", enum: readableConnections },
          query: { type: "string" },
          database: { type: "string" },
          row_limit: { type: "number" },
        },
        required: ["connection", "query"],
      },
    },
  • Handler implementation for 'execute_select'. Extracts args, validates using validateReadQuery, optionally applies row limit via resolveRowLimit/buildLimitedQuery, runs query via db.runReadOnly, and returns results with row_count/rows.
    case "execute_select": {
      const connection = args?.connection;
      const query = args?.query;
      const database = args?.database;
      const requestedRowLimit = args?.row_limit;
    
      if (!connection) return fail("'connection' field is required.");
      if (!query) return fail("'query' field is required.");
    
      const connectionConfig = db.getConnectionConfig(connection);
      const validatedQuery = validateReadQuery(query);
    
      const upper = validatedQuery.trim().toUpperCase();
      let finalQuery = validatedQuery;
      let appliedRowLimit = null;
    
      if (upper.startsWith("SELECT") || upper.startsWith("WITH")) {
        appliedRowLimit = resolveRowLimit(
          requestedRowLimit,
          connectionConfig,
        );
        if (appliedRowLimit !== null) {
          finalQuery = buildLimitedQuery(validatedQuery, appliedRowLimit);
        }
      }
    
      const rows = await db.runReadOnly(connection, finalQuery, { database });
    
      const result = {
        row_count: Array.isArray(rows) ? rows.length : 0,
        rows,
      };
      if (appliedRowLimit !== null) {
        result.row_limit = appliedRowLimit;
      }
      return ok(result);
    }
  • validateReadQuery helper used by execute_select to ensure only SELECT/SHOW/DESCRIBE/EXPLAIN queries are allowed.
    export function validateReadQuery(rawQuery) {
      if (typeof rawQuery !== "string") {
        throw new Error("Query must be a string.");
      }
    
      const query = rawQuery.trim();
      if (!query) {
        throw new Error("Query must not be empty.");
      }
    
      if (!isReadQuery(query)) {
        throw new Error(
          "Only SELECT/SHOW/DESCRIBE/EXPLAIN queries are allowed."
        );
      }
    
      return query;
    }
  • resolveRowLimit helper used by execute_select to determine the effective row limit based on connection config defaults/max.
    export function resolveRowLimit(requestedRowLimit, connectionConfig) {
      const defaultLimit = connectionConfig.default_row_limit || 0;
      const maxLimit = connectionConfig.max_row_limit || 0;
    
      if (requestedRowLimit != null) {
        const n = Number(requestedRowLimit);
        if (!Number.isFinite(n) || n <= 0) {
          throw new Error("row_limit must be a positive number.");
        }
        const chosen = Math.floor(n);
        return maxLimit > 0 ? Math.min(chosen, maxLimit) : chosen;
      }
    
      if (defaultLimit > 0) {
        return maxLimit > 0 ? Math.min(defaultLimit, maxLimit) : defaultLimit;
      }
    
      return null;
    }
  • buildLimitedQuery helper wraps a query with LIMIT to enforce row limits.
    export function buildLimitedQuery(query, rowLimit) {
      return `SELECT * FROM (${query}) AS mcp_query LIMIT ${rowLimit}`;
    }
Behavior3/5

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

The description declares the tool as read-only and mentions a row limit, which are important behavioral traits. However, with no annotations, it lacks disclosure of other behaviors like error handling, result format, or query length limits.

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 consists of two concise sentences with the action verb upfront. No extraneous information is included, making it easy to parse quickly.

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?

Given the tool has 4 parameters and no annotations or output schema, the description is too minimal. It fails to explain return values, parameter dependencies, or error scenarios, which are critical for correct invocation.

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?

Schema description coverage is 0%, yet the description only adds meaning for row_limit. It does not explain the connection enum, the purpose of the optional database parameter, or expected query format, leaving three parameters undocumented.

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 executes read-only SQL-type queries (SELECT/SHOW/DESCRIBE/EXPLAIN) and enforces a row limit. It distinguishes itself from sibling tools that focus on metadata or suggestions, though it could explicitly state that it returns query results.

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?

No guidance is provided on when to use this tool versus siblings such as describe_table or suggest_query. The description does not specify context, prerequisites, or alternatives, leaving the agent to infer usage.

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/cemalturkcan/mariadb-mcp-server'

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