Skip to main content
Glama
elber-code

Database Tools for Claude AI

by elber-code

mysql

Execute SQL queries in MySQL databases directly from Claude AI. Retrieve table information and manage database interactions using natural language commands.

Instructions

Execute a query in MySQL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSQL query to execute

Implementation Reference

  • index.js:18-38 (registration)
    Registers the 'mysql' tool on the MCP server with description, input schema using Zod, and an async handler function that invokes executeMysqlQuery with environment-based database config.
    server.tool("mysql", "Execute a query in MySQL", {
        query: z.string().describe("SQL query to execute"),
    }, async ({ query }) => {
        try {
            return executeMysqlQuery(query, {
                host: process.env.DB_HOST || 'localhost',
                user: process.env.DB_USER || 'root',
                password: process.env.DB_PASSWORD || ''
            });
        }
        catch (error) {
            return {
                content: [
                    {
                        type: "text",
                        text: "Error executing query: " + (error.message || "Unknown error"),
                    },
                ],
            };
        }
    });
  • Zod schema defining the input parameter 'query' as a string for the mysql tool.
    query: z.string().describe("SQL query to execute"),
  • index.js:20-37 (handler)
    The handler function for the mysql tool. It catches errors and calls the executeMysqlQuery helper with config from process.env.
    }, async ({ query }) => {
        try {
            return executeMysqlQuery(query, {
                host: process.env.DB_HOST || 'localhost',
                user: process.env.DB_USER || 'root',
                password: process.env.DB_PASSWORD || ''
            });
        }
        catch (error) {
            return {
                content: [
                    {
                        type: "text",
                        text: "Error executing query: " + (error.message || "Unknown error"),
                    },
                ],
            };
        }
  • mysql.js:4-34 (handler)
    Core handler logic: creates MySQL connection using mysql2/promise, executes the query, formats results as JSON string, returns structured content.
    export const executeMysqlQuery = async (query, config) => {
    
        const connection = await mysql.createConnection(config);
    
        const [results] = await connection.execute(query);
    
        await connection.end();
    
        let resultText;
    
        if (Array.isArray(results)) {
            if (results.length === 0) {
                resultText = "The query returned no results.";
            }
            else {
                resultText = `Results (${results.length} rows):\n\n${JSON.stringify(results, null, 2)}`;
            }
        }
        else {
            resultText = `Result: ${JSON.stringify(results, null, 2)}`;
        }
    
        return {
            content: [
                {
                    type: "text",
                    text: resultText,
                },
            ],
        };
    };
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions execution but doesn't disclose behavioral traits like whether it's read-only or destructive, authentication needs, error handling, or rate limits, leaving 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 a single, efficient sentence with no wasted words, making it front-loaded and appropriately sized for its purpose.

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 complexity of executing SQL queries, no annotations, and no output schema, the description is incomplete. It lacks details on return values, error cases, or operational constraints, which are crucial for effective use.

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 'query' parameter. The description adds no additional meaning beyond what the schema provides, such as query syntax or examples, meeting the baseline for high coverage.

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') and resource ('a query in MySQL'), making the purpose understandable. However, it doesn't distinguish from siblings since there are none, so it's not fully specific to a unique context.

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 alternatives, such as for read vs. write operations or specific query types. The description only states what it does without context or exclusions.

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/elber-code/database-tools'

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