SuperAPI AI Directory

mysql_mcp_server

MySQL MCP Server is a server implementation based on the Model Context Protocol (MCP), used to enable secure, structured interaction between AI applications (hosts/clients) and MySQL databases. It provides database exploration and analysis capabilities through a controlled interface, supporting two transport modes: STDIO and Streamable HTTP (SSE), with SSE mode recommended for remote or self-hosted deployments. Main capabilities include: listing available MySQL tables as resources, reading table contents, executing SQL queries with error handling, optional multi-database mode, SSH tunnel support, complete schema information, table data sampling, secure database access via environment variables, and comprehensive logging. The server is designed to be integrated into AI applications such as Claude Desktop and Visual Studio Code, and should not be run directly as a standalone Python program.

Open website

About this tool

Purpose

MySQL MCP Server is a Model Context Protocol (MCP) implementation used to enable secure, structured interaction between AI applications (hosts/clients) and MySQL databases. This server component makes database exploration and analysis safer and more organized through a controlled interface.

Main Capabilities

  • List available MySQL tables as resources
  • Read table contents
  • Execute SQL queries with proper error handling
  • Multi-database mode (optional MYSQL_DATABASE)
  • SSE/HTTP transport support (MCP_TRANSPORT=sse)
  • SSH tunnel support
  • Comprehensive schema information
  • Table data sampling
  • Secure database access via environment variables
  • Comprehensive logging

Deployment Options

  • Hosted — Fronteir AI runs the server for you; no local setup required.
  • Local — Smithery installs and runs the server on your own machine.

Installation Methods

Install via Smithery

MySQL MCP Server can be automatically installed for Claude Desktop via Smithery.

Install via Claude Code CLI

Install via Autohand Code CLI

Adding --scope project after mcp add keeps the registration in the current workspace. For current CLI details, see Autohand Code.

Manual Installation

The following environment variables need to be set.

.env File Loading

At startup, the server automatically loads the .env file via python-dotenv, so configuration can be simplified for local use. This file is read from the process working directory (and parent directories), which works when you run the server yourself from the project folder.

⚠️ Claude Code / Claude Desktop: These hosts start the server from their own working directory, so the project's .env will not be found, and you will see Missing required database configuration. Please put the MYSQL_* values into the env block of the MCP configuration (see the Usage section below), rather than relying on .env.

Multi-database MoFormat

When MYSQL_DATABASE is not set, the server runs in multi-database mode:

  • list_resources returns all user databases (system databases are filtered out)
  • Use fully qualified table names in SQL queries, such as mydb.mytable

Note: Only a single SQL statement is supported. Multi-statement queries are not supported (for example, USE db; SELECT ...).

Available Tools

execute_sql

Executes any standard SQL query.

  • Parameter: query (string)
  • Features: Supports SELECT, SHOW, DESCRIBE, and DML (INSERT, UPDATE, DELETE). DML operations are flagged as destructive hints.
  • Limitation: Only a single statement is supported. Multi-statement queries are not supported.
  • Cross-database: Use the database.table notation to query any database, regardless of the MYSQL_DATABASE setting.

get_schema_info

Provides detailed metadata about the database structure.

  • Parameter: table_name (optional string)
  • Output: Column names, types, nullability, default values, and comments.
  • Cross-database: Pass database.table to query tables outside MYSQL_DATABASE; a bare name uses the configured database.
  • Identifier rules: Names may contain only alphanumeric characters, underscores, and $ (the dot is allowed as a separator between the database and table names).

get_table_sample

Retrieves a representative data sample.

  • Parameters: table_name (string), limit (optional integer, maximum 20)
  • Use case: Quickly understand the data format and content without retrieving a large result set.
  • Cross-database: Pass database.table to sample tables outside MYSQL_DATABASE; a bare name uses the configured database.

Available Prompts

In addition to tools, the server also exposes MCP prompts—guided multi-step workflows that clients can launch on demand. In Claude Code they appear as slash commands (/mcp__<server>__<prompt>); in Claude Desktop they appear in the prompts (+) menu.

Both prompts orchestrate the existing get_schema_info and get_table_sample tools; explore_database also uses the resource list to enumerate tables.

Usage

With Claude Desktop

Add the configuration to claude_desktop_config.json.

With Visual Studio Code

Add the configuration to mcp.json. Note: uv must be installed for it to work.

Debugging with MCP Inspector

Although MySQL MCP Server is not intended to run standalone or directly from the command line with Python, you can debug it using MCP Inspector. MCP Inspector provides a convenient way to test and debug your MCP implementation.

MySQL MCP Server is designed to integrate with AI applications such as Claude Desktop and should not be run directly as a standalone Python program.

Security Considerations

  • Identifier validation: Table names and database names passed to get_schema_info and get_table_sample are validated against a strict whitelist (alphanumeric, underscore, and $ only; a single dot is allowed as a database.table separator). Other special characters are rejected to prevent SQL injection.
  • Encrypted access: Full support for SSL/TLS and SSH tunneling for secure remote connections.
  • Log privacy: Passwords and SSH private keys are automatically masked in server logs.
  • Least privilege: Always use a dedicated MySQL user with the minimum required privileges.
  • The SSE transport has no built-in authentication. The SSE server binds to 0.0.0.0 by default and accepts connections without credentials. If you expose it beyond localhost, place it behind a reverse proxy that enforces authentication (nginx, Caddy, Traefik).

Security Best Practices

This MCP implementation requires database access to run. For security:

  • Create a dedicated MySQL user with minimum privileges
  • Never use root credentials or administrative accounts
  • Restrict database access to only the necessary operations
  • Enable logging for auditing
  • Regularly conduct security reviews of database access

⚠️ Important: When configuring database access, always followthe principle of least privilege.

Applicable Scenarios

Suitable for scenarios where AI applications need to securely explore, query, and analyze MySQL databases, such as viewing database structures, sampling data, and controlled SQL execution through MCP clients like Claude Desktop or Visual Studio Code.

Limitations

  • Only a single SQL statement is supported; multi-statement queries are not supported.
  • The SSE transport has no built-in authentication; exposing it beyond localhost requires configuring reverse proxy authentication yourself.
  • It should not be run directly as a standalone Python program.
  • In Claude Code / Claude Desktop, the project .env cannot be found automatically; MYSQL_* values must be provided in the env block of the MCP configuration.

License

MIT License - see the LICENSE file for details.