Skip to main content
Glama
MCP MySQL Server

MCP MySQL Server

by kevinbin

@enemyrr/mcp-mysql-服务器

铁匠徽章

提供 MySQL 数据库操作的模型上下文协议服务器。该服务器使 AI 模型能够通过标准化接口与 MySQL 数据库交互。

Cursor IDE 的安装和设置

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 MySQL 数据库服务器:

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

手动安装

  1. 克隆并构建项目:

git clone https://github.com/enemyrr/mcp-mysql-server.git
cd mcp-mysql-server
npm install
npm run build
  1. 在 Cursor IDE 设置中添加服务器:

    • 打开命令面板(Cmd/Ctrl + Shift + P)

    • 搜索“MCP:添加服务器”

    • 填写字段:

      • 名称: mysql

      • 类型: command

      • 命令: node /absolute/path/to/mcp-mysql-server/build/index.js

注意:将/absolute/path/to/替换为您克隆和构建项目的实际路径。

Related MCP server: MCP MySQL Server

数据库配置

您可以通过三种方式配置数据库连接:

  1. .env 中的数据库 URL (推荐):

DATABASE_URL=mysql://user:password@host:3306/database
  1. .env 中的各个参数:

DB_HOST=localhost
DB_USER=your_user
DB_PASSWORD=your_password
DB_DATABASE=your_database
  1. 通过工具直接连接:

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"
  }
});

可用工具

1. 连接数据库

使用 URL、工作区路径或直接凭据连接到 MySQL 数据库。

2. 查询

使用可选的准备好的语句参数执行 SELECT 查询。

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

3. 执行

使用可选的准备好的语句参数执行 INSERT、UPDATE 或 DELETE 查询。

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

4. 列表表

列出所连接数据库中的所有表。

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

5. describe_table

获取特定表的结构。

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

6. 创建表

创建具有指定字段和索引的新表。

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. 添加列

向现有表中添加新列。

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

特征

  • 多种连接方式(URL、工作区、直接)

  • 通过自动清理来安全处理连接

  • 查询参数的预处理语句支持

  • 架构管理工具

  • 全面的错误处理和验证

  • TypeScript 支持

  • 自动工作区检测

安全

  • 使用准备好的语句来防止 SQL 注入

  • 支持通过环境变量进行安全密码处理

  • 执行前验证查询

  • 完成后自动关闭连接

错误处理

服务器提供以下详细的错误消息:

  • 连接失败

  • 无效的查询或参数

  • 缺少配置

  • 数据库错误

  • 架构验证错误

贡献

欢迎贡献!请随时向https://github.com/enemyrr/mcp-mysql-server提交 Pull 请求。

执照

麻省理工学院

Available Tools

7 tools
add_columnC

Add a new column to existing table

Inputs: field (required), table (required).

connect_dbC

Connect to MySQL database using URL or config

Inputs: database, host, password, url, +2 more.

create_tableC

Create a new table in the database

Inputs: fields (required), table (required), indexes.

describe_tableB

Get table structure

Inputs: table (required).

executeB

Execute an INSERT, UPDATE, or DELETE query

Inputs: sql (required), params.

list_tablesB

List all tables in the database

Inputs: no named parameters.

queryB

Execute a SELECT query

Inputs: sql (required), params.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 7 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose with no ambiguity: connect_db handles connections, list_tables and describe_table provide metadata, create_table and add_column manage schema, while execute and query separate write and read operations. The descriptions make it easy to distinguish between similar tools like execute vs query or create_table vs add_column.

    Naming Consistency5/5

    All tools follow a consistent verb_noun pattern with clear, descriptive names (e.g., connect_db, list_tables, create_table). There are no deviations in naming conventions, and the snake_case style is applied uniformly throughout the toolset.

    Tool Count5/5

    With 7 tools, this server is well-scoped for basic MySQL database operations. Each tool earns its place by covering essential functions: connection management, schema operations, metadata queries, and data manipulation. The count is neither too sparse nor overwhelming for the domain.

    Completeness4/5

    The toolset provides solid coverage for core MySQL workflows, including connection, schema management (create, modify), and data operations (read/write). A minor gap exists in lacking explicit tools for updating or deleting tables (e.g., drop_table, alter_table), but agents can work around this using the execute tool for such DDL queries.

    Maintenance

    ActivityInactive
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      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.
      28
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      A Model Context Protocol server that enables AI models to interact with MySQL databases, providing tools for querying, executing statements, listing tables, and describing table structures.
      5
      329 npm
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      A Model Context Protocol server that enables AI models to interact with MySQL databases through natural language, supporting SQL queries, table creation, and schema exploration.
      3
      -