Skip to main content
Glama
MCP MySQL Server

MCP MySQL Server

MCP MySQL Server

This is a Node.js-based MCP (Managed Connector Platform) server for MySQL, exposing functionalities to interact with a MySQL database.

Features

  • query: Executes a SQL query with optional parameters.

  • describe_table: Describes the schema of a specified table.

  • list_tables: Lists all tables in the connected database.

  • update: Performs update operations on a table.

  • insert: Inserts a single record into a table.

  • delete: Deletes records from a table based on a condition (implemented by deleteSingle internally).

Related MCP server: mysql-mcp-server

Setup and Configuration

Prerequisites

  • Node.js (LTS version recommended)

  • npm (Node Package Manager)

  • MySQL Server running and accessible

  • Express.js (included as a dependency)

Installation

  1. Clone the repository (or create the project structure manually):

    git clone <repository-url>
    cd mcp-mysql

    If you are setting this up manually, ensure you have package.json and index.js as provided.

  2. Install dependencies:

    Navigate to the project directory and run:

    npm install

Configuration

  1. Create a .env file:

    In the root directory of the project, create a file named .env.

  2. Add database credentials to .env:

    Populate the .env file with your MySQL database connection details:

    DB_HOST=localhost
    DB_PORT=3306
    DB_USER=root
    DB_PASSWORD=password
    DB_DATABASE=mysql_db

    Note: Replace localhost, 3306, root, password, mysql_db, and your_mysql_port with your actual database host, port, username, password, database name, and desired server port respectively.

MCP JSON Configuration for IDEs (e.g., Cursor AI, VS Code)

To allow IDEs to automatically discover and interact with your MCP MySQL server, you can add the following JSON configuration to your IDE's .cursor/mcp.json file.

{
  "mcpServers": {
    "mcp_mysql_dheer": {
      "command": "node",
      "args": ["index.js"],
      "env": {
        "DB_HOST": "your_db_host",
        "DB_PORT": "your_db_port",
        "DB_USER": "your_db_user",
        "DB_PASSWORD": "your_db_pwd",
        "DB_DATABASE": "your_db"
      }
    }
  }
}

Docker Usage

This MCP server runs as a stdio application. Below are the instructions to build a Docker image and run the server within a container.

  1. Build the Docker Image:

    Navigate to the project directory containing the Dockerfile and package.json, then run:

    docker build -t mcp_mysql_dheer .
  2. Run the Docker Container (as a stdio server):

    When running the Docker container, you'll need to provide the MySQL database credentials as environment variables.

    docker run -i mcp_mysql_dheer node index.js \
      -e DB_HOST=your_mysql_host \
      -e DB_USER=your_mysql_user \
      -e DB_PASSWORD=your_mysql_password \
      -e DB_DATABASE=your_mysql_database \
      -e DB_PORT=your_mysql_port

    Note:

    • -i flag is crucial for STDIN to remain open, allowing the MCP client to communicate with the server.

    • Replace your_mysql_host, your_mysql_user, your_mysql_password, your_mysql_database, and your_mysql_port with your actual database connection details.

Usage (Example with a hypothetical MCP Client)

This server is designed to be consumed by an MCP client. Here's a conceptual example of how an MCP client might interact with these functionalities:

const client = new MCPClient({
  server: {
    command: 'docker',
    args: [
      'run',
      '-i',
      '--rm',
      'mcp_mysql_dheer',
      'node',
      'index.js',
      '-e', 'DB_HOST=your_mysql_host',
      '-e', 'DB_USER=your_mysql_user',
      '-e', 'DB_PASSWORD=your_mysql_password',
      '-e', 'DB_DATABASE=your_mysql_database',
      '-e', 'DB_PORT=your_mysql_port'
    ],
  },
});

async function exampleUsage() {
  // Example: List tables
  const tables = await client.callTool('list_tables', {});
  console.log('Tables:', tables);

  // Example: Query data
  const users = await client.callTool('query', { sql: 'SELECT * FROM users' });
  console.log('Users:', users);
}

exampleUsage();

Available Tools

7 tools
connect_dbB

Connect to the MySQL database. This tool does not require any input parameters.

Inputs: no named parameters.

deleteC

Delete rows from a table based on a condition

Inputs: condition (required), tableName (required).

describe_tableC

Get the structure/schema of a table

Inputs: tableName (required).

insertC

Insert a single row into a table

Inputs: data (required), tableName (required).

list_tablesA

List all tables in the database

Inputs: no named parameters.

queryC

Execute a SQL query on the MySQL database

Inputs: sql (required), params.

updateC

Update rows in a table

Inputs: data (required), condition (required), tableName (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 7 tools

    Disambiguation3/5

    The generic `query` tool can perform the same writes as `insert`, `update`, and `delete`, so boundaries between these four tools are fuzzy and an agent must choose between a raw-SQL path and a structured path. Descriptions do help (insert/update/delete are parameterized conveniences), and `list_tables`/`describe_table` are clearly distinct, but `connect_db` taking no parameters adds further uncertainty about connection state.

    Naming Consistency3/5

    Mixed conventions: `list_tables`, `describe_table`, and `connect_db` use verb_noun, while `query`, `insert`, `update`, and `delete` are bare verbs. It remains readable and each name is intuitive, but there is no single predictable pattern.

    Tool Count5/5

    Seven tools is well-scoped for a MySQL server: read, schema inspection, single-row write, bulk update/delete, and connection setup. Each tool earns its place without redundancy in count.

    Completeness4/5

    Core CRUD plus schema introspection and raw SQL are covered, which lets agents handle DDL, multi-row inserts, and transactions through `query`. Minor gaps: no batch-insert tool, no explicit transaction/commit controls, and no database-level listing (list_databases) or explain/performance tooling.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables MySQL database operations through MCP, including executing SQL queries, listing databases and tables, and describing table structures.
      5
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables natural language interaction with MySQL databases through MCP, supporting SQL execution, schema exploration, and database management via tools, resources, and prompts.
      5
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI agents to query and manage MySQL databases through a structured MCP interface, supporting SQL execution, table inspection, and database operations.
      9
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI models to interact with MySQL databases through MCP protocol, supporting queries, table schema inspection, and data manipulation operations.
      MIT