MCP MySQL Server logo

MCP MySQL Server

Community
TickHaiJun

MCP MySQL Server 是一个基于 @modelcontextprotocol/sdk 的 MySQL 工具服务,支持 SQL 查询、表结构获取、连接检测等功能,适用于 AI 代理、自动化工具等场景。

PublisherTickHaiJun
Repositorymysql-mcp-server
LanguageJavaScript
Forks
13
Stars
32
Available tools
0
Transport typestdio
Categories
LicenseApache-2.0
Links
  • Connect tools to AI workflows

    MCP MySQL Server exposes MCP capabilities that can be used by compatible AI clients and agents.

  • 0 available tools

    Browse the callable actions below, including names and descriptions when provided by the server.

  • Ready-to-copy setup

    Use the installation snippets to configure this server in your preferred MCP client.

  • Open source signals

    32 stars and 13 forks from the linked repository.

MCP MySQL Server

项目简介

MCP MySQL Server 是一个基于 @modelcontextprotocol/sdk 的 MySQL 工具服务,支持 SQL 查询、表结构获取、连接检测等功能,适用于 AI 代理、自动化工具等场景。

主要功能

  • 执行 SQL 查询(SELECT、INSERT、UPDATE、DELETE)
  • 获取数据库表结构信息
  • 检测数据库连接状态
  • SQL 语句和参数安全校验
  • 优雅的服务启动与关闭

架构说明

  • 入口文件:src/index.js 启动和管理 MCP 服务器实例
  • 服务实现:src/server.js 实现 MCP Server,注册工具、处理请求
  • 数据库管理:src/database.js 管理 MySQL 连接池、执行 SQL、获取表结构
  • 配置管理:src/config.js 支持 .env 环境变量和默认配置
  • 安全校验:src/validators.js 校验 SQL 语句和参数,防止危险操作和注入

安装与使用

  1. 克隆项目
    bash
    git clone https://github.com/yourname/mcp-mysql-server.git
    cd mcp-mysql-server
  2. 安装依赖
    bash
    npm install
  3. 配置数据库连接(可选,支持 .env 文件)
    env
    DB_HOST=localhost
    DB_PORT=3306
    DB_USER=root
    DB_PASSWORD=yourpassword
    DB_NAME=yourdatabase
  4. 启动服务
    bash
    node src/index.js

配置说明

  • 支持通过环境变量或 .env 文件配置数据库和服务参数
  • 主要配置项见 src/config.js

主要实现细节

  • 使用 mysql2/promise 实现高效的连接池和异步 SQL 执行
  • 所有 SQL 语句和参数均经过安全校验,防止危险操作和 SQL 注入
  • MCP Server 支持三大工具:
    • execute_sql:执行 SQL 查询
    • get_tables_info:获取所有表及字段结构
    • get_connection_status:检测数据库连接
  • 优雅处理进程信号,支持平滑关闭

安全性说明

  • 禁止 DROP/TRUNCATE/ALTER 等危险操作
  • 检查常见 SQL 注入模式
  • 限制参数数量,防止滥用
  • 禁用多语句执行

在 Cursor 中 验证 开发的 MCP Server 是否能运行

Cursor 添加 MCP Server

通过 Cursor Settings -> MCP Add new global MCP server,可以将 MCP 服务添加为全局可用。这意味着你配置的 MCP 服务将在所有项目中生效。

也可以只针对 项目级别 添加

在项目的 .cursor目录下,新建一个 mcp.json文件进行配置,这样的设置只会对特定项目生效。

mcp server 的格式是如何呢

配置 server 基本格式规范

jsx
{
  "mcpServers": {
    "<server-name>": {
      "command": "<启动命令>",
      "args": ["<参数1>", "<参数2>", ...],
      "env": {
        "<环境变量名1>": "<值1>",
        "<环境变量名2>": "<值2>",
        ...
      },
      "transport": "<传输协议>",
      "port": <端口号>,
      "host": "<主机地址>"
    }
  }
}

查询数据库表和字段信息

查看当前数据库是否连接

查询表里数据

看到这里,是不是觉得很神奇?我们用自然语言描述需求,AI助手自动生成并执行SQL,然后分析结果给出结论。

依赖

贡献方式

欢迎提交 Issue 和 PR 参与贡献!

许可证

ISC License

Installation

TypingMind
{
  "mcpServers": {
    "mysql-mcp-server": {
      "command": "node",
      "args": [
        "src/index.js"
      ]
    }
  }
}

Use MCP MySQL Server MCP with multiple AI models

TypingMind connects MCP tools at the workspace level, so once MCP MySQL Server is connected, you can use it with different AI models in TypingMind instead of setting it up separately for each model. This MCP runs locally through the TypingMind MCP connector on your device.

Setup guide to use the local connector

Use this when the MCP server needs access to local files, apps, or private resources on your computer.

1

Open the MCP settings

In TypingMind, go to Settings, Advanced Settings, then Model Context Protocol and choose Setup Connector.

  1. Open TypingMind in your browser.
  2. Click the Settings icon.
  3. Go to Advanced Settings.
  4. Open the Model Context Protocol section.
  5. Click Setup Connector and choose This Device.
TypingMind MCP connector setup screen with This Device selected
2

Run the connector command

Choose This Device, copy the command from TypingMind, and run it in Terminal. Keep the process running while you use MCP.

  1. Copy the setup command shown by TypingMind.
  2. Open Terminal on macOS or Windows Terminal on Windows.
  3. Paste and run the command.
  4. Approve the package install if Terminal asks you to proceed.
  5. Keep the Terminal window running while using MCP tools.
3

Add MCP MySQL Server as a server

When the connector status is Ready, click Edit Servers and paste the MCP server configuration.

  1. Wait until the connector status shows Ready.
  2. Click Edit Servers.
  3. Paste the MCP MySQL Server MCP server configuration.
  4. Save the server list.
  5. Refresh if you want to confirm the connector is still ready.
TypingMind MCP settings showing active server and Edit Servers button
{
  "mcpServers": {
    "mysql-mcp-server": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-mysql-server"
      ]
    }
  }
}
4

Use it across models

Save the server list, open Plugins, enable the MCP MySQL Server MCP tools, then select any supported AI model in TypingMind and use the tools in chat or assign them to an AI agent.

  1. Open the Plugins page in TypingMind.
  2. Enable the MCP MySQL Server MCP tools.
  3. Start a chat and choose the AI model you want to use.
  4. Use the MCP tools in chat or assign them to an AI agent.
  5. Switch to another AI model whenever needed without reconnecting MCP.
TypingMind chat using enabled MCP tools with a selected AI model
Can you use MCP MySQL Server to help me with this task?
MCP MySQL Server
Sure. I read it.
Here is what I found using MCP MySQL Server.

Frequently asked questions

What is the MCP MySQL Server MCP server used for?

MCP MySQL Server is an MCP server that lets compatible AI clients connect to external tools and context. In TypingMind, you can add this MCP server once and make its tools available in your AI workspace.

Can I use MCP MySQL Server MCP with multiple AI models in TypingMind?

Yes. TypingMind connects MCP tools at the workspace level, so you can use MCP MySQL Server with different AI models such as Claude, ChatGPT, Gemini, or other models you have configured in TypingMind without setting up the MCP server separately for each model.

Why use MCP MySQL Server MCP with TypingMind?

TypingMind is one of the best frontends for LLM chat because it brings multiple AI models, prompts, plugins, AI agents, API keys, and MCP tools into one workspace. With MCP MySQL Server connected, you can use its MCP tools across your preferred models while keeping your chat workflow organized in TypingMind.

How do I connect MCP MySQL Server MCP to TypingMind?

MCP MySQL Server runs through the TypingMind local MCP connector. This is best when the MCP server needs access to local files, desktop apps, command-line tools, or private resources on your computer.

What tools does MCP MySQL Server MCP provide in TypingMind?

MCP MySQL Server exposes MCP capabilities that can be enabled from the TypingMind Plugins page and used in chat or assigned to AI agents.

Do I need to share my API keys with TypingMind to use MCP MySQL Server MCP?

No. TypingMind is local-first and lets you keep your model providers, API keys, prompts, and MCP configuration under your control. If MCP MySQL Server requires authentication, add the required headers, OAuth settings, or local configuration for that MCP server when you create the connection.

Related MCP Servers

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇