Registry / database / mcp-mysql-server

mcp-mysql-server

JSON →
library1.0.2jsnpmunverified

The @enemyrr/mcp-mysql-server package provides a Model Context Protocol (MCP) server designed to enable AI models, such as those integrated into Cursor IDE or Claude Desktop, to interact with MySQL databases. It offers a standardized interface for AI agents to perform common database operations like connecting, querying, executing DML statements, and managing schema. Currently at version 0.2.0, the package is in early development, implying potentially frequent updates and API changes before a stable 1.0 release. Its key differentiator is simplifying MySQL integration for AI agents through the MCP abstraction, allowing models to operate on databases without needing to handle direct driver interactions or complex connection pooling. Configuration is flexible, supporting database URLs, individual credentials via `.env` files, or direct arguments to the `connect_db` tool.

npm install mcp-mysql-server
INSTALL
IMPORT
SIG · MCP-MYSQL-SERVER
M
mcp-mysql-server
databasejavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

connect_db
await use_mcp_tool({ server_name: "mysql", tool_name: "connect_db", arguments: { url: "mysql://user:pass@host:3306/db" } })
import { connect_db } from '@enemyrr/mcp-mysql-server'
This package is an MCP server; its functionality (tools like `connect_db`) is accessed via an MCP client's `use_mcp_tool` abstraction, not through direct JavaScript `import` or `require` statements from user application code.
query
await use_mcp_tool({ server_name: "mysql", tool_name: "query", arguments: { sql: "SELECT * FROM users", params: [] } })
const query = require('@enemyrr/mcp-mysql-server').query
The `query` tool for executing SELECT statements is exposed by the MCP server and invoked through the MCP client's API, facilitating AI model interaction with the database.
execute
await use_mcp_tool({ server_name: "mysql", tool_name: "execute", arguments: { sql: "INSERT INTO logs (message) VALUES (?) ", params: ['test'] } })
type ExecuteArgs = typeof import('@enemyrr/mcp-mysql-server')['execute']
Similar to other tools, the `execute` tool for DML operations (INSERT, UPDATE, DELETE) is a server capability accessed programmatically via the MCP client interface, not a directly importable function or type.
list_tables
await use_mcp_tool({ server_name: "mysql", tool_name: "list_tables" })
import { list_tables } from '@enemyrr/mcp-mysql-server/tools'
Server-provided tools like `list_tables` are part of the MCP contract. Direct file imports from the server package will fail and are not the intended interaction method.

Demonstrates connecting to a MySQL database using environment variables, executing a simple SELECT query, performing an INSERT statement, and listing database tables via the `use_mcp_tool` abstraction.

// This code assumes you are running within an environment that provides `use_mcp_tool`, // such as Cursor IDE or a compatible AI agent framework. // Ensure your .env file in the workspace root has DATABASE_URL=mysql://user:password@host:3306/database // or individual DB_HOST, DB_USER, etc. async function runDbOperations() { console.log("Attempting to connect to MySQL..."); // 1. Connect to the database using environment variables from the workspace const connectResult = await use_mcp_tool({ server_name: "mysql", tool_name: "connect_db", arguments: { workspace: process.env.MCP_WORKSPACE_PATH ?? "./" // Uses .env from current directory } }); if (connectResult.status === 'success') { console.log("Successfully connected to MySQL database."); // 2. Execute a simple SELECT query const selectQueryResult = await use_mcp_tool({ server_name: "mysql", tool_name: "query", arguments: { sql: "SELECT 1 + 1 AS solution, CURRENT_USER() AS user;", params: [] } }); if (selectQueryResult.status === 'success') { console.log("Select Query result:", selectQueryResult.data); } else { console.error("Select Query failed:", selectQueryResult.error); } // 3. Example: Execute an INSERT statement (requires a 'test_table' or similar) // Ensure a table exists, e.g., CREATE TABLE test_table (id INT AUTO_INCREMENT PRIMARY KEY, message VARCHAR(255)); const insertQueryResult = await use_mcp_tool({ server_name: "mysql", tool_name: "execute", arguments: { sql: "INSERT INTO test_table (message) VALUES (?)", params: ["Hello from MCP MySQL Server!"] } }); if (insertQueryResult.status === 'success') { console.log("Insert Query successful. Rows affected:", insertQueryResult.data.rowsAffected); } else { console.error("Insert Query failed:", insertQueryResult.error); } // 4. List all tables in the connected database const listTablesResult = await use_mcp_tool({ server_name: "mysql", tool_name: "list_tables" }); if (listTablesResult.status === 'success') { console.log("Tables in database:", listTablesResult.data); } else { console.error("List tables failed:", listTablesResult.error); } } else { console.error("Failed to connect to MySQL database:", connectResult.error); } } // In a real AI agent context, this function would be called implicitly or explicitly by the agent. runDbOperations();
Debug
Known issues
breakingAs a pre-1.0 release (v0.2.0), the API and exposed tool definitions are subject to change without notice. Future versions may introduce breaking changes requiring updates to MCP client integrations.
fix
Always consult the latest README and changelog for the installed version. Pin dependency versions and test thoroughly before upgrading in production environments.
affects: >=0.2.0
gotchaIncorrect or incomplete database configuration (via .env or direct arguments) will lead to connection failures. The server may start but tools will fail to execute with database errors.
fix
Verify `DATABASE_URL` or individual `DB_HOST`, `DB_USER`, `DB_PASSWORD`, `DB_DATABASE` variables in your `.env` file or the arguments passed to `connect_db`. Ensure the MySQL server is running and accessible from where `mcp-mysql-server` is hosted.
affects: >=0.2.0
gotchaWhile the provided examples use prepared statements (`sql` with `params`), developers manually constructing SQL strings without parameterization can introduce SQL injection vulnerabilities.
fix
Always use the `params` array with placeholders (`?`) in your `sql` strings for `query` and `execute` tools when incorporating user-supplied or dynamic values. Never concatenate values directly into the `sql` string.
affects: >=0.2.0
Errors
Common errors & fixes
Error: connect ECONNREFUSED
The MySQL server is not running or is inaccessible from the host running the MCP server, or the specified host/port is incorrect.
fix
Ensure the MySQL database server is active and reachable. Verify the `DB_HOST` and `DB_PORT` (default 3306) in your `.env` configuration or `connect_db` arguments.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'user'@'host' (using password: YES/NO)
Incorrect username or password provided for the MySQL database connection.
fix
Double-check the `DB_USER` and `DB_PASSWORD` variables in your `.env` file or `connect_db` arguments against your MySQL user credentials.
Error: ER_BAD_DB_ERROR: Unknown database 'your_database'
The specified database name in the connection string or parameters does not exist on the MySQL server.
fix
Verify that the `DB_DATABASE` variable in your `.env` file or the `database` argument in `connect_db` matches an existing database on your MySQL server. Create the database if it's missing.
MCP server 'mysql' not found (when calling `use_mcp_tool`)
The `mcp-mysql-server` has not been correctly registered or configured within your MCP client environment (e.g., Cursor IDE).
fix
Follow the 'Installation & Setup for Cursor IDE' steps in the README. Ensure the `Name` field for the server is exactly `mysql` and the `Command` path points to the correct `index.js` build file of the cloned project.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
mysql2requiredRuntime dependency for connecting to and interacting with MySQL databases.
dotenvrequiredRequired for loading database connection configurations from .env files, as recommended for setup.
Agent activity
16 hits · last 30 days
node
12
OpenAI (training)
1
Resources
mcp-mysql-server — npm install mcp-mysql-server · libregistry