Skip to main content
Glama
bretoreta

MariaDB MCP Server

by bretoreta

list_tables

Retrieve all table names from a MariaDB database to explore its structure and contents. Specify a database name or use the default to view available tables.

Instructions

List all tables in a specified database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNoDatabase name (optional, uses default if not specified)

Implementation Reference

  • Handler for the list_tables tool: extracts database from args, runs SHOW FULL TABLES query via executeQuery helper, returns JSON stringified rows.
    case "list_tables": {
      const db = args.database as string | undefined;
      const { rows } = await executeQuery("SHOW FULL TABLES", [], db);
      return {
        content: [{ type: "text", text: JSON.stringify(rows, null, 2) }],
      };
    }
  • Input schema for list_tables tool: object with optional 'database' string property.
    inputSchema: {
      type: "object",
      properties: { database: { type: "string" } },
    },
  • src/index.ts:80-114 (registration)
    Registration of list_tables tool in the ListToolsRequestSchema handler, defining name, description, and schema.
    mcpServer.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          name: "list_databases",
          description: "List all databases",
          inputSchema: { type: "object" },
        },
        {
          name: "list_tables",
          description: "List tables in a database",
          inputSchema: {
            type: "object",
            properties: { database: { type: "string" } },
          },
        },
        {
          name: "describe_table",
          description: "Show schema of a table",
          inputSchema: {
            type: "object",
            properties: { database: { type: "string" }, table: { type: "string" } },
            required: ["table"],
          },
        },
        {
          name: "execute_query",
          description: "Run an arbitrary SQL query",
          inputSchema: {
            type: "object",
            properties: { query: { type: "string" }, database: { type: "string" } },
            required: ["query"],
          },
        },
      ],
    }));
  • Supporting executeQuery function called by list_tables handler to perform the SQL query on the database.
    export async function executeQuery(
      sql: string,
      params: any[] = [],
      database?: string
    ): Promise<{ rows: any; fields: mariadb.FieldInfo[] }> {
      console.error(`[Query] Executing: ${sql}`);
      // Create connection pool if not already created
      if (!pool) {
        console.error("[Setup] Connection pool not found, creating a new one");
        pool = createConnectionPool();
      }
      try {
        // Get connection from pool
        if (connection) {
          console.error("[Query] Reusing existing connection");
        } else {
          console.error("[Query] Creating new connection");
          connection = await pool.getConnection();
        }
    
        // Use specific database if provided
        if (database) {
          console.error(`[Query] Using database: ${database}`);
          await connection.query(`USE \`${database}\``);
        }
        if (!isAlloowedQuery(sql)) {
          throw new Error("Query not allowed");
        }
        // Execute query with timeout
        const [rows, fields] = await connection.query({
          metaAsArray: true,
          namedPlaceholders: true,
          sql,
          ...params,
          timeout: DEFAULT_TIMEOUT,
        });
    
        // Apply row limit if result is an array
        const limitedRows =
          Array.isArray(rows) && rows.length > DEFAULT_ROW_LIMIT
            ? rows.slice(0, DEFAULT_ROW_LIMIT)
            : rows;
    
        // Log result summary
        console.error(
          `[Query] Success: ${
            Array.isArray(rows) ? rows.length : 1
          } rows returned with ${JSON.stringify(params)}`
        );
    
        return { rows: limitedRows, fields };
      } catch (error) {
        if (connection) {
          connection.release();
          console.error("[Query] Connection released with error");
        }
        console.error("[Error] Query execution failed:", error);
        throw error;
      } finally {
        // Release connection back to pool
        if (connection) {
          connection.release();
          console.error("[Query] Connection released");
        }
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what the tool does, not how it behaves. It doesn't disclose whether this is a read-only operation, what permissions are required, whether it returns metadata or just names, if there are rate limits, or what happens when the database doesn't exist.

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 a single, efficient sentence that states the core purpose without any wasted words. It's appropriately sized for a simple list operation and front-loads the essential information.

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 tool with no annotations and no output schema, the description is insufficient. It doesn't explain what format the list returns (names only? with metadata?), whether there are pagination considerations, what happens with large databases, or any error conditions. The context signals indicate this is a simple tool, but the description leaves too many behavioral questions unanswered.

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?

Schema description coverage is 100%, so the schema already documents the single parameter fully. The description mentions 'specified database' which aligns with the schema but doesn't add meaningful semantic context beyond what the schema provides, such as explaining what 'default' means or providing examples.

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 ('List all tables') and target resource ('in a specified database'), providing specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'list_databases' or 'describe_table', which would require a 5.

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 about when to use this tool versus alternatives like 'list_databases' or 'describe_table'. The description mentions a database parameter but doesn't explain when to specify it versus using the default, or when this tool is appropriate versus executing a query.

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

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