Skip to main content
Glama
pickstar-2002

MySQL MCP Server

mysql_connect

Establish a connection to a MySQL database by providing host, user credentials, and optional database name to enable database operations through the MySQL MCP Server.

Instructions

连接到 MySQL 数据库

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostYesMySQL 服务器地址
portNoMySQL 端口号
userYes用户名
passwordYes密码
databaseNo数据库名称(可选)

Implementation Reference

  • Input schema definition for the mysql_connect tool, including parameters like host, port, user, password, and optional database.
    {
      name: 'mysql_connect',
      description: '连接到 MySQL 数据库',
      inputSchema: {
        type: 'object',
        properties: {
          host: { type: 'string', description: 'MySQL 服务器地址' },
          port: { type: 'number', description: 'MySQL 端口号', default: 3306 },
          user: { type: 'string', description: '用户名' },
          password: { type: 'string', description: '密码' },
          database: { type: 'string', description: '数据库名称(可选)' },
        },
        required: ['host', 'user', 'password'],
      },
    },
  • Handler method in MySQLMCPServer that validates config, calls DatabaseManager.connect, and returns success message.
    private async handleConnect(args: MySQLConfig): Promise<any> {
      const config = { ...getConfig(), ...args };
      validateConfig(config);
      
      await this.dbManager.connect(config);
      
      return {
        content: [
          {
            type: 'text',
            text: `成功连接到 MySQL 服务器: ${config.host}:${config.port}`,
          },
        ],
      };
    }
  • Core implementation in DatabaseManager that creates mysql2 connection pool using provided config, tests the connection with ping, and logs success.
    async connect(config: MySQLConfig): Promise<void> {
      try {
        this.config = config;
        this.pool = mysql.createPool({
          host: config.host,
          port: config.port,
          user: config.user,
          password: config.password,
          database: config.database,
          connectionLimit: config.connectionLimit || 10,
          multipleStatements: true
        });
    
        // 测试连接
        const connection = await this.pool.getConnection();
        await connection.ping();
        connection.release();
        
        console.log(`已成功连接到 MySQL 服务器: ${config.host}:${config.port}`);
      } catch (error) {
        throw new Error(`连接 MySQL 失败: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • src/server.ts:233-234 (registration)
    Switch case in CallToolRequestSchema handler that routes mysql_connect calls to handleConnect method.
    case 'mysql_connect':
      return await this.handleConnect(args as any);
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 action 'connect' but doesn't describe what this entails: whether it establishes a persistent session, requires authentication, has side effects (e.g., opening network connections), returns a connection handle, or includes error handling. For a critical initialization 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 a single, efficient sentence in Chinese ('连接到 MySQL 数据库') that directly states the tool's action. It is front-loaded with the core purpose and wastes no words, making it easy to parse quickly. For a simple connection tool, this conciseness is appropriate and effective.

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 incomplete. It doesn't explain the return value (e.g., connection ID or status), error conditions, or how the connection integrates with sibling tools (e.g., mysql_query might require an active connection). For a foundational tool in a MySQL suite, 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?

Schema description coverage is 100%, with all parameters documented in the input schema (host, port, user, password, database). The description adds no additional meaning beyond the schema, such as parameter interactions (e.g., database is optional for initial connection) or examples. With high schema coverage, the baseline is 3, as the description doesn't compensate but also doesn't detract.

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 '连接到 MySQL 数据库' (Connect to MySQL database) states the basic action but is vague about scope and differentiation. It specifies the verb 'connect' and resource 'MySQL database', but doesn't clarify if this establishes a persistent connection, session, or temporary link, nor how it differs from sibling tools like mysql_disconnect or mysql_query. The purpose is understandable but lacks specificity for agent decision-making.

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., must be called before other MySQL operations), exclusions (e.g., not needed for mysql_list_databases if already connected), or contextual cues. With siblings like mysql_disconnect and mysql_query, the agent must infer usage from the name alone, which is insufficient for reliable 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/pickstar-2002/mysql-mcp'

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