Skip to main content
Glama
kevinbin

MCP MySQL Server

by kevinbin

connect_db

Establish a connection to a MySQL database using a URL or configuration parameters. Integrate database interactions into workflows via the MCP MySQL Server's standardized interface.

Instructions

Connect to MySQL database using URL or config

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNo
hostNo
passwordNo
urlNoDatabase URL (mysql://user:pass@host:port/db)
userNo
workspaceNoProject workspace path

Implementation Reference

  • The main handler function for the 'connect_db' tool. Loads database configuration from input arguments using loadConfig, establishes and tests the connection with ensureConnection, returns a success message, or throws an MCP error on failure.
    private async handleConnectDb(args: ConnectionArgs) {
      this.config = await this.loadConfig(args);
    
      try {
        await this.ensureConnection();
        return {
          content: [
            {
              type: 'text',
              text: `Successfully connected to database ${this.config.database} at ${this.config.host}`
            }
          ]
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to connect to database: ${getErrorMessage(error)}`
        );
      }
    }
  • TypeScript interface defining the expected input shape for connect_db tool arguments.
    interface ConnectionArgs {
      url?: string;
      workspace?: string;
      host?: string;
      user?: string;
      password?: string;
      database?: string;
    }
  • src/index.ts:350-374 (registration)
    Registration of the 'connect_db' tool in the ListToolsRequestSchema handler, including name, description, and JSON inputSchema.
    {
      name: 'connect_db',
      description: 'Connect to MySQL database using URL or config',
      inputSchema: {
        type: 'object',
        properties: {
          url: {
            type: 'string',
            description: 'Database URL (mysql://user:pass@host:port/db)',
            optional: true
          },
          workspace: {
            type: 'string',
            description: 'Project workspace path',
            optional: true
          },
          // Keep existing connection params as fallback
          host: { type: 'string', optional: true },
          user: { type: 'string', optional: true },
          password: { type: 'string', optional: true },
          database: { type: 'string', optional: true }
        },
        // No required fields - will try different connection methods
      },
    },
  • src/index.ts:519-520 (registration)
    Dispatch routing in CallToolRequestSchema handler that casts arguments to ConnectionArgs and calls the handleConnectDb function.
    case 'connect_db':
      return await this.handleConnectDb(request.params.arguments as unknown as ConnectionArgs);
  • Key helper function used by the handler to derive ConnectionConfig from input args: tries URL parse, workspace .env load, or direct connection params.
    private async loadConfig(args: ConnectionArgs): Promise<ConnectionConfig> {
      if (args.url) return this.parseConnectionUrl(args.url);
      if (args.workspace) {
        const config = await this.loadWorkspaceConfig(args.workspace);
        if (config) return config;
      }
      if (this.hasDirectConfig(args)) return this.createDirectConfig(args);
    
      throw new McpError(
        ErrorCode.InvalidParams,
        'No valid configuration provided. Please provide either a URL, workspace path, or connection parameters.'
      );
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action 'connect' but doesn't describe what the connection entails (e.g., authentication requirements, rate limits, persistence, or what happens on failure). This is a significant gap for a tool that likely involves network operations and security.

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 is front-loaded with the core purpose. There is no wasted text, making it highly concise and well-structured for quick understanding.

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, no output schema, and low schema description coverage (33%), the description is incomplete. It lacks details on authentication, error handling, connection lifecycle, and how it integrates with sibling tools, making it inadequate for safe and 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?

The description mentions 'using URL or config', which hints at the 'url' parameter and possibly others like 'host', 'user', 'password', but doesn't add detailed meaning beyond the schema. With schema description coverage at 33% (only 'url' and 'workspace' have descriptions), the description partially compensates but doesn't fully explain the semantics of all 6 parameters.

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', specifying it establishes a connection. However, it doesn't differentiate from sibling tools like 'execute' or 'query' that might also involve database operations, making it clear but not sibling-distinctive.

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 like 'execute' or 'query', nor does it mention prerequisites such as needing to connect before performing other operations. It lacks explicit when/when-not instructions or context for usage.

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

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