Skip to main content
Glama
CobaltBlue3699

MySQL MCP Server


MySQL MCP Server

A Model Context Protocol (MCP) server for MySQL databases, built with NestJS and MCP-Nest. Enables AI assistants like Claude and Cursor to interact with MySQL databases through a standardized protocol.

English · 繁體中文


Overview

MySQL MCP Server exposes MySQL database operations as MCP tools, allowing AI assistants to:

  • Query and explore database schemas

  • Execute SQL queries with permission controls

  • List tables, describe table structures, and browse databases

  • Run in multiple transport modes (stdio, HTTP SSE, Streamable HTTP)

Related MCP server: MCP MySQL Server

Features

Description

Connection Pool

Efficient MySQL connection management with configurable pool size

Permission Control

Granular SQL operation permissions (SELECT, INSERT, UPDATE, DELETE, DDL)

DRY_RUN Mode

Validate SQL queries without returning actual data

MCP Tools

Standardized database operations exposed via Model Context Protocol

Graceful Shutdown

Clean resource cleanup on process termination

File Logging

Configurable log output with rotation support

Prerequisites

  • Node.js 18+

  • MySQL 5.7+ database

  • npm or pnpm package manager

Installation

# Global installation (recommended)
npm install -g @johnson.lee/mysql-mcp-server

# Or use npx
npx @johnson.lee/mysql-mcp-server

Quick Start

# Set environment variables
export DB_HOST=localhost
export DB_PORT=3306
export DB_USER=root
export DB_PASSWORD=your_password
export DB_NAME=your_database

# Run the server
mysql-mcp

Configuration

Configure via environment variables:

Database Connection

Variable

Default

Description

DB_HOST

localhost

MySQL host

DB_PORT

3306

MySQL port

DB_USER

root

MySQL user

DB_PASSWORD

-

MySQL password

DB_NAME

test_db

Database name

DB_POOL_MIN

2

Min pool connections

DB_POOL_MAX

10

Max pool connections

Permission Control

Variable

Default

Description

ALLOW_SELECT

true

Allow SELECT queries

ALLOW_VIEW

true

Allow SHOW / DESCRIBE

ALLOW_INSERT

false

Allow INSERT

ALLOW_UPDATE

false

Allow UPDATE

ALLOW_DELETE

false

Allow DELETE

ALLOW_DDL

false

Allow CREATE/ALTER/DROP/TRUNCATE

Server Options

Variable

Default

Description

MCP_SERVER_NAME

mysql-mcp-server

Server name — used as log file prefix

MCP_TRANSPORT

stdio

Transport: stdio/http-sse/streamable-http

LOG_LEVEL

info

Log level: debug/info/warn/error

LOG_DIR

./logs

Log directory

DRY_RUN

false

Validate SQL without returning data

Editor Integration

Claude Desktop

Edit ~/.config/claude/claude_desktop_config.json:

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["@johnson.lee/mysql-mcp-server"],
      "env": {
        "DB_HOST": "localhost",
        "DB_USER": "root",
        "DB_PASSWORD": "your_password",
        "DB_NAME": "your_database"
      }
    }
  }
}

Cursor

Create .cursor/mcp.json:

{
  "mcpServers": {
    "mysql": {
      "command": "npx",
      "args": ["@johnson.lee/mysql-mcp-server"],
      "env": {
        "DB_HOST": "localhost",
        "DB_USER": "root",
        "DB_PASSWORD": "your_password",
        "DB_NAME": "your_database"
      }
    }
  }
}

Multi-Environment Setup

You can register multiple instances to connect different databases simultaneously. Each instance should have a unique MCP_SERVER_NAME, which is also used as the log file prefix — e.g. dev-info.log, prod-error.log.

Note: All env values must be strings. Use "true" / "false", not bare booleans.

{
  "mcpServers": {
    "dev-mysql": {
      "command": "npx",
      "args": ["@johnson.lee/mysql-mcp-server"],
      "env": {
        "MCP_SERVER_NAME": "dev",
        "DB_HOST": "dev-db.example.com",
        "DB_PORT": "3306",
        "DB_USER": "dev_user",
        "DB_PASSWORD": "dev_password",
        "DB_NAME": "dev_db",
        "LOG_DIR": "/tmp/mcp-logs"
      }
    },
    "prod-mysql": {
      "command": "npx",
      "args": ["@johnson.lee/mysql-mcp-server"],
      "env": {
        "MCP_SERVER_NAME": "prod",
        "DB_HOST": "prod-db.example.com",
        "DB_PORT": "3306",
        "DB_USER": "prod_user",
        "DB_PASSWORD": "prod_password",
        "DB_NAME": "prod_db",
        "LOG_DIR": "/tmp/mcp-logs",
        "DRY_RUN": "true"
      }
    }
  }
}

With the above config, log files are written to LOG_DIR with the server name as prefix:

/tmp/mcp-logs/
├── dev-info.log
├── dev-error.log
├── prod-info.log
└── prod-error.log

Available Tools

list_tables

List all tables in the current database.

describe_table

Get table structure (columns, types, keys, etc.).

{
  "name": "describe_table",
  "arguments": { "tableName": "users" }
}

execute_query

Execute SQL queries.

{
  "name": "execute_query",
  "arguments": { "sql": "SELECT * FROM users LIMIT 10" }
}

list_databases

List all available databases on the MySQL server.


Built with NestJS and MCP-Nest

Available Tools

4 tools
describe_tableB

Get the structure of a specific table

ParametersJSON Schema
NameRequiredDescriptionDefault
tableNameYesThe name of the table to describe

TDQS

B3.4/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The description indicates a read-only operation ('Get'), but lacks details on error handling (e.g., missing table), authentication needs, or what exactly constitutes 'structure' (columns, types, constraints?). With no annotations, the description carries the full burden, which is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence, no unnecessary words. However, it could be slightly expanded to include what is returned without becoming verbose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simplicity (1 parameter, no output schema), the description is adequate but does not mention what the structure includes or behavior if the table does not exist. A bit more detail would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The only parameter, tableName, is fully described in the input schema (pattern, required, description). The tool description adds no additional meaning, so baseline score of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Get the structure of a specific table' clearly states the action (Get) and the resource (structure of a specific table). It distinguishes from siblings like list_tables and execute_query, which list tables or run queries.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit guidance on when to use this tool instead of alternatives. It is implied that one uses it to retrieve table structure, but there are no when-not instructions or prerequisites mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

execute_queryB

Execute a SELECT query on the database

ParametersJSON Schema
NameRequiredDescriptionDefault
sqlYesThe SQL query to execute
timeoutNoQuery timeout in milliseconds

TDQS

B3.4/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must carry the full burden. It states 'SELECT query' implying read-only, but does not explicitly confirm non-destructiveness, mention permissions, error handling, or query restrictions (e.g., no DDL/DML). This is insufficient for a database tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with no redundant words. It is appropriately sized for a simple tool and front-loads the essential action.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool executes SQL queries, critical missing context includes: whether only SELECT is allowed, return format, timeout behavior, and potential side effects. The description is too minimal for safe and correct invocation, especially without annotations or output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with both parameters described. The tool description adds no extra meaning beyond the schema definitions; it merely restates 'SELECT query'. Baseline score of 3 is appropriate as the schema already provides parameter details.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Execute a SELECT query on the database' clearly identifies the tool's action (execution), resource (database), and operation type (SELECT). It distinguishes from sibling tools that describe or list metadata.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No explicit usage guidelines are provided, but the description implies this tool is for SELECT queries, while siblings handle metadata exploration. The agent must infer when to use this versus describe_table or list_tables.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_databasesA

List all available databases

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must convey behavior. It correctly indicates a read-only listing operation with no side effects, but does not mention output format or any constraints (e.g., user permissions). It is basic but not misleading.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence with no wasted words. It is front-loaded and efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple list tool with no parameters and no output schema, the description is almost complete. It could mention that it returns database names, but the core functionality is clear.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

There are no parameters, and schema description coverage is 100% trivially. Per guidelines, with 0 parameters the baseline is 4. The description does not need to add parameter meaning.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'list' and resource 'databases' with the scope 'all available'. It distinguishes itself from sibling tools (describe_table, execute_query, list_tables) which focus on tables and queries.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when needing to see available databases but provides no explicit guidance on when to use or not use this tool versus alternatives. No exclusions or context are given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_tablesA

List all tables in the current database

ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

TDQS

A3.5/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, and the description only states the basic action. It does not disclose any behavioral traits such as output format, connection requirements, or potential side effects. For a simple read operation, this is minimal but could be improved.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, concise sentence that is front-loaded with the core purpose. Every word earns its place with no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description is adequate for a simple listing operation but lacks details on what information is returned (e.g., table names only). No output schema exists, so more context would be beneficial.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

There are no parameters, and schema coverage is 100%. The description adds no value beyond the schema, so baseline score of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'List all tables in the current database' clearly specifies the verb (list) and resource (tables), and effectively distinguishes from siblings like describe_table (describes a specific table) and list_databases (lists databases).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for listing tables but does not explicitly state when to use this tool versus alternatives like describe_table or execute_query. No exclusions or context are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 4 tool updatesv0.0.2-8
    • First observeddescribe_table
    • First observedexecute_query
    • First observedlist_databases
    • First observedlist_tables

TDQS

A3.7/5.0
Disambiguation5/5

Each tool targets a distinct resource or action: table structure, SELECT query execution, database listing, and table listing. There is no overlap in functionality.

Naming Consistency5/5

All tool names consistently follow the verb_noun pattern (list_databases, list_tables, describe_table, execute_query), making them easy to parse and select.

Tool Count4/5

With 4 tools, the set is minimal but focused. It covers basic database exploration needs, though one might expect additional tools for write operations or schema browsing.

Completeness3/5

The set handles core read operations (listing, describing, querying) but lacks any write capabilities (INSERT, UPDATE, DELETE) and does not support non-SELECT queries, leaving notable gaps for a general MySQL server.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    A server that enables AI models to interact with MySQL databases through a Model Control Protocol, providing tools for table creation, schema inspection, query execution, and data retrieval.
    28
    MIT
  • A
    license
    B
    quality
    D
    maintenance
    A Model Context Protocol server that enables AI models to interact with MySQL databases, providing tools for querying, executing statements, listing tables, and describing table structures.
    5
    342
    MIT
  • F
    license
    B
    quality
    D
    maintenance
    A Model Context Protocol server that enables AI models to interact with MySQL databases through a standardized interface, providing tools for querying, executing commands, and managing database schemas.
    7
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    A Model Context Protocol server that enables AI models to interact with MySQL databases through natural language, supporting SQL queries, table creation, and schema exploration.
    3
    -

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/CobaltBlue3699/mysql-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server