MySQL MCP Server
MySQL MCP 서버
MySQL 데이터베이스와 상호작용하기 위한 MCP 서버.
이 서버는 읽기 전용 쿼리(query) 실행과 최종적으로 롤백되는 쓰기 쿼리(test_execute) 실행을 지원합니다.
설정
환경 변수
~/.mcp/.env 에 다음 환경 변수를 추가합니다.
지엑스피1
참고 :
host.docker.internal은 Docker 컨테이너에서 호스트 머신 서비스에 액세스하기 위한 특수 DNS 이름입니다. 호스트 머신에서 실행 중인 MySQL 서버에 연결할 때 이 설정을 사용하세요. 다른 MySQL 서버에 연결하는 경우 적절한 호스트 이름으로 변경하세요.
mcp.json 구성
{
"mcpServers": {
"mysql": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"--add-host=host.docker.internal:host-gateway",
"--env-file",
"/Users/username/.mcp/.env",
"ghcr.io/xiangma9712/mcp/mysql"
]
}
}
}Related MCP server: MCP MySQL Server
용법
서버 시작
docker run -i --rm --add-host=host.docker.internal:host-gateway --env-file ~/.mcp/.env ghcr.io/xiangma9712/mcp/mysql참고 : OrbStack을 사용하는 경우
host.docker.internal자동으로 지원되므로--add-host옵션을 생략할 수 있습니다. Docker Desktop도 일반적으로 이 옵션을 자동으로 지원하지만, 안정성 향상을 위해--add-host옵션을 추가하는 것이 좋습니다.
사용 가능한 명령
1. 읽기 전용 쿼리 실행
{
"type": "query",
"payload": {
"sql": "SELECT * FROM your_table"
}
}응답:
{
"success": true,
"data": [
{
"id": 1,
"name": "example"
}
]
}2. 테스트 쿼리 실행
{
"type": "test_execute",
"payload": {
"sql": "UPDATE your_table SET name = 'updated' WHERE id = 1"
}
}응답:
{
"success": true,
"data": "The UPDATE SQL query can be executed."
}3. 테이블 나열
{
"type": "list_tables"
}응답:
{
"success": true,
"data": ["table1", "table2", "table3"]
}4. 테이블 설명
{
"type": "describe_table",
"payload": {
"table": "your_table"
}
}응답:
{
"success": true,
"data": [
{
"Field": "id",
"Type": "int(11)",
"Null": "NO",
"Key": "PRI",
"Default": null,
"Extra": ""
},
{
"Field": "name",
"Type": "varchar(255)",
"Null": "YES",
"Key": "",
"Default": null,
"Extra": ""
}
]
}구현 세부 사항
TypeScript로 구현됨
mysql2 패키지를 사용합니다
Docker 컨테이너로 실행됩니다
표준 입력을 통해 JSON 명령을 수락합니다.
표준 출력을 통해 JSON 응답을 반환합니다.
host.docker.internal사용하여 호스트 MySQL에 연결합니다(OrbStack 및 Docker Desktop과 호환).
보안 고려 사항
민감한 정보 관리를 위해 환경 변수를 사용합니다.
SQL 주입 방지는 구현자의 책임입니다.
프로덕션 사용에 적합한 네트워크 구성이 필요합니다.
호스트 머신 서비스에 연결할 때 적절한 방화벽 설정이 필요합니다.
Available Tools
4 toolsdescribe_tableC
Retrieves column information for a table.
| Name | Required | Description | Default |
|---|---|---|---|
| tableName | Yes |
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 retrieves information, implying a read-only operation, but doesn't specify permissions required, rate limits, error handling, or the format of returned column information, leaving significant gaps for a tool with no structured safety hints.
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 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?
Given no annotations, no output schema, and low schema coverage, the description is incomplete. It lacks details on behavioral traits, parameter constraints, and return values, which are critical for a tool that retrieves structured data. This leaves the agent with insufficient context for reliable invocation.
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 description mentions 'tableName' implicitly by referring to 'a table', but with 0% schema description coverage and one parameter, it adds minimal semantic value beyond what the schema's property name suggests. Since schema coverage is low, the description doesn't compensate with details like valid table name formats or examples, meeting the baseline for a single parameter.
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 ('Retrieves') and resource ('column information for a table'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from siblings like 'list_tables' (which likely lists table names) or 'query' (which might execute SQL queries), missing full 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 'list_tables' or 'query'. It lacks context about prerequisites, such as needing an existing table name, or exclusions, leaving the agent to infer usage from the purpose alone.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
list_tablesB
Retrieves a list of tables in the database.
| Name | Required | Description | Default |
|---|---|---|---|
No parameters | |||
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 it 'retrieves' data (implying read-only), but doesn't mention any constraints like permissions needed, rate limits, pagination, or what format the list returns. This leaves significant behavioral gaps for a 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, clear sentence with no wasted words. It's front-loaded with the core purpose and efficiently communicates the essential function without redundancy or fluff.
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 simple list-retrieval tool with no parameters and no output schema, the description is minimally adequate. However, without annotations or output details, it lacks completeness regarding behavioral aspects like return format or constraints. It meets basic needs but has clear gaps in 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 tool has 0 parameters, and schema description coverage is 100% (though trivial since there's no schema). The description doesn't need to explain parameters, so it appropriately avoids unnecessary detail. A baseline of 4 is justified as it doesn't mislead about parameters that don't exist.
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 ('Retrieves') and resource ('list of tables in the database'), making the tool's purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'describe_table' or 'query', which prevents a perfect 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?
No guidance is provided on when to use this tool versus alternatives like 'describe_table' (for table details) or 'query' (for data retrieval). The description only states what it does, not when it's appropriate, leaving the agent to infer usage context.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
queryB
Executes a read-only SQL query.
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations provided, the description carries the full burden. It discloses 'read-only', indicating non-destructive behavior, which is useful. However, it lacks details on permissions, rate limits, error handling, or response format, leaving significant behavioral gaps for a tool that executes SQL queries.
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 appropriately sized and front-loaded, clearly stating the core action without unnecessary elaboration, 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?
Given the complexity of executing SQL queries, no annotations, no output schema, and low schema coverage, the description is incomplete. It lacks information on return values, error cases, or operational context, making it inadequate for safe and effective tool invocation.
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%, so the schema provides no parameter details. The description adds minimal semantics by implying the 'sql' parameter is for SQL queries, but it doesn't explain syntax, supported SQL dialects, or constraints, failing to compensate for the low 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 verb ('executes') and resource ('SQL query'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'test_execute' or 'describe_table', which might also involve query execution or database operations, so it's not fully specific to sibling context.
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 'test_execute' or 'list_tables'. It mentions 'read-only', which hints at usage context, but lacks explicit when/when-not instructions or named alternatives, leaving the agent with minimal direction.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
test_executeB
Checks if an SQL query can be executed and rolls back afterward.
| Name | Required | Description | Default |
|---|---|---|---|
| sql | 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. It discloses key behavioral traits: the tool checks executability and performs a rollback, indicating it's a safe, non-destructive operation. However, it doesn't mention error handling, performance implications, or what 'checks' entails (e.g., syntax validation, permission checks), leaving gaps for a mutation-related 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, efficient sentence: 'Checks if an SQL query can be executed and rolls back afterward.' It's front-loaded with the core purpose, has zero waste, and appropriately sized for the tool's complexity.
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 involves SQL execution testing (a mutation-related operation), no annotations, no output schema, and low parameter coverage, the description is incomplete. It lacks details on return values (e.g., success/failure indicators), error responses, or rollback specifics, making it inadequate for safe agent 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 0%, so the description must compensate. It mentions 'SQL query' as the input, which adds meaning to the 'sql' parameter by specifying it's an SQL query string. However, it doesn't provide details on query format, supported SQL dialects, or constraints, failing to fully compensate for the low 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 tool's purpose: 'Checks if an SQL query can be executed and rolls back afterward.' This specifies the verb ('checks') and resource ('SQL query'), and distinguishes it from siblings like 'query' (which likely executes queries) and 'describe_table'/'list_tables' (which are read-only metadata tools). However, it doesn't explicitly differentiate from 'query' beyond implying a test vs. execution distinction, keeping it at 4 rather than 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 implies usage context: it's for testing SQL queries before actual execution, suggesting when to use it (to validate queries) versus alternatives like 'query' (for actual execution). However, it doesn't explicitly state when-not-to-use or name alternatives, and lacks prerequisites (e.g., database connection requirements), so it's not fully explicit.
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.
4 tool updates
v1.0.0- Added
describe_table - Added
list_tables - Added
query - Added
test_execute
TDQS
Scored across 4 tools
Each tool has a clearly distinct purpose: describe_table for column metadata, list_tables for table enumeration, query for read-only SQL execution, and test_execute for query validation with rollback. There is no overlap in functionality, making tool selection straightforward for an agent.
The naming follows a consistent verb_noun pattern (describe_table, list_tables, query, test_execute), with 'query' as a minor deviation as it lacks a noun suffix. Overall, the pattern is predictable and readable, though not perfectly uniform.
With 4 tools, the count is reasonable for a database server, covering essential operations like listing tables, describing schema, querying, and testing queries. It is slightly lean but well-scoped, lacking only advanced features like write operations or transaction management.
The toolset covers basic read and validation operations but has notable gaps: there are no tools for data manipulation (e.g., insert, update, delete), schema modification (e.g., create_table), or transaction control. This limits the server to read-only and diagnostic tasks, which may cause agent failures for write workflows.
Maintenance
Related MCP Connectors
- dataOAuthco.thinair
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
PostgreSQL, MySQL, OpenAPI/Swagger, and shared Agent Memory with scoped access.
Connect to PlanetScale databases, branches, schema, query insights, and execute SQL
Generate, fix, explain and run read-only SQL on PostgreSQL, MySQL and SQL Server
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.-
- AlicenseNot gradedqualityDmaintenanceEnables interaction with MySQL databases through MCP, supporting query execution, table operations (insert, update, delete), and schema inspection for natural language database management.185 npmMIT
- AlicenseNot gradedqualityDmaintenanceEnables AI models to interact with MySQL databases through standardized operations including querying, executing commands, listing tables, and describing table structures with secure prepared statement support.289 npmMIT
- FlicenseAqualityDmaintenanceEnables querying local MySQL databases and managing Docker containers (listing, logs) through natural language via the Model Context Protocol.459 npm-