Sponsored by Deepsite.site

MySQL MCP Server

Created By
actstorms10 months ago
Content

MySQL MCP Server

Version: 0.1.0

A Model Context Protocol (MCP) server for interacting with a MySQL database. This server allows MCP clients (like AI assistants) to query and modify data in a configured MySQL database.

Features

  • Connects to a MySQL database using standard connection parameters.
  • Provides MCP tools for executing SQL queries and statements.
  • Supports read-only queries (SELECT, SHOW, DESCRIBE).
  • Supports write operations (INSERT, UPDATE, DELETE) via separate tools, gated by an environment variable (MYSQL_ALLOW_WRITE_OPS).
  • Communicates over standard input/output (stdio).

Installation

# Install as a project dependency (recommended for use within another project)
npm install

# Or, if intended as a standalone global tool:
# 1. Build the project:
#    npm run build
# 2. Link it globally:
#    npm link 
#    (or use `npm install -g .` if publishing)

Configuration

This server requires the following environment variables to be set for database connection:

  • MYSQL_HOST: The hostname or IP address of your MySQL server.
  • MYSQL_USER: The username for connecting to the database.
  • MYSQL_PASSWORD: The password for the specified user.
  • MYSQL_DATABASE: The name of the database to connect to.
  • MYSQL_PORT: (Optional) The port number for the MySQL server (defaults to 3306).
  • MYSQL_ALLOW_WRITE_OPS: (Optional) Set to true to enable the insert, update, and delete tools. Defaults to false (write operations disabled). Warning: Enabling write operations allows the MCP client to modify your database. Use with caution.

These variables need to be available in the environment where the server process is launched. How you set them depends on your operating system and how you run the server (e.g., .env file, system environment variables, shell export).

Usage

Once configured and built (npm run build), you can run the server:

# If linked globally
mysql-server

# Or run directly using node
node build/index.js 

The server will start and print MySQL MCP server running on stdio to stderr, then listen for MCP requests on standard input/output. You would typically configure your MCP client (e.g., an AI assistant integration) to connect to this server process.

Available Tools

The server exposes the following tools for use by MCP clients:

1. query

  • Description: Executes a read-only SQL query (SELECT, SHOW, DESCRIBE) against the configured database.
  • Input Schema:
    {
      "type": "object",
      "properties": {
        "sql": {
          "type": "string",
          "description": "The read-only SQL query (SELECT, SHOW, DESCRIBE) to execute."
        }
      },
      "required": ["sql"]
    }
    
  • Output: Returns the query results as a JSON string within the MCP response content. Returns an error if the query is not read-only or if there's a database error.

2. insert

  • Description: Executes an INSERT SQL statement. Requires MYSQL_ALLOW_WRITE_OPS to be set to true.
  • Input Schema:
    {
      "type": "object",
      "properties": {
        "sql": {
          "type": "string",
          "description": "The INSERT SQL statement to execute."
        }
      },
      "required": ["sql"]
    }
    
  • Output: Returns a success message including affected rows and insert ID (if applicable), or an error message if the operation fails or write operations are disabled.

3. update

  • Description: Executes an UPDATE SQL statement. Requires MYSQL_ALLOW_WRITE_OPS to be set to true.
  • Input Schema:
    {
      "type": "object",
      "properties": {
        "sql": {
          "type": "string",
          "description": "The UPDATE SQL statement to execute."
        }
      },
      "required": ["sql"]
    }
    
  • Output: Returns a success message including affected rows, or an error message if the operation fails or write operations are disabled.

4. delete

  • Description: Executes a DELETE SQL statement. Requires MYSQL_ALLOW_WRITE_OPS to be set to true.
  • Input Schema:
    {
      "type": "object",
      "properties": {
        "sql": {
          "type": "string",
          "description": "The DELETE SQL statement to execute."
        }
      },
      "required": ["sql"]
    }
    
  • Output: Returns a success message including affected rows, or an error message if the operation fails or write operations are disabled.

Development

To work on the server code:

  1. Clone the repository: (If applicable)
    # git clone <repository-url>
    # cd mysql-server
    
  2. Install dependencies:
    npm install
    
  3. Build the code: (Compiles TypeScript to JavaScript in build/)
    npm run build
    
  4. Watch for changes: (Automatically recompiles on changes)
    npm run watch
    
  5. Run the MCP Inspector: (For testing/debugging the server locally)
    # Make sure you have built the code first
    npm run inspector 
    
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Serper MCP ServerA Serper MCP Server
Tavily Mcp
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
ChatWiseThe second fastest AI chatbot™
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
DeepChatYour AI Partner on Desktop
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Playwright McpPlaywright MCP server
CursorThe AI Code Editor
WindsurfThe new purpose-built IDE to harness magic
Amap Maps高德地图官方 MCP Server
Y GuiA web-based graphical interface for AI chat interactions with support for multiple AI models and MCP (Model Context Protocol) servers.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.