Skip to main content
Glama
nilsir

MCP Server MySQL

by nilsir

connect

Establish a connection to a MySQL database using provided credentials or environment variables, enabling database operations through the MCP Server MySQL.

Instructions

Connect to a MySQL database. If not called explicitly, will use environment variables for connection.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostNoDatabase host
portNoDatabase port
userNoDatabase user
passwordNoDatabase password
databaseNoDatabase name

Implementation Reference

  • The handler function for the 'connect' tool. It creates a MySQL connection pool using the provided parameters or falls back to environment variables, closes any existing pool, tests the new connection by acquiring and releasing it, and returns a success message with connection details.
    async ({ host, port, user, password, database }) => {
      const config = {
        host: host || process.env.MYSQL_HOST || "localhost",
        port: port || parseInt(process.env.MYSQL_PORT || "3306", 10),
        user: user || process.env.MYSQL_USER || "root",
        password: password || process.env.MYSQL_PASSWORD || "",
        database: database,
        waitForConnections: true,
        connectionLimit: 10,
        queueLimit: 0,
      };
    
      // Close existing pool if any
      if (pool) {
        await pool.end();
      }
    
      pool = mysql.createPool(config);
    
      // Test connection
      const connection = await pool.getConnection();
      connection.release();
    
      const output = {
        success: true,
        host: config.host,
        port: config.port,
        database: config.database || null,
      };
    
      return {
        content: [
          {
            type: "text" as const,
            text: `Successfully connected to MySQL server at ${config.host}:${config.port}${config.database ? ` (database: ${config.database})` : ""}`,
          },
        ],
        structuredContent: output,
      };
    }
  • Zod schema defining the optional input parameters for the 'connect' tool: host, port, user, password, and database.
    {
      host: z.string().optional().describe("Database host"),
      port: z.number().optional().describe("Database port"),
      user: z.string().optional().describe("Database user"),
      password: z.string().optional().describe("Database password"),
      database: z.string().optional().describe("Database name"),
    },
  • src/index.ts:89-140 (registration)
    Registration of the 'connect' tool on the MCP server using server.tool(), specifying the tool name, description, input schema, and handler function.
    // Tool: connect
    server.tool(
      "connect",
      "Connect to a MySQL database. If not called explicitly, will use environment variables for connection.",
      {
        host: z.string().optional().describe("Database host"),
        port: z.number().optional().describe("Database port"),
        user: z.string().optional().describe("Database user"),
        password: z.string().optional().describe("Database password"),
        database: z.string().optional().describe("Database name"),
      },
      async ({ host, port, user, password, database }) => {
        const config = {
          host: host || process.env.MYSQL_HOST || "localhost",
          port: port || parseInt(process.env.MYSQL_PORT || "3306", 10),
          user: user || process.env.MYSQL_USER || "root",
          password: password || process.env.MYSQL_PASSWORD || "",
          database: database,
          waitForConnections: true,
          connectionLimit: 10,
          queueLimit: 0,
        };
    
        // Close existing pool if any
        if (pool) {
          await pool.end();
        }
    
        pool = mysql.createPool(config);
    
        // Test connection
        const connection = await pool.getConnection();
        connection.release();
    
        const output = {
          success: true,
          host: config.host,
          port: config.port,
          database: config.database || null,
        };
    
        return {
          content: [
            {
              type: "text" as const,
              text: `Successfully connected to MySQL server at ${config.host}:${config.port}${config.database ? ` (database: ${config.database})` : ""}`,
            },
          ],
          structuredContent: output,
        };
      }
    );
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 the connection behavior and fallback to environment variables, but lacks details on permissions needed, error handling, connection persistence, rate limits, or what happens on failure. For a tool with 5 parameters and no annotations, this is insufficient behavioral disclosure.

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 two sentences, front-loaded with the main purpose and followed by important usage context. Every sentence adds value without redundancy, making it efficient and well-structured.

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

Completeness3/5

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

Given the tool's complexity (5 parameters, no output schema, no annotations), the description is minimal. It covers the basic purpose and usage but lacks details on return values, error cases, or integration with sibling tools. It's adequate for a simple connection tool but has clear gaps in completeness.

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 fully documents all 5 parameters (host, port, user, password, database). The description doesn't add any parameter-specific details beyond what the schema provides, such as default values or format requirements. Baseline 3 is appropriate when the schema handles parameter 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 tool's purpose: 'Connect to a MySQL database.' It specifies the action (connect) and resource (MySQL database). However, it doesn't explicitly differentiate from siblings like 'use_database' or 'health_check', which might also involve database connections or checks.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context: 'If not called explicitly, will use environment variables for connection.' This indicates when to use it (for explicit connection setup) versus relying on defaults. It doesn't specify alternatives like other connection methods or exclusions, but the context is helpful.

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/nilsir/mcp-server-mysql'

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