npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@malove86/mcp-mysql-server

v0.2.4

Published

A Model Context Protocol server for MySQL database operations

Downloads

221

Readme

mcp-mysql-server

一个基于Model Context Protocol的MySQL数据库操作服务器。该服务器使AI模型能够通过标准化接口与MySQL数据库进行交互。

安装

npx @malove86/mcp-mysql-server

配置

服务器支持两种部署模式:

1. 本地运行模式

在MCP设置配置文件中使用命令行运行:

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "@malove86/mcp-mysql-server"],
      "env": {
        "MYSQL_HOST": "your_host",
        "MYSQL_USER": "your_user",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database",
        "MYSQL_PORT": "3306"
      }
    }
  }
}

2. 远程URL模式 (v0.2.2+)

指向远程运行的MCP服务器:

{
  "mcpServers": {
    "mcp-mysql-server": {
      "url": "http://your-server-address:port/mcp-mysql-server"
    }
  }
}

在远程服务器上,您需要设置环境变量后启动MCP服务器:

# 设置环境变量
export MYSQL_HOST=your_host
export MYSQL_USER=your_user
export MYSQL_PASSWORD=your_password
export MYSQL_DATABASE=your_database
export MYSQL_PORT=3306  # 可选,默认为3306

# 启动服务器
npx @malove86/mcp-mysql-server

注意:MYSQL_PORT是可选的,默认值为3306。

新特性 (v0.2.2+)

  • 自动数据库连接:在服务器启动时,如果设置了环境变量,会自动尝试连接数据库
  • 无需客户端参数:当使用URL模式时,客户端不需要提供数据库连接信息
  • 无感知数据库操作:可以直接使用list_tablesquery等工具,无需先调用connect_db
  • 更安全:敏感的数据库凭据只在服务器端存在,不会暴露在客户端对话中
  • 优雅的容错:即使初始连接失败,后续操作会自动重试连接

可用工具

1. connect_db

使用提供的凭据建立与MySQL数据库的连接。如果已通过环境变量设置了连接,此工具是可选的。

{
  "host": "localhost",
  "user": "root",
  "password": "your_password",
  "database": "your_database",
  "port": 3306  // 可选,默认为3306
}

2. query

执行SELECT查询,支持可选的预处理语句参数。

{
  "sql": "SELECT * FROM users WHERE id = ?",
  "params": [1]  // 可选参数
}

3. list_tables

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

{
  "random_string": "dummy"  // 需要任意字符串参数
}

4. describe_table

获取特定表的结构。

{
  "table": "users"
}

功能特点

  • 安全的连接处理,自动清理
  • 支持预处理语句参数
  • 全面的错误处理和验证
  • TypeScript支持
  • 自动连接管理
  • 服务器环境变量配置
  • 支持URL远程连接模式

安全性

  • 使用预处理语句防止SQL注入
  • 通过环境变量支持安全密码处理
  • 执行前验证查询
  • 完成后自动关闭连接
  • URL模式下敏感凭据不暴露在客户端

贡献

欢迎贡献!请随时提交Pull Request到 https://github.com/Malove86/mcp-mysql-server.git

许可证

MIT