Skip to main content
Glama
sajithrw

MCP MySQL Server

by sajithrw

mysql_connect

Establish a connection to MySQL databases by providing host, user credentials, and optional parameters like database name and SSL settings.

Instructions

Connect to a MySQL database with provided connection parameters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYesMySQL server hostname or IP address
portNoMySQL server port (default: 3306)
userYesDatabase username
passwordYesDatabase password
databaseNoDatabase name (optional)
sslNoUse SSL connection (default: false)

Implementation Reference

  • The handleConnect method that executes the mysql_connect tool logic: parses and validates connection parameters using ConfigSchema, closes any existing pool, creates a new MySQL connection pool using createConnection, tests it implicitly, and returns a success message.
    private async handleConnect(args: any) {
      try {
        const config = ConfigSchema.parse(args);
        this.config = config;
        
        // Close existing connection if any
        if (this.pool) {
          await this.pool.end();
        }
    
        this.pool = await this.createConnection(config);
        
        return {
          content: [
            {
              type: "text",
              text: `Successfully connected to MySQL server at ${config.host}:${config.port}${config.database ? ` (database: ${config.database})` : ""}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`Connection failed: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Zod schema (ConfigSchema) used to validate input parameters for the mysql_connect tool, matching the tool's inputSchema definition.
    const ConfigSchema = z.object({
      host: z.string(),
      port: z.number().optional().default(3306),
      user: z.string(),
      password: z.string(),
      database: z.string().optional(),
      ssl: z.boolean().optional().default(false),
      connectionLimit: z.number().optional().default(10),
    });
    
    type Config = z.infer<typeof ConfigSchema>;
  • src/index.ts:100-135 (registration)
    Registration of the mysql_connect tool in the ListTools response, including name, description, and input schema specification.
    {
      name: "mysql_connect",
      description: "Connect to a MySQL database with provided connection parameters",
      inputSchema: {
        type: "object",
        properties: {
          host: {
            type: "string",
            description: "MySQL server hostname or IP address",
          },
          port: {
            type: "number",
            description: "MySQL server port (default: 3306)",
            default: 3306,
          },
          user: {
            type: "string",
            description: "Database username",
          },
          password: {
            type: "string",
            description: "Database password",
          },
          database: {
            type: "string",
            description: "Database name (optional)",
          },
          ssl: {
            type: "boolean",
            description: "Use SSL connection (default: false)",
            default: false,
          },
        },
        required: ["host", "user", "password"],
      },
    },
  • Supporting method createConnection that actually sets up the mysql2/promise Pool with config options, applies SSL if needed, and tests the connection with ping before returning the pool.
    private async createConnection(config: Config): Promise<mysql.Pool> {
      try {
        const poolConfig: mysql.PoolOptions = {
          host: config.host,
          port: config.port,
          user: config.user,
          password: config.password,
          database: config.database,
          connectionLimit: config.connectionLimit,
          multipleStatements: false,
        };
    
        if (config.ssl) {
          poolConfig.ssl = {};
        }
    
        this.pool = mysql.createPool(poolConfig);
    
        // Test the connection
        const connection = await this.pool.getConnection();
        await connection.ping();
        connection.release();
    
        return this.pool;
      } catch (error) {
        throw new Error(`Failed to connect to MySQL: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • src/index.ts:248-251 (registration)
    Tool dispatch registration in the CallToolRequest handler switch statement, routing 'mysql_connect' calls to the handleConnect method.
    switch (name) {
      case "mysql_connect":
        return await this.handleConnect(args);
      case "mysql_query":
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure but offers minimal information. It mentions 'connection parameters' but doesn't describe what happens after connection (e.g., establishes a session, returns a connection handle, may have timeout/error behavior, or requires subsequent disconnect). For a tool that likely creates persistent state, this is inadequate behavioral transparency.

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 gets straight to the point with zero wasted words. It's appropriately sized for a connection tool and front-loads the essential information without unnecessary elaboration.

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 a database connection tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what the tool returns (e.g., a connection object, status code), how errors are handled, whether the connection persists, or how it integrates with sibling tools. For a foundational tool in a database suite, this leaves critical gaps.

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 fully documents all 6 parameters. The description adds no additional parameter semantics beyond what's in the schema (it just says 'with provided connection parameters'). This meets the baseline of 3 when the schema does the heavy lifting, but earns no extra credit for adding value.

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 verb ('Connect') and resource ('MySQL database'), making the purpose immediately understandable. However, it doesn't distinguish this tool from its siblings like mysql_disconnect or explain how it relates to other database operations, missing the differentiation that would earn a perfect score.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., that this must be called before other mysql_* tools), when not to use it (e.g., if already connected), or how it relates to sibling tools like mysql_disconnect. This leaves the agent with insufficient context for proper tool selection.

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

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