MySQL MCP Server
The MySQL MCP Server allows interaction with MySQL databases via JSON commands in a Docker container. You can:
Execute read-only SQL queries (
query)Test SQL write queries with automatic rollback (
test_execute)List all tables in the database (
list_tables)Describe the structure of a specific table (
describe_table)
Runs as a containerized service with special configurations for host connectivity, allowing MySQL database access from Docker environments with proper networking setup.
Uses environment variables stored in .env files for configuration management, particularly for sensitive database connection credentials.
Enables interaction with MySQL databases through read-only queries, schema exploration, and safe testing of write operations (with rollback). Provides tools for executing queries, listing tables, and describing table structures.
Implemented in TypeScript, providing type-safe database interactions with MySQL.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MySQL MCP Serverlist all tables in the database"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MySQL MCP Server
An MCP server for interacting with MySQL databases.
This server supports executing read-only queries (query) and write queries that are ultimately rolled back (test_execute).
Setup
Environment Variables
Add the following environment variables to ~/.mcp/.env:
MYSQL_HOST=host.docker.internal # Hostname to access host services from Docker container
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your_passwordNote:
host.docker.internalis a special DNS name for accessing host machine services from Docker containers. Use this setting when connecting to a MySQL server running on your host machine. If connecting to a different MySQL server, change to the appropriate hostname.
mcp.json Configuration
{
"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
Usage
Starting the Server
docker run -i --rm --add-host=host.docker.internal:host-gateway --env-file ~/.mcp/.env ghcr.io/xiangma9712/mcp/mysqlNote: If you're using OrbStack,
host.docker.internalis automatically supported, so the--add-hostoption can be omitted. While Docker Desktop also typically supports this automatically, adding the--add-hostoption is recommended for better reliability.
Available Commands
1. Execute Read-only Query
{
"type": "query",
"payload": {
"sql": "SELECT * FROM your_table"
}
}Response:
{
"success": true,
"data": [
{
"id": 1,
"name": "example"
}
]
}2. Test Query Execution
{
"type": "test_execute",
"payload": {
"sql": "UPDATE your_table SET name = 'updated' WHERE id = 1"
}
}Response:
{
"success": true,
"data": "The UPDATE SQL query can be executed."
}3. List Tables
{
"type": "list_tables"
}Response:
{
"success": true,
"data": ["table1", "table2", "table3"]
}4. Describe Table
{
"type": "describe_table",
"payload": {
"table": "your_table"
}
}Response:
{
"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": ""
}
]
}Implementation Details
Implemented in TypeScript
Uses mysql2 package
Runs as a Docker container
Accepts JSON commands through standard input
Returns JSON responses through standard output
Uses
host.docker.internalto connect to host MySQL (compatible with both OrbStack and Docker Desktop)
Security Considerations
Uses environment variables for sensitive information management
SQL injection prevention is the implementer's responsibility
Proper network configuration required for production use
Appropriate firewall settings needed when connecting to host machine services
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.
TDQS
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
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
PostgreSQL, MySQL, OpenAPI/Swagger, and shared Agent Memory with scoped access.
Connect to PlanetScale databases, branches, schema, query insights, and execute SQL
- mcpOAuthcom.gibsonai
GibsonAI MCP server: manage your databases with natural language
Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…
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.121MIT
- 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.342MIT
- FlicenseAqualityCmaintenanceEnables querying local MySQL databases and managing Docker containers (listing, logs) through natural language via the Model Context Protocol.488
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/xiangma9712/mysql-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server