### Installation and Basic Usage Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Instructions on how to install the MCP MySQL Server using Smithery CLI or npx, and how to run it directly with a MySQL connection URL. ```APIDOC ## Installation Install the MCP MySQL Server via Smithery CLI or run directly with npx. ```bash # Install via Smithery for Claude Desktop npx -y @smithery/cli install @f4ww4z/mcp-mysql-server --client claude # Or run directly with npx npx @f4ww4z/mcp-mysql-server mysql://user:password@localhost:3306/database ``` ``` -------------------------------- ### Install via Smithery Source: https://github.com/f4ww4z/mcp-mysql-server/blob/main/README.md Automatically install the MCP server for Claude Desktop using the Smithery CLI. ```bash npx -y @smithery/cli install @f4ww4z/mcp-mysql-server --client claude ``` -------------------------------- ### Install and Run MCP MySQL Server Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Commands to install the server via Smithery CLI or execute it directly using npx. ```bash # Install via Smithery for Claude Desktop npx -y @smithery/cli install @f4ww4z/mcp-mysql-server --client claude # Or run directly with npx npx @f4ww4z/mcp-mysql-server mysql://user:password@localhost:3306/database ``` -------------------------------- ### Manual Installation Source: https://github.com/f4ww4z/mcp-mysql-server/blob/main/README.md Run the server manually using npx. ```bash npx @f4ww4z/mcp-mysql-server ``` -------------------------------- ### Describe Table Structure Source: https://github.com/f4ww4z/mcp-mysql-server/blob/main/README.md Get the schema structure of a specific table. ```typescript use_mcp_tool({ server_name: "mysql", tool_name: "describe_table", arguments: { table: "users" } }); ``` -------------------------------- ### Configuration Methods Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Details on configuring the MCP MySQL Server using MCP client settings with a MySQL connection URL or via environment variables. ```APIDOC ## Configuration with MCP Settings (Recommended) Configure the server in your MCP client settings file using a MySQL connection URL for the simplest setup. ```json { "mcpServers": { "mysql": { "command": "npx", "args": ["-y", "@f4ww4z/mcp-mysql-server", "mysql://user:password@localhost:3306/database"] } } } ``` ## Configuration with Environment Variables Configure the server using individual environment variables when you need separate credential management. ```json { "mcpServers": { "mysql": { "command": "npx", "args": ["-y", "@f4ww4z/mcp-mysql-server"], "env": { "MYSQL_HOST": "localhost", "MYSQL_USER": "your_user", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database", "MYSQL_PORT": "3306" } } } } ``` ``` -------------------------------- ### Configure MCP MySQL Server with Environment Variables Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Configuration block for MCP clients using individual environment variables for credentials. ```json { "mcpServers": { "mysql": { "command": "npx", "args": ["-y", "@f4ww4z/mcp-mysql-server"], "env": { "MYSQL_HOST": "localhost", "MYSQL_USER": "your_user", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database", "MYSQL_PORT": "3306" } } } } ``` -------------------------------- ### Connect to Database Source: https://github.com/f4ww4z/mcp-mysql-server/blob/main/README.md Establish a connection to a MySQL database using the connect_db tool. ```typescript use_mcp_tool({ server_name: "mysql", tool_name: "connect_db", arguments: { host: "localhost", user: "your_user", password: "your_password", database: "your_database" } }); ``` -------------------------------- ### Connect to Database using connect_db Tool Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Establishes a database connection using individual parameters. Automatically closes existing connections. ```typescript // Connect using individual parameters use_mcp_tool({ server_name: "mysql", tool_name: "connect_db", arguments: { host: "localhost", user: "admin", password: "secret", database: "myapp", port: 3306 // optional, defaults to 3306 } }); // Expected response: // { // "content": [ // { // "type": "text", // "text": "Successfully connected to database" // } // ] // } ``` -------------------------------- ### connect_db Tool Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Details on using the `connect_db` tool to establish a connection to a MySQL database, supporting individual parameters and MySQL URL format. ```APIDOC ## connect_db Tool Establishes a connection to a MySQL database using provided credentials. Supports both individual parameters and MySQL URL format. Automatically closes any existing connection before creating a new one. ```typescript // Connect using individual parameters use_mcp_tool({ server_name: "mysql", tool_name: "connect_db", arguments: { host: "localhost", user: "admin", password: "secret", database: "myapp", port: 3306 // optional, defaults to 3306 } }); // Expected response: // { // "content": [ // { // "type": "text", // "text": "Successfully connected to database" // } // ] // } ``` ``` -------------------------------- ### MCP Server Configuration Source: https://github.com/f4ww4z/mcp-mysql-server/blob/main/README.md Configure the MCP server in your settings file using either a connection string or environment variables. ```json { "mcpServers": { "mysql": { "command": "npx", "args": ["-y", "@f4ww4z/mcp-mysql-server", "mysql://user:password@localhost:port/database"], } } } ``` ```json { "mcpServers": { "mysql": { "command": "npx", "args": ["-y", "@f4ww4z/mcp-mysql-server"], "env": { "MYSQL_HOST": "your_host", "MYSQL_USER": "your_user", "MYSQL_PASSWORD": "your_password", "MYSQL_DATABASE": "your_database" } } } } ``` -------------------------------- ### execute Tool Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Executes INSERT, UPDATE, or DELETE queries with optional prepared statement parameters. ```APIDOC ## execute Tool ### Description Executes INSERT, UPDATE, or DELETE queries with optional prepared statement parameters. Returns the result object containing affected rows, insert ID, and other metadata. SELECT statements are not allowed. ### Parameters #### Request Body - **sql** (string) - Required - The SQL query to execute. - **params** (array) - Optional - Parameters for the prepared statement. ### Request Example { "sql": "INSERT INTO users (name, email, age) VALUES (?, ?, ?)", "params": ["John Doe", "john@example.com", 42] } ### Response #### Success Response (200) - **affectedRows** (number) - Number of rows affected by the query. - **insertId** (number) - The ID generated by the database for an AUTO_INCREMENT column. #### Response Example { "fieldCount": 0, "affectedRows": 1, "insertId": 5, "serverStatus": 2, "warningCount": 0 } ``` -------------------------------- ### Configure MCP MySQL Server with Connection URL Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Configuration block for MCP clients using a MySQL connection string. ```json { "mcpServers": { "mysql": { "command": "npx", "args": ["-y", "@f4ww4z/mcp-mysql-server", "mysql://user:password@localhost:3306/database"] } } } ``` -------------------------------- ### Codex Configuration Source: https://github.com/f4ww4z/mcp-mysql-server/blob/main/README.md Configure the MCP server for Codex on macOS or Windows. ```toml [mcp_servers.mcp-mysql-server] command = "npx" args = [ "-y", "@f4ww4z/mcp-mysql-server", "mysql://user:password@127.0.0.1:3306/database" ] ``` ```toml [mcp_servers.mcp-mysql-server] command = "npx" args = [ "-y", "@f4ww4z/mcp-mysql-server", "mysql://user:password@127.0.0.1:3306/database" ] ``` -------------------------------- ### Run MCP Evaluation Suite Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Execute the included MCP evaluation suite to test the functionality of all five tools using OpenAI's GPT-4 model. Ensure your OpenAI API key is set as an environment variable. ```bash # Set your OpenAI API key and run evals OPENAI_API_KEY=your-key npx mcp-eval src/evals/evals.ts src/index.ts ``` -------------------------------- ### Codex Configuration Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Specific configuration instructions for using MCP MySQL Server with Codex CLI on macOS and Windows. ```APIDOC ## Configuration for Codex (macOS) Configure the server in `~/.codex/config.toml` for use with Codex CLI on macOS. ```toml [mcp_servers.mcp-mysql-server] command = "npx" args = [ "-y", "@f4ww4z/mcp-mysql-server", "mysql://user:password@127.0.0.1:3306/database" ] ``` ## Configuration for Codex (Windows) Configure the server in `%USERPROFILE%\.codex\config.toml` for use with Codex CLI on Windows. ```toml [mcp_servers.mcp-mysql-server] command = "npx" args = [ "-y", "@f4ww4z/mcp-mysql-server", "mysql://user:password@127.0.0.1:3306/database" ] ``` ``` -------------------------------- ### query Tool Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Information on using the `query` tool to execute SELECT queries, including support for prepared statement parameters to prevent SQL injection. ```APIDOC ## query Tool Executes SELECT queries against the connected database with optional prepared statement parameters. This tool only accepts SELECT statements; use the execute tool for data modifications. ```typescript // Simple SELECT query use_mcp_tool({ server_name: "mysql", tool_name: "query", arguments: { sql: "SELECT * FROM users LIMIT 10" } }); // SELECT with prepared statement parameters (prevents SQL injection) use_mcp_tool({ server_name: "mysql", tool_name: "query", arguments: { sql: "SELECT id, name, email FROM users WHERE status = ? AND created_at > ?", params: ["active", "2024-01-01"] } }); // Expected response: // { // "content": [ // { // "type": "text", // "text": "[ // { // "id": 1, // "name": "John Doe", // "email": "john@example.com" // }, // { // "id": 2, // "name": "Jane Smith", // "email": "jane@example.com" // } // ]" // } // ] // } ``` ``` -------------------------------- ### Execute SELECT Query Source: https://github.com/f4ww4z/mcp-mysql-server/blob/main/README.md Run a SELECT query with optional prepared statement parameters. ```typescript use_mcp_tool({ server_name: "mysql", tool_name: "query", arguments: { sql: "SELECT * FROM users WHERE id = ?", params: [1] } }); ``` -------------------------------- ### list_tables Tool Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Lists all tables in the currently connected database. ```APIDOC ## list_tables Tool ### Description Lists all tables in the currently connected database. Takes no arguments and returns an array of table names. ### Response #### Success Response (200) - **tables** (array) - List of table objects. #### Response Example [ { "Tables_in_myapp": "users" }, { "Tables_in_myapp": "orders" } ] ``` -------------------------------- ### Execute INSERT, UPDATE, DELETE Queries Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Use the 'execute' tool for INSERT, UPDATE, or DELETE operations. It supports prepared statements for safe parameter handling. SELECT statements are not permitted with this tool. ```typescript use_mcp_tool({ server_name: "mysql", tool_name: "execute", arguments: { sql: "INSERT INTO users (name, email, age) VALUES (?, ?, ?)", params: ["John Doe", "john@example.com", 42] } }); ``` ```typescript use_mcp_tool({ server_name: "mysql", tool_name: "execute", arguments: { sql: "UPDATE users SET status = ? WHERE last_login < ?", params: ["inactive", "2023-01-01"] } }); ``` ```typescript use_mcp_tool({ server_name: "mysql", tool_name: "execute", arguments: { sql: "DELETE FROM sessions WHERE expired_at < ?", params: ["2024-01-01"] } }); ``` -------------------------------- ### Run Evaluations Source: https://github.com/f4ww4z/mcp-mysql-server/blob/main/README.md Execute tests using the mcp-eval package with required environment variables. ```bash OPENAI_API_KEY=your-key npx mcp-eval src/evals/evals.ts src/index.ts ``` -------------------------------- ### MCP MySQL Server Tools Source: https://github.com/f4ww4z/mcp-mysql-server/blob/main/README.md This section details the available tools for interacting with the MySQL database via the MCP server. ```APIDOC ## Tool: connect_db ### Description Establish connection to MySQL database using provided credentials. ### Method `use_mcp_tool` ### Endpoint N/A (Tool Function) ### Parameters #### Request Body - **server_name** (string) - Required - The name of the MCP server (e.g., "mysql"). - **tool_name** (string) - Required - The name of the tool to use (e.g., "connect_db"). - **arguments** (object) - Required - An object containing the arguments for the tool. - **host** (string) - Required - The database host. - **user** (string) - Required - The database username. - **password** (string) - Required - The database password. - **database** (string) - Required - The database name. ### Request Example ```json { "server_name": "mysql", "tool_name": "connect_db", "arguments": { "host": "localhost", "user": "your_user", "password": "your_password", "database": "your_database" } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. #### Response Example ```json { "status": "connected" } ``` ``` ```APIDOC ## Tool: query ### Description Execute SELECT queries with optional prepared statement parameters. ### Method `use_mcp_tool` ### Endpoint N/A (Tool Function) ### Parameters #### Request Body - **server_name** (string) - Required - The name of the MCP server (e.g., "mysql"). - **tool_name** (string) - Required - The name of the tool to use (e.g., "query"). - **arguments** (object) - Required - An object containing the arguments for the tool. - **sql** (string) - Required - The SQL query to execute. - **params** (array) - Optional - An array of parameters for prepared statements. ### Request Example ```json { "server_name": "mysql", "tool_name": "query", "arguments": { "sql": "SELECT * FROM users WHERE id = ?", "params": [1] } } ``` ### Response #### Success Response (200) - **data** (array) - An array of rows returned by the query. #### Response Example ```json { "data": [ { "id": 1, "name": "John Doe", "email": "john@example.com" } ] } ``` ``` ```APIDOC ## Tool: execute ### Description Execute INSERT, UPDATE, or DELETE queries with optional prepared statement parameters. ### Method `use_mcp_tool` ### Endpoint N/A (Tool Function) ### Parameters #### Request Body - **server_name** (string) - Required - The name of the MCP server (e.g., "mysql"). - **tool_name** (string) - Required - The name of the tool to use (e.g., "execute"). - **arguments** (object) - Required - An object containing the arguments for the tool. - **sql** (string) - Required - The SQL query to execute. - **params** (array) - Optional - An array of parameters for prepared statements. ### Request Example ```json { "server_name": "mysql", "tool_name": "execute", "arguments": { "sql": "INSERT INTO users (name, email) VALUES (?, ?)", "params": ["John Doe", "john@example.com"] } } ``` ### Response #### Success Response (200) - **status** (string) - Indicates the success of the operation. - **affected_rows** (integer) - The number of rows affected by the query. #### Response Example ```json { "status": "success", "affected_rows": 1 } ``` ``` ```APIDOC ## Tool: list_tables ### Description List all tables in the connected database. ### Method `use_mcp_tool` ### Endpoint N/A (Tool Function) ### Parameters #### Request Body - **server_name** (string) - Required - The name of the MCP server (e.g., "mysql"). - **tool_name** (string) - Required - The name of the tool to use (e.g., "list_tables"). - **arguments** (object) - Required - An empty object as no arguments are needed. ### Request Example ```json { "server_name": "mysql", "tool_name": "list_tables", "arguments": {} } ``` ### Response #### Success Response (200) - **tables** (array) - An array of table names in the database. #### Response Example ```json { "tables": ["users", "products", "orders"] } ``` ``` ```APIDOC ## Tool: describe_table ### Description Get the structure of a specific table. ### Method `use_mcp_tool` ### Endpoint N/A (Tool Function) ### Parameters #### Request Body - **server_name** (string) - Required - The name of the MCP server (e.g., "mysql"). - **tool_name** (string) - Required - The name of the tool to use (e.g., "describe_table"). - **arguments** (object) - Required - An object containing the arguments for the tool. - **table** (string) - Required - The name of the table to describe. ### Request Example ```json { "server_name": "mysql", "tool_name": "describe_table", "arguments": { "table": "users" } } ``` ### Response #### Success Response (200) - **columns** (array) - An array of column definitions for the table. #### Response Example ```json { "columns": [ {"name": "id", "type": "INT"}, {"name": "name", "type": "VARCHAR(255)"}, {"name": "email", "type": "VARCHAR(255)"} ] } ``` ``` -------------------------------- ### List Database Tables Source: https://github.com/f4ww4z/mcp-mysql-server/blob/main/README.md Retrieve a list of all tables in the currently connected database. ```typescript use_mcp_tool({ server_name: "mysql", tool_name: "list_tables", arguments: {} }); ``` -------------------------------- ### Execute SELECT Queries using query Tool Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Executes SELECT statements with optional prepared statement parameters to prevent SQL injection. ```typescript // Simple SELECT query use_mcp_tool({ server_name: "mysql", tool_name: "query", arguments: { sql: "SELECT * FROM users LIMIT 10" } }); // SELECT with prepared statement parameters (prevents SQL injection) use_mcp_tool({ server_name: "mysql", tool_name: "query", arguments: { sql: "SELECT id, name, email FROM users WHERE status = ? AND created_at > ?", params: ["active", "2024-01-01"] } }); // Expected response: // { // "content": [ // { // "type": "text", // "text": "[\n {\n \"id\": 1,\n \"name\": \"John Doe\",\n \"email\": \"john@example.com\"\n },\n {\n \"id\": 2,\n \"name\": \"Jane Smith\",\n \"email\": \"jane@example.com\"\n }\n]" // } // ] // } ``` -------------------------------- ### describe_table Tool Source: https://context7.com/f4ww4z/mcp-mysql-server/llms.txt Retrieves the complete structure of a specified table. ```APIDOC ## describe_table Tool ### Description Retrieves the complete structure of a specified table including column names, data types, nullability, keys, defaults, and extra attributes. ### Parameters #### Request Body - **table** (string) - Required - The name of the table to describe. ### Request Example { "table": "users" } ### Response #### Success Response (200) - **Field** (string) - Column name. - **Type** (string) - Data type. - **Null** (string) - Nullability status. - **Key** (string) - Key information. - **Default** (string) - Default value. - **Extra** (string) - Extra attributes. #### Response Example [ { "Field": "id", "Type": "int(11)", "Null": "NO", "Key": "PRI", "Default": null, "Extra": "auto_increment" } ] ``` -------------------------------- ### Execute Data Modification Source: https://github.com/f4ww4z/mcp-mysql-server/blob/main/README.md Run INSERT, UPDATE, or DELETE queries using the execute tool. ```typescript use_mcp_tool({ server_name: "mysql", tool_name: "execute", arguments: { sql: "INSERT INTO users (name, email) VALUES (?, ?)", params: ["John Doe", "john@example.com"] } }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.