MCP MySQL Server
@enemyrr/mcp-mysql-服务器
提供 MySQL 数据库操作的模型上下文协议服务器。该服务器使 AI 模型能够通过标准化接口与 MySQL 数据库交互。
Cursor IDE 的安装和设置
通过 Smithery 安装
要通过Smithery自动为 Claude Desktop 安装 MySQL 数据库服务器:
npx -y @smithery/cli install @enemyrr/mcp-mysql-server --client claude手动安装
克隆并构建项目:
git clone https://github.com/enemyrr/mcp-mysql-server.git
cd mcp-mysql-server
npm install
npm run build在 Cursor IDE 设置中添加服务器:
打开命令面板(Cmd/Ctrl + Shift + P)
搜索“MCP:添加服务器”
填写字段:
名称:
mysql类型:
command命令:
node /absolute/path/to/mcp-mysql-server/build/index.js
注意:将
/absolute/path/to/替换为您克隆和构建项目的实际路径。
Related MCP server: MCP MySQL Server
数据库配置
您可以通过三种方式配置数据库连接:
.env 中的数据库 URL (推荐):
DATABASE_URL=mysql://user:password@host:3306/database.env 中的各个参数:
DB_HOST=localhost
DB_USER=your_user
DB_PASSWORD=your_password
DB_DATABASE=your_database通过工具直接连接:
use_mcp_tool({
server_name: "mysql",
tool_name: "connect_db",
arguments: {
url: "mysql://user:password@host:3306/database"
// OR
workspace: "/path/to/your/project" // Will use project's .env
// OR
host: "localhost",
user: "your_user",
password: "your_password",
database: "your_database"
}
});可用工具
1. 连接数据库
使用 URL、工作区路径或直接凭据连接到 MySQL 数据库。
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"
});5. describe_table
获取特定表的结构。
use_mcp_tool({
server_name: "mysql",
tool_name: "describe_table",
arguments: {
table: "users"
}
});6. 创建表
创建具有指定字段和索引的新表。
use_mcp_tool({
server_name: "mysql",
tool_name: "create_table",
arguments: {
table: "users",
fields: [
{
name: "id",
type: "int",
autoIncrement: true,
primary: true
},
{
name: "email",
type: "varchar",
length: 255,
nullable: false
}
],
indexes: [
{
name: "email_idx",
columns: ["email"],
unique: true
}
]
}
});7. 添加列
向现有表中添加新列。
use_mcp_tool({
server_name: "mysql",
tool_name: "add_column",
arguments: {
table: "users",
field: {
name: "phone",
type: "varchar",
length: 20,
nullable: true
}
}
});特征
多种连接方式(URL、工作区、直接)
通过自动清理来安全处理连接
查询参数的预处理语句支持
架构管理工具
全面的错误处理和验证
TypeScript 支持
自动工作区检测
安全
使用准备好的语句来防止 SQL 注入
支持通过环境变量进行安全密码处理
执行前验证查询
完成后自动关闭连接
错误处理
服务器提供以下详细的错误消息:
连接失败
无效的查询或参数
缺少配置
数据库错误
架构验证错误
贡献
欢迎贡献!请随时向https://github.com/enemyrr/mcp-mysql-server提交 Pull 请求。
执照
麻省理工学院
Available Tools
7 toolsadd_columnC
Add a new column to existing table
| Name | Required | Description | Default |
|---|---|---|---|
| field | Yes | ||
| table | Yes |
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 of behavioral disclosure. It states this is a mutation ('Add'), implying it modifies database structure, but doesn't cover critical aspects like permissions required, whether changes are reversible, impact on existing data, error handling, or response format. For a tool that alters schema with no annotation coverage, this is a significant gap in transparency.
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 front-loaded with the core action and resource, making it easy to parse quickly. Every word ('Add', 'new column', 'existing table') contributes directly to understanding the tool's function.
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 (2 parameters with nested objects, no output schema, and no annotations), the description is incomplete. It doesn't explain the input structure (e.g., that 'field' is an object with specific properties), behavioral traits (e.g., mutation effects), or output expectations. For a schema-altering tool with rich parameters but no supporting documentation, this leaves too much undefined.
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 0%, meaning none of the parameters (table, field with nested properties like name, type, nullable, length, default) are documented in the schema. The description only mentions 'table' and 'column' generically, without explaining what 'field' represents or detailing the nested properties. It fails to compensate for the schema's lack of documentation, leaving key semantics unclear.
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 ('Add') and resource ('new column to existing table'), making the purpose immediately understandable. It distinguishes this tool from siblings like 'create_table' (which creates entire tables) and 'describe_table' (which inspects structure). However, it doesn't specify what kind of database or system it operates on, which could help further differentiate it from generic column-adding tools.
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. It doesn't mention prerequisites (e.g., needing an existing table from 'create_table' or 'list_tables'), exclusions (e.g., not for modifying columns), or comparisons to siblings like 'execute' (which might handle SQL directly). Without this context, an agent must infer usage from the tool name alone.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
connect_dbC
Connect to MySQL database using URL or config
| Name | Required | Description | Default |
|---|---|---|---|
| database | No | ||
| host | No | ||
| password | No | ||
| url | No | Database URL (mysql://user:pass@host:port/db) | |
| user | No | ||
| workspace | No | Project workspace path |
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 of behavioral disclosure. It states the tool connects to a database, implying it establishes a session or handle, but doesn't describe what happens after connection (e.g., persistence, timeout, error handling), authentication needs beyond parameters, or side effects. For a tool with zero annotation coverage, this is a significant gap in transparency.
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 extremely concise—a single sentence that directly states the tool's purpose and method without any fluff. It's front-loaded and wastes no words, making it easy for an agent to parse quickly. Every part of the sentence earns its place by conveying essential information.
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 complexity (database connection with 6 parameters), lack of annotations, no output schema, and low schema description coverage, the description is incomplete. It doesn't cover behavioral aspects like connection lifecycle, error cases, or output format, leaving critical gaps for the agent to infer. This is inadequate for a tool that likely has significant operational implications.
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 33% (only 'url' and 'workspace' have descriptions), so the description must compensate but adds minimal value. It mentions 'URL or config', hinting at parameters like 'url' and possibly 'host', 'user', etc., but doesn't explain their semantics, relationships (e.g., mutual exclusivity), or defaults. The description provides some context but doesn't fully bridge the coverage gap, warranting a baseline score.
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 ('Connect to MySQL database') and the resource ('MySQL database'), making the purpose evident. It specifies the connection method ('using URL or config'), which helps distinguish it from other database operations. However, it doesn't explicitly differentiate from sibling tools like 'execute' or 'query', which might also involve database interactions, so it's not a perfect 5.
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. It doesn't mention prerequisites (e.g., needing this connection before using other tools like 'query'), exclusions, or contextual cues. With sibling tools like 'execute' and 'query' available, the lack of usage guidelines leaves the agent uncertain about proper sequencing or selection.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
create_tableC
Create a new table in the database
| Name | Required | Description | Default |
|---|---|---|---|
| fields | Yes | ||
| indexes | No | ||
| table | Yes | Table name |
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 'create' implies a write operation but doesn't cover critical aspects like permissions required, whether the operation is idempotent, error handling (e.g., if the table already exists), or side effects. This leaves significant gaps for a mutation 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, direct sentence with zero wasted words, making it highly efficient and front-loaded. It immediately conveys the core purpose without unnecessary elaboration, which is ideal for conciseness.
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 3 parameters, no annotations, and no output schema, the description is insufficient. It lacks details on behavior, error cases, dependencies (e.g., connection state), and doesn't explain what 'create' entails operationally (e.g., atomicity, rollback). This leaves the agent poorly equipped to use the tool effectively in complex scenarios.
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 low at 33%, with only the 'table' parameter having a description. The tool description doesn't add any parameter details beyond the schema, failing to compensate for the coverage gap. However, the schema itself provides clear structure for 'fields' and 'indexes', so a baseline score of 3 is appropriate given the schema's clarity despite missing descriptions.
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 ('create') and resource ('new table in the database'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'add_column' or 'execute', which could also involve table creation operations, so it doesn't reach the highest score.
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' (which might create tables via SQL) or 'add_column' (which modifies existing tables). There's no mention of prerequisites, such as needing an established database connection via 'connect_db', leaving the agent without contextual usage cues.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
describe_tableB
Get table structure
| Name | Required | Description | Default |
|---|---|---|---|
| table | Yes | Table name |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, and the description fails to disclose behavioral traits like read-only nature, side effects, or required permissions. It simply states the function without additional context.
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 extremely concise (two words), front-loaded, and gets straight to the point. However, it could benefit from a bit more detail without sacrificing brevity.
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 is simple with one parameter and no output schema, the description is minimal but adequate for a basic understanding. However, it doesn't specify what 'structure' includes (e.g., columns, types), leaving some ambiguity.
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 coverage is 100% with the only parameter 'table' described as 'Table name'. The description adds no new meaning beyond the schema, so baseline 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 'Get table structure' clearly states the verb (Get) and resource (table structure), and distinguishes the tool from siblings like execute, list_tables, and query, which have different purposes.
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 vs alternatives, such as list_tables or query. It lacks context on when not to use it or any prerequisites.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
executeB
Execute an INSERT, UPDATE, or DELETE query
| Name | Required | Description | Default |
|---|---|---|---|
| params | No | Query parameters (optional) | |
| sql | Yes | SQL query (INSERT, UPDATE, DELETE) |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description must bear the burden of behavioral disclosure. It confirms mutation but fails to detail side effects, permanence, or return 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 short sentence with no wasted words, but it could include more detail without sacrificing conciseness.
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 lack of output schema and annotations, the description does not explain return values or error behavior. It is too minimal for a mutation tool.
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 coverage is 100%, and the description does not add meaning beyond the schema. The schema already documents 'sql' and 'params' adequately.
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 tool executes INSERT, UPDATE, or DELETE queries, which specifies the action and resource. It distinguishes from sibling tools like 'query' which likely handles SELECT 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 implies usage for write operations but does not explicitly guide when to use this tool versus alternatives like 'query'. There is no mention of prerequisites or restrictions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_tablesB
List all tables in the database
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
There are no annotations, so the description must fully disclose behavior. It merely states 'List all tables', which implies a read operation, but omits details on permissions, output format, or performance implications.
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 no unnecessary words. It is appropriately front-loaded but lacks any structural enhancement like bullet points that could aid readability.
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 no output schema or annotations, the description should explain what 'list' returns (e.g., table names, schemas). Without this, an agent may not know how to use the result. Sibling tools like 'describe_table' suggest additional context might be needed.
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 tool has no parameters, so the description cannot add parameter meaning. Baseline for zero parameters is 4, and the description is sufficient for the parameterless case.
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 tool lists all tables in the database. While it distinguishes from 'describe_table' by listing instead of describing, it does not explicitly differentiate from potential siblings like 'query' or 'execute'.
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 its siblings (describe_table, execute, query). It is implied that it retrieves table names, but no context on prerequisites or alternatives.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
queryB
Execute a SELECT query
| Name | Required | Description | Default |
|---|---|---|---|
| params | No | Query parameters (optional) | |
| sql | Yes | SQL SELECT query |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description bears full responsibility for behavioral disclosure. It only states the tool executes a SELECT query, but does not explicitly confirm it is read-only, mention permission requirements, error handling, or the effect of malformed queries. The implied read-only nature is not sufficient.
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 concise sentence that front-loads the main action. It is not verbose, though it could include more context without losing conciseness. The structure is effective but minimal.
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?
There is no output schema, yet the description does not explain what the tool returns (e.g., result set structure, row count, error messages). It also lacks information on pagination, limits, or behavior with large queries, leaving the agent with significant gaps.
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 documents both parameters ('sql' and 'params') adequately. The description adds no additional meaning or context about parameter usage, formatting, or constraints beyond the schema, earning a baseline score of 3.
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 'Execute a SELECT query' clearly identifies the tool's action (execute) and resource (SELECT query). It distinguishes from sibling tools like 'execute' (which likely handles other SQL statements) and 'describe_table'/'list_tables' (which are informational).
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. It does not mention that for non-SELECT queries (e.g., INSERT, UPDATE) one should use the sibling 'execute' tool, nor does it specify any prerequisites or limitations.
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.
7 tool updates
v1.0.0- First observed
add_column - First observed
connect_db - First observed
create_table - First observed
describe_table - First observed
execute - First observed
list_tables - First observed
query
TDQS
Scored across 7 tools
Each tool has a clearly distinct purpose with no ambiguity: connect_db handles connections, list_tables and describe_table provide metadata, create_table and add_column manage schema, while execute and query separate write and read operations. The descriptions make it easy to distinguish between similar tools like execute vs query or create_table vs add_column.
All tools follow a consistent verb_noun pattern with clear, descriptive names (e.g., connect_db, list_tables, create_table). There are no deviations in naming conventions, and the snake_case style is applied uniformly throughout the toolset.
With 7 tools, this server is well-scoped for basic MySQL database operations. Each tool earns its place by covering essential functions: connection management, schema operations, metadata queries, and data manipulation. The count is neither too sparse nor overwhelming for the domain.
The toolset provides solid coverage for core MySQL workflows, including connection, schema management (create, modify), and data operations (read/write). A minor gap exists in lacking explicit tools for updating or deleting tables (e.g., drop_table, alter_table), but agents can work around this using the execute tool for such DDL queries.
Maintenance
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
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 Model Context Protocol server for Wix AI tools
- mcpOAuthcom.gibsonai
GibsonAI MCP server: manage your databases with natural language
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceA 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.28MIT
- 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.5289 npmMIT
- 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-
- AlicenseAqualityDmaintenanceA Model Context Protocol server that allows AI agents to execute SQL queries against a MySQL database, supporting operations like reading data, creating tables, inserting, updating, and deleting records.63,689 npm7MIT