Skip to main content
Glama

MCP-MySQL Server

by enemyrr

@enemyrr/mcp-mysql-server

A Model Context Protocol server that provides MySQL database operations. This server enables AI models to interact with MySQL databases through a standardized interface.

Installation & Setup for Cursor IDE

Installing via Smithery

To install MySQL Database Server for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install @enemyrr/mcp-mysql-server --client claude

Installing Manually

  1. Clone and build the project:
git clone https://github.com/enemyrr/mcp-mysql-server.git cd mcp-mysql-server npm install npm run build
  1. Add the server in Cursor IDE settings:
    • Open Command Palette (Cmd/Ctrl + Shift + P)
    • Search for "MCP: Add Server"
    • Fill in the fields:
      • Name: mysql
      • Type: command
      • Command: node /absolute/path/to/mcp-mysql-server/build/index.js

Note: Replace /absolute/path/to/ with the actual path where you cloned and built the project.

Database Configuration

You can configure the database connection in three ways:

  1. Database URL in .env (Recommended):
DATABASE_URL=mysql://user:password@host:3306/database
  1. Individual Parameters in .env:
DB_HOST=localhost DB_USER=your_user DB_PASSWORD=your_password DB_DATABASE=your_database
  1. Direct Connection via Tool:
use_mcp_tool({ server_name: "mysql", tool_name: "connect_db", arguments: { url: "mysql://user:password@host:3306/database" // OR workspace: "/path/to/your/project" // Will use project's .env // OR host: "localhost", user: "your_user", password: "your_password", database: "your_database" } });

Available Tools

1. connect_db

Connect to MySQL database using URL, workspace path, or direct credentials.

2. query

Execute SELECT queries with optional prepared statement parameters.

use_mcp_tool({ server_name: "mysql", tool_name: "query", arguments: { sql: "SELECT * FROM users WHERE id = ?", params: [1] } });

3. execute

Execute INSERT, UPDATE, or DELETE queries with optional prepared statement parameters.

use_mcp_tool({ server_name: "mysql", tool_name: "execute", arguments: { sql: "INSERT INTO users (name, email) VALUES (?, ?)", params: ["John Doe", "john@example.com"] } });

4. list_tables

List all tables in the connected database.

use_mcp_tool({ server_name: "mysql", tool_name: "list_tables" });

5. describe_table

Get the structure of a specific table.

use_mcp_tool({ server_name: "mysql", tool_name: "describe_table", arguments: { table: "users" } });

6. create_table

Create a new table with specified fields and indexes.

use_mcp_tool({ server_name: "mysql", tool_name: "create_table", arguments: { table: "users", fields: [ { name: "id", type: "int", autoIncrement: true, primary: true }, { name: "email", type: "varchar", length: 255, nullable: false } ], indexes: [ { name: "email_idx", columns: ["email"], unique: true } ] } });

7. add_column

Add a new column to an existing table.

use_mcp_tool({ server_name: "mysql", tool_name: "add_column", arguments: { table: "users", field: { name: "phone", type: "varchar", length: 20, nullable: true } } });

Features

  • Multiple connection methods (URL, workspace, direct)
  • Secure connection handling with automatic cleanup
  • Prepared statement support for query parameters
  • Schema management tools
  • Comprehensive error handling and validation
  • TypeScript support
  • Automatic workspace detection

Security

  • Uses prepared statements to prevent SQL injection
  • Supports secure password handling through environment variables
  • Validates queries before execution
  • Automatically closes connections when done

Error Handling

The server provides detailed error messages for:

  • Connection failures
  • Invalid queries or parameters
  • Missing configuration
  • Database errors
  • Schema validation errors

Contributing

Contributions are welcome! Please feel free to submit a Pull Request to https://github.com/enemyrr/mcp-mysql-server

License

MIT

Install Server
A
security – no known vulnerabilities
F
license - not found
A
quality - confirmed to work

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

使 AI 模型能够通过标准化接口执行 MySQL 数据库操作,支持安全连接、查询执行和全面的模式管理。

  1. Cursor IDE 的安装和设置
    1. 通过 Smithery 安装
    2. 手动安装
  2. 数据库配置
    1. 可用工具
      1. 1. 连接数据库
      2. 2. 查询
      3. 3. 执行
      4. 4. 列表表
      5. 5. describe_table
      6. 6. 创建表
      7. 7. 添加列
    2. 特征
      1. 安全
        1. 错误处理
          1. 贡献
            1. 执照

              Related MCP Servers

              • A
                security
                A
                license
                A
                quality
                This server enables AI models to interact with MySQL databases through a standardized interface.
                Last updated -
                5
                965
                97
                JavaScript
                MIT License
                • Linux
                • Apple
              • -
                security
                A
                license
                -
                quality
                A server that enables AI models to interact with MySQL databases through a Model Control Protocol, providing tools for table creation, schema inspection, query execution, and data retrieval.
                Last updated -
                26
                Python
                MIT License
                • Linux
                • Apple
              • A
                security
                A
                license
                A
                quality
                Connect and interact with MySQL databases seamlessly. Execute SQL queries, manage database connections, and retrieve data directly through AI assistants. Enhance your AI capabilities with structured access to your MySQL data.
                Last updated -
                9
                0
                16
                TypeScript
                MIT License
              • -
                security
                F
                license
                -
                quality
                Enables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.
                Last updated -
                Python
                • Linux
                • Apple

              View all related MCP servers

              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