MySQL MCP Server
MySQL MCP 服务器
这是一个模型上下文协议 (MCP) 服务器,提供对 MySQL 数据库的访问。它允许代理针对 MySQL 数据库执行 SQL 查询。
特征
对 MySQL 数据库执行 SQL 查询:
读取数据(SELECT 语句)
创建表(CREATE TABLE 语句)
插入数据(INSERT INTO 语句)
更新数据(UPDATE 语句)
删除数据(DELETE FROM 语句)
以 JSON 格式返回查询结果
可配置数据库连接设置
使用唯一 ID 进行事务日志记录
Related MCP server: MCP MySQL Server
先决条件
Node.js(v14 或更高版本)
MySQL 服务器
MCP SDK
安装
克隆或下载此存储库
安装依赖项:
cd mysql-mcp-server
npm install构建服务器:
npm run build配置
MySQL MCP 服务器使用以下环境变量进行配置:
MYSQL_HOST:MySQL 服务器主机名(默认值:'localhost')MYSQL_PORT:MySQL 服务器端口(默认值:3306)MYSQL_USER:MySQL 用户名(默认值:'mcp101')MYSQL_PASSWORD:MySQL 密码(默认值:'123qwe')MYSQL_DATABASE:MySQL 数据库名称(默认值:'mcpdb')
数据库设置
创建 MySQL 数据库:
CREATE DATABASE mcpdb;创建具有数据库访问权限的 MySQL 用户:
CREATE USER 'mcp101'@'localhost' IDENTIFIED BY '123qwe';
GRANT ALL PRIVILEGES ON mcpdb.* TO 'mcp101'@'localhost';
FLUSH PRIVILEGES;使用示例数据创建测试表:
USE mcpdb;
CREATE TABLE test_users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO test_users (name, email) VALUES
('John Doe', 'john@example.com'),
('Jane Smith', 'jane@example.com'),
('Bob Johnson', 'bob@example.com');MCP 配置
将 MySQL MCP 服务器添加到您的 MCP 设置文件:
VSCode(Claude扩展)
文件: ~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json
根据您的 MySQL 配置更改参数
{
"mcpServers": {
"mysql-mcp-server": {
"autoApprove": [],
"disabled": false,
"timeout": 60,
"command": "node",
"args": [
"/path/to/mysql-mcp-server/build/index.js"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "mcp101",
"MYSQL_PASSWORD": "123qwe",
"MYSQL_DATABASE": "mcpdb"
},
"transportType": "stdio"
}
}
}克劳德桌面应用程序
文件: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"mysql-mcp-server": {
"autoApprove": [],
"disabled": false,
"timeout": 60,
"command": "node",
"args": [
"/path/to/mysql-mcp-server/build/index.js"
],
"env": {
"MYSQL_HOST": "localhost",
"MYSQL_PORT": "3306",
"MYSQL_USER": "mcp101",
"MYSQL_PASSWORD": "123qwe",
"MYSQL_DATABASE": "mcpdb"
},
"transportType": "stdio"
}
}
}用法
配置完成后,您就可以使用 MySQL MCP 服务器与 Claude 进行对话。例如:
“您能向我显示 test_users 表中的所有用户吗?”
Claude将使用run_sql_query工具执行:
SELECT * FROM test_users可用工具
运行sql查询
对 MySQL 数据库执行只读 SQL 查询(仅限 SELECT 语句)。
参数:
query:要执行的 SQL SELECT 查询。
例子:
{
"query": "SELECT * FROM test_users"
}创建表
在 MySQL 数据库中创建一个新表。
参数:
query:要执行的 SQL CREATE TABLE 查询。
例子:
{
"query": "CREATE TABLE products (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), price DECIMAL(10,2))"
}插入数据
将数据插入 MySQL 数据库的表中。
参数:
query:要执行的 SQL INSERT INTO 查询。
例子:
{
"query": "INSERT INTO products (name, price) VALUES ('Laptop', 999.99), ('Smartphone', 499.99)"
}更新数据
更新 MySQL 数据库中的表中的数据。
参数:
query:要执行的 SQL UPDATE 查询。
例子:
{
"query": "UPDATE products SET price = 899.99 WHERE name = 'Laptop'"
}删除数据
从 MySQL 数据库的表中删除数据。
参数:
query:要执行的 SQL DELETE FROM 查询。
例子:
{
"query": "DELETE FROM products WHERE name = 'Smartphone'"
}安全注意事项
使用具有适当权限的专用 MySQL 用户来管理 MCP 服务器
如果只需要查询数据,请考虑使用只读权限
安全地存储数据库凭证等敏感信息
所有操作均以唯一的事务 ID 记录,以供审计
Available Tools
6 toolscreate_tableC
Creates a new table in the MySQL database.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SQL CREATE TABLE query to execute. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool creates a table, implying a write operation, but doesn't mention critical aspects like whether it requires specific permissions, if it's idempotent, what happens on errors, or any rate limits. This leaves significant gaps in understanding the tool's behavior.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, clear sentence that efficiently conveys the core purpose without unnecessary words. It's front-loaded and wastes no space, making it easy for an agent to parse quickly.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a tool that performs a database write operation with no annotations and no output schema, the description is insufficient. It doesn't address behavioral traits like error handling, permissions, or return values, leaving the agent with incomplete context for safe and effective use.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema description coverage is 100%, with the single parameter 'query' documented as 'The SQL CREATE TABLE query to execute.' The description doesn't add any meaningful semantics beyond this, such as SQL syntax examples or constraints, so it meets the baseline for adequate but not enhanced parameter understanding.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action ('creates') and resource ('new table in the MySQL database'), making the purpose immediately understandable. However, it doesn't distinguish this tool from sibling tools like 'execute_sql' or 'run_sql_query' which might also create tables, missing the opportunity to clarify its specific role in the toolset.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance is provided on when to use this tool versus alternatives like 'execute_sql' or 'run_sql_query', which could potentially handle similar tasks. The description lacks context about prerequisites, such as database permissions or connection requirements, leaving the agent to infer usage scenarios.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
delete_dataC
Deletes data from a table in the MySQL database.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SQL DELETE FROM query to execute. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries full burden for behavioral disclosure. It states the tool performs a deletion, implying a destructive mutation, but fails to mention critical aspects like required permissions, whether deletions are permanent or reversible, transaction handling, error behavior, or rate limits. This leaves significant gaps for a destructive operation.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, efficient sentence that directly states the tool's purpose with zero wasted words. It is appropriately sized and front-loaded, making it easy to parse quickly.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a destructive mutation tool with no annotations and no output schema, the description is insufficiently complete. It lacks details on behavioral traits (e.g., permanence, permissions), output expectations, error handling, and differentiation from siblings, leaving the agent with inadequate context for safe and effective use.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, so the schema already fully documents the single 'query' parameter. The description adds no additional meaning about parameter usage, syntax examples, or constraints beyond what the schema provides, meeting the baseline for high coverage.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action ('Deletes') and target resource ('data from a table in the MySQL database'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like 'execute_sql' or 'run_sql_query' which could also handle DELETE operations, so it misses the highest score for sibling distinction.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives like 'execute_sql' or 'run_sql_query', nor does it mention prerequisites, exclusions, or specific contexts. It merely states what the tool does without indicating appropriate usage scenarios.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
execute_sqlB
Executes any non-SELECT SQL statement (e.g., ALTER TABLE, DROP, etc.)
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SQL statement to execute. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries the full burden. It states the tool executes SQL statements but doesn't disclose behavioral traits like whether it requires specific permissions, if changes are reversible, potential side effects (e.g., data loss from DROP), or error handling. This is a significant gap for a mutation tool with zero annotation coverage.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, efficient sentence with zero waste. It's front-loaded with the core purpose and includes helpful examples (e.g., ALTER TABLE, DROP). Every word earns its place.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the complexity (executes non-SELECT SQL, which can be destructive), lack of annotations, and no output schema, the description is incomplete. It should address behavioral aspects like safety, permissions, or return values to compensate for the missing structured data.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The input schema has 100% description coverage, with the 'query' parameter documented as 'The SQL statement to execute.' The description adds no additional meaning beyond this, as it doesn't specify syntax, format, or constraints. Baseline 3 is appropriate when the schema does the heavy lifting.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the verb ('executes') and resource ('non-SELECT SQL statement') with specific examples (ALTER TABLE, DROP). However, it doesn't explicitly differentiate from siblings like 'run_sql_query' (which likely handles SELECT) or 'create_table'/'delete_data' (which are specific operations).
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage by specifying 'non-SELECT SQL statement', which suggests when to use this tool (for non-SELECT operations) versus alternatives like 'run_sql_query' (for SELECT). However, it doesn't explicitly name alternatives or provide exclusions (e.g., when to use 'create_table' instead).
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
insert_dataC
Inserts data into a table in the MySQL database.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SQL INSERT INTO query to execute. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries full burden for behavioral disclosure. While 'inserts data' implies a write/mutation operation, it doesn't address critical aspects like required permissions, whether the operation is idempotent, transaction handling, error behavior, or what happens on success/failure. For a database mutation tool, this leaves significant gaps in understanding how it behaves.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, efficient sentence with zero wasted words. It's appropriately sized for a simple tool and front-loads the essential information (action + target) immediately.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a database mutation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what happens after insertion (e.g., returns inserted row count, error messages, or confirmation), nor does it address behavioral aspects like transaction safety or permission requirements. The combination of mutation nature and lack of structured metadata demands more descriptive context.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 100%, with the single parameter 'query' fully documented in the schema. The description adds no additional parameter information beyond what the schema provides, such as query format examples or constraints. The baseline of 3 is appropriate when the schema does all the parameter documentation work.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action ('inserts data') and target resource ('into a table in the MySQL database'), providing a specific verb+resource combination. However, it doesn't distinguish this tool from sibling tools like 'execute_sql' or 'run_sql_query' which might also handle INSERT operations, leaving some ambiguity about specialization.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no guidance on when to use this tool versus alternatives like 'execute_sql', 'update_data', or 'create_table'. It doesn't mention prerequisites, exclusions, or specific contexts where this tool is preferred, leaving the agent to guess based on tool names alone.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
run_sql_queryA
Executes a read-only SQL query (SELECT statements only) against the MySQL database.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SQL SELECT query to execute. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
Since no annotations are provided, the description carries the full burden of behavioral disclosure. It effectively describes key behavioral traits: it's read-only (implying no data mutation), limited to SELECT statements (constraining query types), and executes against a MySQL database (specifying the target). However, it lacks details on permissions, rate limits, error handling, or result format, which would be useful for a database tool.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, well-structured sentence that front-loads the key information: action ('Executes'), constraint ('read-only SQL query (SELECT statements only)'), and target ('against the MySQL database'). There is no wasted verbiage, and every word contributes to clarity and utility.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's moderate complexity (executing SQL queries), lack of annotations, and no output schema, the description is reasonably complete. It covers the core purpose, usage constraints, and target database. However, it doesn't address potential behavioral aspects like result format, pagination, timeouts, or authentication needs, which could be important for an AI agent to use it effectively.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema description coverage is 100%, with the single parameter 'query' documented as 'The SQL SELECT query to execute.' The description adds minimal value beyond this by reinforcing the SELECT-only constraint, but doesn't provide additional syntax, format, or validation details. With high schema coverage, the baseline score of 3 is appropriate.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the specific action ('Executes a read-only SQL query') and resource ('against the MySQL database'), with explicit limitation to 'SELECT statements only'. This distinguishes it from siblings like create_table, delete_data, insert_data, and update_data which are write operations, and from execute_sql which might allow broader SQL statements.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description explicitly states 'read-only SQL query (SELECT statements only)', providing clear guidance on when to use this tool (for SELECT queries) versus when not to use it (for write operations like INSERT, UPDATE, DELETE, or DDL). It implicitly suggests alternatives like insert_data for INSERT queries or update_data for UPDATE queries among the sibling tools.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
update_dataC
Updates data in a table in the MySQL database.
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SQL UPDATE query to execute. |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool performs updates but doesn't mention critical aspects like required permissions, whether changes are reversible, transaction handling, error behavior, or rate limits. This is inadequate for a mutation tool with zero annotation coverage.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, efficient sentence with zero wasted words. It's appropriately sized and front-loaded, directly stating the tool's purpose without unnecessary elaboration.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a mutation tool with no annotations, no output schema, and multiple sibling tools, the description is incomplete. It lacks behavioral context, usage differentiation, and details about what happens after execution (e.g., success/failure responses, affected rows). The high schema coverage doesn't compensate for these gaps in a write operation context.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema description coverage is 100%, with the single parameter 'query' documented as 'The SQL UPDATE query to execute'. The description adds no additional parameter details beyond what the schema provides, so it meets the baseline for high schema coverage without compensating value.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action ('Updates') and target ('data in a table in the MySQL database'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'execute_sql' or 'run_sql_query' that might also perform updates, leaving some ambiguity about when to choose this specific tool.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance is provided on when to use this tool versus alternatives like 'execute_sql', 'run_sql_query', or 'delete_data'. The description lacks context about prerequisites, constraints, or explicit recommendations for tool selection among siblings.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
6 tool updates
- First observed
create_table - First observed
delete_data - First observed
execute_sql - First observed
insert_data - First observed
run_sql_query - First observed
update_data
TDQS
Scored across 6 tools
Most tools have distinct purposes with clear boundaries (e.g., create_table vs. insert_data vs. update_data). However, execute_sql and run_sql_query could cause confusion since both execute SQL statements, differentiated only by read-only vs. non-SELECT operations, which might not be immediately obvious to an agent.
All tool names follow a consistent verb_noun pattern (e.g., create_table, delete_data, execute_sql), with no mixing of conventions. This predictability makes it easy for agents to understand and use the tool set.
With 6 tools, this server is well-scoped for basic MySQL database operations. Each tool serves a clear purpose (e.g., table creation, data manipulation, query execution), and the count is appropriate for covering core functionalities without being overwhelming.
The tool set provides good coverage for basic CRUD operations (create, read, update, delete) and table management. However, there are minor gaps, such as missing tools for listing tables or databases, which could limit agents in exploratory tasks, though core workflows are still supported.
Maintenance
Related MCP Connectors
The Mercado Pago MCP Server implements the Model Context Protocol to provide AI agents and LLMs with access to Mercado Pago's APIs and tools within compatible development environments. It acts as an intermediary that translates Mercado Pago resources into executable functions (tools) that AI applications can invoke to perform actions and automate flows. The server simplifies integration, enables using documentation to implement or improve code, and optimizes operations through natural language interactions without manual implementations.
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
- dataOAuthco.thinair
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
Related MCP Servers
- AlicenseBqualityDmaintenanceA 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.5251 npmMIT
- FlicenseBqualityDmaintenanceA 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-
- FlicenseNot gradedqualityDmaintenanceA 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-
- AlicenseBqualityDmaintenanceA server based on Model Context Protocol that enables AI models to interact with MySQL databases through a standardized interface, supporting features like query execution, table listing, and automated connection management.430 npm10MIT