Skip to main content
Glama
daedalus

mcp-mysql-connector

by daedalus

mcp-mysql-connector

MCP 服务器,将 MySQL 数据库功能以工具形式提供给 LLM 智能体。

mcp-name: io.github.daedalus/mcp-mysql-connector

PyPI Python Coverage Ruff

概述

mcp-mysql-connector 是一个模型上下文协议(MCP)服务器,以工具形式为 LLM 智能体提供 MySQL 数据库操作能力。它允许 AI 助手通过标准化协议与 MySQL 数据库交互,支持:

  • 数据库与表管理

  • 查询执行

  • 用户认证与权限管理

  • Schema 结构内省

  • 事务控制

Related MCP server: MCP Server MySQL

安装

pip install mcp-mysql-connector

快速开始

运行服务器

# Run with stdio transport (default)
mcp-mysql-connector

# Or run programmatically
python -c "from mcp_mysql import mcp; mcp.run()"

配置

使用 connect 工具连接到 MySQL:

{
  "host": "localhost",
  "port": 3306,
  "user": "root",
  "password": "your_password",
  "database": "your_database"
}

MCP 工具

连接管理

工具

描述

connect

连接到 MySQL 数据库

disconnect

从 MySQL 断开连接

is_connected

检查连接状态

commit

提交当前事务

rollback

回滚当前事务

查询执行

工具

描述

execute_query

执行原始 SQL 查询并返回结果

数据库操作

工具

描述

list_databases

列出服务器上的所有数据库

create_database

创建新数据库

drop_database

删除数据库

database_exists

检查数据库是否存在

表操作

工具

描述

list_tables

列出数据库中的表

describe_table

获取表结构

create_table

创建新表

drop_table

删除表

table_exists

检查表是否存在

列与索引操作

工具

描述

show_columns

显示列详细信息

show_indexes

显示索引详细信息

create_index

创建索引

drop_index

删除索引

用户管理

工具

描述

create_user

创建 MySQL 用户

drop_user

删除 MySQL 用户

grant_privileges

向用户授予权限

revoke_privileges

撤销用户的权限

show_privileges

显示用户权限

服务器信息

工具

描述

server_status

获取 MySQL 服务器状态

MCP 资源

服务器为数据库和表的元数据提供动态资源:

  • database://{name} — 数据库元数据,包括表列表

  • table://{db}/{table} — 表元数据,包括结构、列和索引

使用示例

连接与查询

# First, connect to database
connect(host="localhost", user="root", password="secret", database="mydb")

# Execute a query
execute_query(sql="SELECT * FROM users WHERE active = true")

# List all tables
list_tables(database="mydb")

创建数据库与表

# Create a database
create_database(name="newapp")

# Create a table
create_table(name="users", schema="id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255), email VARCHAR(255) UNIQUE")

用户管理

# Create a new user with password
create_user(username="app_user", host="localhost", password="secure_password")

# Grant privileges
grant_privileges(privileges="SELECT,INSERT,UPDATE,DELETE", on="newapp.*", username="app_user", host="localhost")

事务控制

# Start transaction
execute_query(sql="BEGIN")

# Execute operations
execute_query(sql="INSERT INTO accounts (balance) VALUES (100)")

# Commit or rollback
commit()  # or rollback()

环境变量

服务器支持通过环境变量进行配置:

export MYSQL_HOST=localhost
export MYSQL_PORT=3306
export MYSQL_USER=root
export MYSQL_PASSWORD=secret
export MYSQL_DATABASE=mydb

开发

# Clone repository
git clone https://github.com/daedalus/mcp-mysql-connector.git
cd mcp-mysql-connector

# Create virtual environment
python -m venv venv
source venv/bin/activate

# Install dependencies
pip install -e ".[test]"

# Run tests
pytest

# Format code
ruff format src/ tests/

# Lint
ruff check src/ tests/

# Type check
mypy src/

架构

mcp-mysql-connector/
├── src/mcp_mysql/
│   ├── core/models.py       # Data models (QueryResult, TableSchema, etc.)
│   ├── adapters/mysql.py    # MySQL connection & pooling
│   ├── services/connection.py  # Connection manager
│   ├── tools/mysql_tools.py   # MCP tool implementations
│   └── mcp.py              # FastMCP server setup
└── tests/                   # Test suite

环境要求

  • Python 3.11+

  • fastmcp >= 2.0.0

  • pymysql >= 1.1.0

  • sqlparse >= 0.4.0

许可证

MIT 许可证 — 详情请参阅 LICENSE

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
1Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

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
    61
    33
    MIT
  • A
    license
    A
    quality
    A
    maintenance
    Enables LLMs to interact with MySQL databases through standardized protocol, supporting database management, table operations, data queries, and modifications with configurable permission controls.
    15
    69
    1
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI agents to safely interact with MySQL/MariaDB databases, supporting read-only queries by default with optional write operations and access control.
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI agents to interact with a MySQL database using natural language, automating SQL tasks like querying, inserting, updating, and deleting data.
    1

View all related MCP servers

Related MCP Connectors

  • Gateway between LLM agents and world data through eight tools and a bundled endpoint catalog.

  • Persistent memory and knowledge management for AI agents with semantic search and 50+ tools.

  • MemoryOracle - 10 agent memory tools: vector store, recall, summarization, redaction.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/daedalus/mcp-mysql-connector'

If you have feedback or need assistance with the MCP directory API, please join our Discord server