Skip to main content
Glama

MariaDB MCP Server

by bretoreta

list_databases

Retrieve a comprehensive list of all accessible databases on the MariaDB server using this tool, enabling users to manage and explore database resources efficiently.

Instructions

List all accessible databases on the MariaDB server

Input Schema

NameRequiredDescriptionDefault

No arguments

Input Schema (JSON Schema)

{ "properties": {}, "required": [], "type": "object" }

Implementation Reference

  • The switch case that implements the core logic of the list_databases tool: executes 'SHOW DATABASES' SQL query using the executeQuery helper and formats the results as JSON text content.
    case "list_databases": { const { rows } = await executeQuery("SHOW DATABASES"); return { content: [{ type: "text", text: JSON.stringify(rows, null, 2) }], }; }
  • src/index.ts:82-86 (registration)
    Tool registration entry in the ListTools handler response, defining the name, description, and input schema (empty object) for list_databases.
    { name: "list_databases", description: "List all databases", inputSchema: { type: "object" }, },
  • Input schema definition for the list_databases tool: accepts an empty object.
    inputSchema: { type: "object" },
  • Helper function executeQuery used by the list_databases handler to run the SQL query against the MariaDB database, handling connections, validation, and result limiting.
    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"); } } }

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

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