mysql-mcp-server

MCP.Pizza Chef: dave-wind

mysql-mcp-server is a Model Context Protocol server that provides secure, read-only access to MySQL databases. It allows LLMs to discover database schemas and execute SELECT queries within read-only transactions, ensuring data integrity. The server complies with MCP standards for seamless integration and offers simple configuration for quick deployment. It is ideal for applications requiring safe, real-time database inspection and querying by AI models.

Use This MCP server To

Inspect MySQL database schemas automatically Execute read-only SELECT queries via LLMs Integrate MySQL data access into AI workflows Enable safe database querying without data modification Support AI agents with live database context Validate SQL queries before execution Expose database tables and columns to models Facilitate data analysis from MySQL within AI environments

README

@davewind/mysql-mcp-server

A Model Context Protocol server that provides read-only access to Mysql databases. This server enables LLMs to inspect database schemas and execute read-only queries.

Key Features

1.Read-Only Database Access: Enforces read-only operations through SQL validation and READ ONLY transactions
2.Schema Discovery: Automatically identifies and exposes database table structures
3.SQL Query Execution: Provides a query tool that accepts and executes SELECT statements
4.Model Context Protocol Compliance: Implements the MCP specification for seamless integration with compatible LLMs
5.Simple Configuration: Easy setup with minimal configuration required

Tools

  • query
    • Execute read-only SQL queries against the connected database
    • Input: sql (string): The SQL query to execute
    • All queries are executed within a READ ONLY transaction

Resources

The server provides schema information for each table in the database:

  • Table Schemas (mysql://user:password@localhost:3306/database)
    • JSON schema information for each table
    • Includes column names and data types
    • Automatically discovered from database metadata

Install

npm install @davewind/mysql-mcp-server -g

Configuration

MCP settings configuration file:

recommended use

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["-y", "@davewind/mysql-mcp-server", "mysql://user:password@localhost:port/database"],
    }
  }
}

Test

Replace mysql://user:password@localhost:port/ and npm run inspector

  "scripts": {
    "inspector": "npx @modelcontextprotocol/inspector@0.10.2 build/index.js mysql://user:password@localhost:port/database
  }

Env

node v18 +

System Architecture

The MySQL MCP Server acts as an intermediary between LLMs and MySQL databases, processing requests according to the Model Context Protocol.

Component Interaction

Component Interaction

Security Model

The MySQL MCP Server implements a strict security model to ensure that database access is read-only.

Security measures include:

1.SQL query validation to allow only SELECT statements 2.Execution of all queries within READ ONLY transactions 3.No support for data modification operations (INSERT, UPDATE, DELETE, etc.) 4. No support for database schema modification (CREATE, ALTER, DROP, etc.)

Integration with LLMs

The MySQL MCP Server is designed to work with any LLM system that supports the Model Context Protocol. It communicates through JSON-RPC over stdio, following the MCP specification.

License

MIT

mysql-mcp-server FAQ

How does mysql-mcp-server ensure queries are read-only?
It enforces read-only operations by validating SQL statements and running all queries within READ ONLY transactions to prevent data modification.
Can mysql-mcp-server automatically discover database schemas?
Yes, it automatically identifies and exposes the structure of tables and columns in the connected MySQL database.
What types of SQL queries can I run with this server?
Only SELECT statements are supported to maintain read-only access and data safety.
How do I configure mysql-mcp-server for my database?
Configuration is simple, requiring minimal setup such as database connection details and credentials.
Is mysql-mcp-server compatible with multiple LLM providers?
Yes, it follows the MCP specification, enabling integration with providers like OpenAI, Claude, and Gemini.
Does mysql-mcp-server support write operations?
No, it strictly enforces read-only access to protect database integrity.
How does this server integrate with AI models?
It exposes database schemas and query tools via MCP, allowing LLMs to fetch real-time data context safely.
What security measures are in place?
Read-only transactions and SQL validation prevent unauthorized data changes and ensure safe querying.