MCP MySQL Server

MCP MySQL Server

Enables interaction with MySQL databases through MCP, supporting query execution, table operations (insert, update, delete), and schema inspection for natural language database management.

Category
Visit Server

README

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).

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();

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured