michael7736 mysql mcp server

michael7736 mysql mcp server avatar

by michael7736

MySQL MCP server project

What is michael7736 mysql mcp server

MySQL MCP Server

This is a Model Context Protocol (MCP) server that provides access to a MySQL database. It allows agent to execute SQL queries against a MySQL database.

Features

  • Execute SQL queries against a MySQL database:
    • Read data (SELECT statements)
    • Create tables (CREATE TABLE statements)
    • Insert data (INSERT INTO statements)
    • Update data (UPDATE statements)
    • Delete data (DELETE FROM statements)
  • Returns query results in JSON format
  • Configurable database connection settings
  • Transaction logging with unique IDs

Prerequisites

  • Node.js (v14 or higher)
  • MySQL server
  • MCP SDK

Installation

  1. Clone or download this repository
  2. Install dependencies:
cd mysql-mcp-server
npm install
  1. Build the server:
npm run build

Configuration

The MySQL MCP server uses the following environment variables for configuration:

  • MYSQL_HOST: MySQL server hostname (default: 'localhost')
  • MYSQL_PORT: MySQL server port (default: 3306)
  • MYSQL_USER: MySQL username (default: 'mcp101')
  • MYSQL_PASSWORD: MySQL password (default: '123qwe')
  • MYSQL_DATABASE: MySQL database name (default: 'mcpdb')

Database Setup

  1. Create a MySQL database:
CREATE DATABASE mcpdb;
  1. Create a MySQL user with access to the database:
CREATE USER 'mcp101'@'localhost' IDENTIFIED BY '123qwe';
GRANT ALL PRIVILEGES ON mcpdb.* TO 'mcp101'@'localhost';
FLUSH PRIVILEGES;
  1. Create a test table with sample data:
USE mcpdb;
CREATE TABLE test_users (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100),
  email VARCHAR(100),
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

INSERT INTO test_users (name, email) VALUES
  ('John Doe', '[email protected]'),
  ('Jane Smith', '[email protected]'),
  ('Bob Johnson', '[email protected]');

MCP Configuration

Add the MySQL MCP server to your MCP settings file:

VSCode (Claude Extension)

File: ~/Library/Application Support/claude-code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json

Change the args according your MySQL configuruation

{
  "mcpServers": {
    "mysql-mcp-server": {
      "autoApprove": [],
      "disabled": false,
      "timeout": 60,
      "command": "node",
      "args": [
        "/path/to/mysql-mcp-server/build/index.js"
      ],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "mcp101",
        "MYSQL_PASSWORD": "123qwe",
        "MYSQL_DATABASE": "mcpdb"
      },
      "transportType": "stdio"
    }
  }
}

Claude Desktop App

File: ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "mysql-mcp-server": {
      "autoApprove": [],
      "disabled": false,
      "timeout": 60,
      "command": "node",
      "args": [
        "/path/to/mysql-mcp-server/build/index.js"
      ],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "mcp101",
        "MYSQL_PASSWORD": "123qwe",
        "MYSQL_DATABASE": "mcpdb"
      },
      "transportType": "stdio"
    }
  }
}

Usage

Once configured, you can use the MySQL MCP server in your conversations with Claude. For example:

"Can you show me all the users in the test_users table?"

Claude will use the run_sql_query tool to execute:

SELECT * FROM test_users

Available Tools

run_sql_query

Executes a read-only SQL query (SELECT statements only) against the MySQL database.

Parameters:

  • query: The SQL SELECT query to execute.

Example:

{
  "query": "SELECT * FROM test_users"
}

create_table

Creates a new table in the MySQL database.

Parameters:

  • query: The SQL CREATE TABLE query to execute.

Example:

{
  "query": "CREATE TABLE products (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), price DECIMAL(10,2))"
}

insert_data

Inserts data into a table in the MySQL database.

Parameters:

  • query: The SQL INSERT INTO query to execute.

Example:

{
  "query": "INSERT INTO products (name, price) VALUES ('Laptop', 999.99), ('Smartphone', 499.99)"
}

update_data

Updates data in a table in the MySQL database.

Parameters:

  • query: The SQL UPDATE query to execute.

Example:

{
  "query": "UPDATE products SET price = 899.99 WHERE name = 'Laptop'"
}

delete_data

Deletes data from a table in the MySQL database.

Parameters:

  • query: The SQL DELETE FROM query to execute.

Example:

{
  "query": "DELETE FROM products WHERE name = 'Smartphone'"
}

Security Considerations

  • Use a dedicated MySQL user with appropriate privileges for the MCP server
  • Consider using read-only privileges if you only need to query data
  • Store sensitive information like database credentials securely
  • All operations are logged with unique transaction IDs for auditing

Leave a Comment

Frequently Asked Questions

What is MCP?

MCP (Model Context Protocol) is an open protocol that standardizes how applications provide context to LLMs. Think of MCP like a USB-C port for AI applications, providing a standardized way to connect AI models to different data sources and tools.

What are MCP Servers?

MCP Servers are lightweight programs that expose specific capabilities through the standardized Model Context Protocol. They act as bridges between LLMs like Claude and various data sources or services, allowing secure access to files, databases, APIs, and other resources.

How do MCP Servers work?

MCP Servers follow a client-server architecture where a host application (like Claude Desktop) connects to multiple servers. Each server provides specific functionality through standardized endpoints and protocols, enabling Claude to access data and perform actions through the standardized protocol.

Are MCP Servers secure?

Yes, MCP Servers are designed with security in mind. They run locally with explicit configuration and permissions, require user approval for actions, and include built-in security features to prevent unauthorized access and ensure data privacy.

Related MCP Servers

chrisdoc hevy mcp avatar

chrisdoc hevy mcp

mcp
sylphlab pdf reader mcp avatar

sylphlab pdf reader mcp

An MCP server built with Node.js/TypeScript that allows AI agents to securely read PDF files (local or URL) and extract text, metadata, or page counts. Uses pdf-parse.

pdf-parsetypescriptnodejs
aashari mcp server atlassian bitbucket avatar

aashari mcp server atlassian bitbucket

Node.js/TypeScript MCP server for Atlassian Bitbucket. Enables AI systems (LLMs) to interact with workspaces, repositories, and pull requests via tools (list, get, comment, search). Connects AI directly to version control workflows through the standard MCP interface.

atlassianrepositorymcp
aashari mcp server atlassian confluence avatar

aashari mcp server atlassian confluence

Node.js/TypeScript MCP server for Atlassian Confluence. Provides tools enabling AI systems (LLMs) to list/get spaces & pages (content formatted as Markdown) and search via CQL. Connects AI seamlessly to Confluence knowledge bases using the standard MCP interface.

atlassianmcpconfluence
prisma prisma avatar

prisma prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB

cockroachdbgomcp
Zzzccs123 mcp sentry avatar

Zzzccs123 mcp sentry

mcp sentry for typescript sdk

mcptypescript
zhuzhoulin dify mcp server avatar

zhuzhoulin dify mcp server

mcp
zhongmingyuan mcp my mac avatar

zhongmingyuan mcp my mac

mcp
zhixiaoqiang desktop image manager mcp avatar

zhixiaoqiang desktop image manager mcp

MCP 服务器,用于管理桌面图片、查看详情、压缩、移动等(完全让Trae实现)

mcp
zhixiaoqiang antd components mcp avatar

zhixiaoqiang antd components mcp

An MCP service for Ant Design components query | 一个减少 Ant Design 组件代码生成幻觉的 MCP 服务,包含系统提示词、组件文档、API 文档、代码示例和更新日志查询

designantdapi

Submit Your MCP Server

Share your MCP server with the community

Submit Now