Skip to main content
Glama
enemyrr

MCP-MySQL Server

connect_db

Establish and manage secure connections to MySQL databases using a URL or configuration settings, enabling AI models to execute queries and manage schema effectively.

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 core handler function for the 'connect_db' tool. Loads the database configuration from provided arguments and establishes a MySQL connection pool, returning a success message.
    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)}`
        );
      }
    }
  • src/index.ts:396-420 (registration)
    Tool registration in ListToolsRequestHandler, defining name, description, and input schema for connect_db.
    {
      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:571-572 (registration)
    Dispatcher case in CallToolRequestHandler that routes 'connect_db' calls to the handleConnectDb method.
    case 'connect_db':
      return await this.handleConnectDb(request.params.arguments as unknown as ConnectionArgs);
  • TypeScript interface defining the input parameters for the connect_db tool.
    interface ConnectionArgs {
      url?: string;
      workspace?: string;
      host?: string;
      user?: string;
      password?: string;
      database?: string;
    }
  • Key helper function called by the handler to load and parse database connection configuration from URL, workspace .env files, or direct parameters.
    private async loadConfig(args: ConnectionArgs): Promise<ConnectionConfig> {
      console.error('Loading config with args:', args);
    
      if (args.url) {
        console.error('Using URL configuration');
        return this.parseConnectionUrl(args.url);
      }
    
      if (args.workspace) {
        console.error('Attempting workspace configuration from:', args.workspace);
        const config = await this.loadWorkspaceConfig(args.workspace);
        if (config) {
          console.error('Successfully loaded workspace config');
          return config;
        }
        console.error('Failed to load workspace config');
      }
    
      if (this.hasDirectConfig(args)) {
        console.error('Using direct configuration parameters');
        return this.createDirectConfig(args);
      }
    
      console.error('No valid configuration method found');
      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?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool connects to a database, implying it establishes a session or handle, but doesn't describe what happens after connection (e.g., persistence, timeout, error handling), authentication needs beyond parameters, or side effects. For a tool with zero annotation coverage, this is a significant gap in 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 extremely concise—a single sentence that directly states the tool's purpose and method without any fluff. It's front-loaded and wastes no words, making it easy for an agent to parse quickly. Every part of the sentence earns its place by conveying essential information.

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 tool's complexity (database connection with 6 parameters), lack of annotations, no output schema, and low schema description coverage, the description is incomplete. It doesn't cover behavioral aspects like connection lifecycle, error cases, or output format, leaving critical gaps for the agent to infer. This is inadequate for a tool that likely has significant operational implications.

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 33% (only 'url' and 'workspace' have descriptions), so the description must compensate but adds minimal value. It mentions 'URL or config', hinting at parameters like 'url' and possibly 'host', 'user', etc., but doesn't explain their semantics, relationships (e.g., mutual exclusivity), or defaults. The description provides some context but doesn't fully bridge the coverage gap, warranting a baseline score.

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 ('Connect to MySQL database') and the resource ('MySQL database'), making the purpose evident. It specifies the connection method ('using URL or config'), which helps distinguish it from other database operations. However, it doesn't explicitly differentiate from sibling tools like 'execute' or 'query', which might also involve database interactions, so it's not a perfect 5.

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., needing this connection before using other tools like 'query'), exclusions, or contextual cues. With sibling tools like 'execute' and 'query' available, the lack of usage guidelines leaves the agent uncertain about proper sequencing or 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

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

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