Skip to main content
Glama
Atomzzm
by Atomzzm

connect_db

Establish a connection to a MySQL database by providing host, user, password, and database name to enable database interactions through the MCP MySQL Server.

Instructions

Connect to MySQL database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYesDatabase host
userYesDatabase user
passwordYesDatabase password
databaseYesDatabase name

Implementation Reference

  • The main handler function for the 'connect_db' tool. Validates arguments, closes existing connection, sets database config, establishes connection using ensureConnection, and returns success or throws error.
    private async handleConnectDb(args: any) {
      if (!args.host || !args.user || !args.password || !args.database) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Missing required database configuration parameters'
        );
      }
    
      // Close existing connection if any
      if (this.connection) {
        await this.connection.end();
        this.connection = null;
      }
    
      this.config = {
        host: args.host,
        user: args.user,
        password: args.password,
        database: args.database,
      };
    
      try {
        await this.ensureConnection();
        return {
          content: [
            {
              type: 'text',
              text: 'Successfully connected to database',
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to connect to database: ${getErrorMessage(error)}`
        );
      }
    }
  • Input schema defining required parameters for connecting to MySQL: host, user, password, database.
    inputSchema: {
      type: 'object',
      properties: {
        host: {
          type: 'string',
          description: 'Database host',
        },
        user: {
          type: 'string',
          description: 'Database user',
        },
        password: {
          type: 'string',
          description: 'Database password',
        },
        database: {
          type: 'string',
          description: 'Database name',
        },
      },
      required: ['host', 'user', 'password', 'database'],
    },
  • src/index.ts:99-124 (registration)
    Tool registration in the ListTools response, including name, description, and input schema.
    {
      name: 'connect_db',
      description: 'Connect to MySQL database',
      inputSchema: {
        type: 'object',
        properties: {
          host: {
            type: 'string',
            description: 'Database host',
          },
          user: {
            type: 'string',
            description: 'Database user',
          },
          password: {
            type: 'string',
            description: 'Database password',
          },
          database: {
            type: 'string',
            description: 'Database name',
          },
        },
        required: ['host', 'user', 'password', 'database'],
      },
    },
  • src/index.ts:195-196 (registration)
    Dispatch in CallToolRequest handler switch statement routing 'connect_db' to its handler.
    case 'connect_db':
      return await this.handleConnectDb(request.params.arguments);
  • Helper method to ensure database connection exists, creates it if needed using the stored config, called by handleConnectDb.
    private async ensureConnection() {
      if (!this.config) {
        throw new McpError(
          ErrorCode.InvalidRequest,
          'Database configuration not set. Use connect_db tool first.'
        );
      }
    
      if (!this.connection) {
        try {
          this.connection = await mysql.createConnection(this.config);
        } catch (error) {
          throw new McpError(
            ErrorCode.InternalError,
            `Failed to connect to database: ${getErrorMessage(error)}`
          );
        }
      }
    }
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 of behavioral disclosure. It states the tool connects to a database, implying it might establish a session or handle authentication, but it doesn't describe what happens on success or failure, whether connections are persistent, timeouts, or error handling. For a tool with 4 required parameters and no annotations, this leaves significant behavioral 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 zero waste: 'Connect to MySQL database'. It is appropriately sized and front-loaded, clearly stating the core action without unnecessary details. Every word earns its place, making it highly concise and well-structured.

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 4 required parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., a connection handle, success status), error conditions, or how it integrates with sibling tools. For a tool that likely enables other operations, more context is needed to guide the agent effectively.

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?

The input schema has 100% description coverage, with clear documentation for all 4 parameters (host, user, password, database). The description adds no additional meaning beyond what the schema provides, such as format examples or constraints. Given the high schema coverage, the baseline score of 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Connect to MySQL database' clearly states the verb ('Connect') and resource ('MySQL database'), making the purpose understandable. However, it doesn't distinguish this tool from potential sibling tools like 'describe_table' or 'execute', which might also involve database operations. The purpose is clear but lacks sibling differentiation.

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 database tools), exclusions, or context for usage relative to siblings like 'query' or 'list_tables'. Without any usage instructions, the agent must infer when this tool is appropriate.

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

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