Skip to main content
Glama
mcp-mysql-server

mcp-mysql-server

by f4ww4z

@f4ww4z/mcp-mysql-服务器

铁匠徽章

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

安装

通过 Smithery 安装

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

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

手动安装

npx @f4ww4z/mcp-mysql-server

Related MCP server: MCP MySQL Server

配置

服务器需要在您的 MCP 设置配置文件中设置以下环境变量:

建议使用

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "@f4ww4z/mcp-mysql-server", "mysql://user:password@localhost:port/database"],
    }
  }
}
{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "@f4ww4z/mcp-mysql-server"],
      "env": {
        "MYSQL_HOST": "your_host",
        "MYSQL_USER": "your_user",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}

运行评估

evals 包会加载一个 mcp 客户端,然后运行 index.ts 文件,因此测试之间无需重新构建。您可以通过在 npx 命令前添加前缀来加载环境变量。完整文档可在此处找到。

OPENAI_API_KEY=your-key  npx mcp-eval src/evals/evals.ts src/index.ts

可用工具

1. 连接数据库

使用提供的凭据建立与 MySQL 数据库的连接。

use_mcp_tool({
  server_name: "mysql",
  tool_name: "connect_db",
  arguments: {
    host: "localhost",
    user: "your_user",
    password: "your_password",
    database: "your_database"
  }
});

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",
  arguments: {}
});

5. describe_table

获取特定表的结构。

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

特征

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

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

  • 全面的错误处理和验证

  • TypeScript 支持

  • 自动连接管理

安全

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

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

  • 执行前验证查询

  • 完成后自动关闭连接

错误处理

服务器提供了常见问题的详细错误消息:

  • 连接失败

  • 无效查询

  • 缺少参数

  • 数据库错误

贡献

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

执照

麻省理工学院

Available Tools

4 tools
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.2/5.0

    Scored across 4 tools

    Disambiguation5/5

    Each tool serves a distinct purpose: describe_table shows schema, execute handles writes, list_tables lists tables, and query handles reads. No overlap or ambiguity.

    Naming Consistency2/5

    Naming is inconsistent: 'describe_table' and 'list_tables' follow verb_noun, while 'execute' is a bare verb and 'query' is a noun. No uniform pattern.

    Tool Count4/5

    Four tools is reasonable for basic database operations, covering schema inspection, reads, and writes. Could be slightly expanded, but not under- or over-scoped.

    Completeness3/5

    Covers essential CRUD and schema listing, but misses DDL operations like create/alter/drop table, which are common needs. Notable gap for schema modification.

    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
      290 npm
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      A Model Context Protocol server that enables AI models to interact with MySQL databases through a standardized interface, providing tools for querying, executing commands, and managing database schemas.
      7
      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
      -