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.
Inputs: tableName (required).
list_tablesB
Retrieves a list of tables in the database.
queryB
Executes a read-only SQL query.
Inputs: sql (required).
test_executeB
Checks if an SQL query can be executed and rolls back afterward.
Inputs: sql (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
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
Work with your database from AI tools: ask, export, approved changes, and scheduled jobs.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Hosted MySQL MCP server for Claude, ChatGPT and Cursor, with each action switched per account.
Text-to-SQL MCP server: read-only queries on PostgreSQL, MySQL and SQL Server with your real schema
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.ISC
- 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.MIT
- AlicenseAqualityDmaintenanceEnables querying local MySQL databases and managing Docker containers (listing, logs) through natural language via the Model Context Protocol.455 npmISC