Skip to main content
Glama
MySql MCP Server

MySql MCP Server

铁匠徽章

MySQL MCP 服务器

许可证:MIT

用于 MySQL 数据库的模型上下文协议 (MCP) 服务器,使 AI 模型能够通过结构化接口与 MySQL 数据库交互。

概述

MySQL MCP 服务器在 AI 模型和 MySQL 数据库之间架起了一座桥梁,使 AI 代理能够查询和分析 MySQL 数据。此实现遵循模型上下文协议 (MCP) 规范,并提供 Web 服务器和 CLI 两种操作模式。

Related MCP server: MySQL MCP Server

特征

  • MySQL数据库连接管理

  • SQL 查询执行

  • 表格列表和结构检查

  • 数据库列表和选择

  • 通过 SSE(服务器发送事件)进行实时状态监控

  • 用于测试 MCP 工具的 Web 界面

  • 支持 stdio 和 SSE 传输方法

  • Docker 部署就绪

安装

# Global installation
npm install -g mysql-mcp

# Local installation
npm install mysql-mcp

与人工智能助手一起使用

使用 Smithery.ai 上发布的服务器

MySQL MCP 服务器已在 Smithery.ai 上发布,可轻松与各种 AI 助手一起使用:

  1. 访问服务器:访问https://smithery.ai/server/@sussa3007/mysql-mcp

  2. 配置服务器:

    • 设置您的 MySQL 数据库连接详细信息:

      • MYSQL_HOST

      • MYSQL_PORT

      • MYSQL_USER

      • MYSQL密码

      • MYSQL_数据库

      • MYSQL_READONLY(可选,设置为 True 以实现只读访问)

  3. 与支持的 AI 平台连接:

    • 人类的克劳德

    • 光标人工智能

    • 风帆冲浪

    • 克莱恩

    • 机智

    • 恩康沃

    • 鹅

  4. 身份验证:登录 Smithery.ai 保存您的配置并生成身份验证令牌。

  5. 在 AI 提示中使用:一旦连接,您就可以在 AI 对话中使用 MySQL 工具,让助手执行数据库操作。

本地安装后使用

要使用本地开发的版本:

  1. 在项目目录中运行npm link

  2. 按如下方式配置您的设置文件:

{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["mysql-mcp"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database",
        "MYSQL_READONLY": "true"
      }
    }
  }
}

工具

地位

检查当前数据库连接状态。

  • 输入:无需参数

  • 返回:连接状态信息,包括主机、端口、数据库和用户名(如果已连接)。

连接

连接到 MySQL 数据库。

  • 输入:

    • host(可选字符串):数据库服务器主机名或 IP 地址

    • 端口(可选字符串):数据库服务器端口

    • 用户(可选字符串):数据库用户名

    • 密码(可选字符串):数据库密码

    • 数据库(可选字符串):要连接的数据库名称

  • 返回:连接成功消息或错误详情。

断开

关闭当前 MySQL 数据库连接。

  • 输入:无需参数

  • 返回:断开连接成功消息或错误详细信息。

询问

在连接的数据库上执行 SQL 查询。

  • 输入:

    • sql(字符串):要执行的 SQL 查询

    • params(可选数组):准备好的语句的参数

  • 返回:查询结果为 JSON 或错误消息。

列表表

获取当前数据库中的表列表。

  • 输入:无需参数

  • 返回:当前数据库中的表名列表。

描述表

获取特定表的结构。

  • 输入:

    • table(字符串):要描述的表的名称

  • 返回:表结构详细信息,包括列、类型、键和其他属性。

列出数据库

获取服务器上所有可访问数据库的列表。

  • 输入:无需参数

  • 返回:服务器上可用的数据库名称列表。

使用数据库

切换到不同的数据库。

  • 输入:

    • 数据库(字符串):要切换到的数据库的名称

  • 返回:确认消息或错误详情。

关键词

mysql、mcp、数据库、ai、模型上下文协议

执照

麻省理工学院

Available Tools

9 tools
connectC

Connect to a MySQL database.

Inputs: database, host, password, port, +1 more.

describe_tableA

Get the structure of a specific table.

Inputs: table (required).

disconnectB

Close the current MySQL database connection.

Inputs: random_string (required).

list_databasesB

Get a list of all accessible databases on the server.

Inputs: random_string (required).

list_tablesB

Get a list of tables in the current database.

Inputs: random_string (required).

queryC

Execute an SQL query on the connected database.

Inputs: sql (required), params.

set_readonlyB

Enable or disable read-only mode

Inputs: readonly (required).

statusC

Check the current database connection status.

Inputs: random_string (required).

use_databaseB

Switch to a different database.

Inputs: database (required).

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.5/5.0

    Scored across 9 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose with no ambiguity: connection management (connect, disconnect, status), database navigation (list_databases, use_database), table operations (list_tables, describe_table), query execution (query), and mode control (set_readonly). The descriptions reinforce non-overlapping functionality.

    Naming Consistency5/5

    All tool names follow a consistent snake_case pattern with clear verb_noun combinations (e.g., list_databases, describe_table, use_database). The naming is predictable and readable throughout the set.

    Tool Count5/5

    With 9 tools, the count is well-scoped for a MySQL database server, covering essential operations like connection management, database/table listing, query execution, and configuration. Each tool earns its place without redundancy.

    Completeness4/5

    The tool set provides strong coverage for core MySQL operations, including CRUD-like functionality via the query tool and lifecycle management. A minor gap is the lack of explicit tools for schema modification (e.g., create/alter/drop tables), but agents can work around this using SQL queries.

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      Enables AI models to perform MySQL database operations through a standardized interface, supporting secure connections, query execution, and comprehensive schema management.
      7
      79 npm
      33
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides secure access to MySQL databases for AI assistants, enabling safe SQL queries, table information retrieval, and data insertion with built-in security protections.
      2
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      A tool service that enables AI agents to interact with MySQL databases through natural language, supporting SQL queries, table structure retrieval, and connection testing.
      7
      32
      Apache 2.0