Skip to main content
Glama
sussa3007

MySql MCP Server

use_database

Switch to a specific MySQL database on MySql MCP server. Provide the database name to establish connection and access data for query execution or management tasks.

Instructions

Switch to a different database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesName of the database to switch to

Implementation Reference

  • The handler for the 'use_database' tool. It extracts the database name from arguments, validates it, executes a 'USE ??' query with the name as parameter, updates the connectionConfig.database, and returns a success message or error.
    case "use_database": {
      try {
        const dbName = request.params.arguments?.database as string;
    
        if (!dbName) {
          throw new Error("Database name is required");
        }
    
        await executeQuery("USE ??", [dbName]);
        connectionConfig.database = dbName;
    
        return {
          content: [
            {
              type: "text",
              text: `Successfully switched to database: ${dbName}`
            }
          ],
          isError: false
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text:
                error instanceof Error
                  ? error.message
                  : "Unknown error occurred"
            }
          ],
          isError: true
        };
      }
    }
  • Tool schema definition including name, description, and input schema for 'use_database' tool, registered in the ListTools response.
    {
      name: "use_database",
      description: "Switch to a different database.",
      inputSchema: {
        type: "object",
        properties: {
          database: {
            type: "string",
            description: "Name of the database to switch to"
          }
        },
        required: ["database"]
      }
    },
  • src/index.ts:136-276 (registration)
    Registration of all tools including 'use_database' in the ListToolsRequestSchema handler.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "status",
            description: "Check the current database connection status.",
            inputSchema: {
              type: "object",
              properties: {
                random_string: {
                  type: "string",
                  description: "Dummy parameter for no-parameter tools"
                }
              },
              required: ["random_string"]
            }
          },
          {
            name: "connect",
            description: "Connect to a MySQL database.",
            inputSchema: {
              type: "object",
              properties: {
                host: {
                  type: "string",
                  description: "Database server hostname or IP address"
                },
                port: { type: "string", description: "Database server port" },
                user: { type: "string", description: "Database username" },
                password: { type: "string", description: "Database password" },
                database: {
                  type: "string",
                  description: "Database name to connect to"
                }
              }
            }
          },
          {
            name: "disconnect",
            description: "Close the current MySQL database connection.",
            inputSchema: {
              type: "object",
              properties: {
                random_string: {
                  type: "string",
                  description: "Dummy parameter for no-parameter tools"
                }
              },
              required: ["random_string"]
            }
          },
          {
            name: "query",
            description: "Execute an SQL query on the connected database.",
            inputSchema: {
              type: "object",
              properties: {
                sql: { type: "string", description: "SQL query to execute" },
                params: {
                  type: "array",
                  description: "Parameters for prepared statements",
                  items: { type: "string" }
                }
              },
              required: ["sql"]
            }
          },
          {
            name: "list_tables",
            description: "Get a list of tables in the current database.",
            inputSchema: {
              type: "object",
              properties: {
                random_string: {
                  type: "string",
                  description: "Dummy parameter for no-parameter tools"
                }
              },
              required: ["random_string"]
            }
          },
          {
            name: "describe_table",
            description: "Get the structure of a specific table.",
            inputSchema: {
              type: "object",
              properties: {
                table: {
                  type: "string",
                  description: "Name of the table to describe"
                }
              },
              required: ["table"]
            }
          },
          {
            name: "list_databases",
            description: "Get a list of all accessible databases on the server.",
            inputSchema: {
              type: "object",
              properties: {
                random_string: {
                  type: "string",
                  description: "Dummy parameter for no-parameter tools"
                }
              },
              required: ["random_string"]
            }
          },
          {
            name: "use_database",
            description: "Switch to a different database.",
            inputSchema: {
              type: "object",
              properties: {
                database: {
                  type: "string",
                  description: "Name of the database to switch to"
                }
              },
              required: ["database"]
            }
          },
          {
            name: "set_readonly",
            description: "Enable or disable read-only mode",
            inputSchema: {
              type: "object",
              properties: {
                readonly: {
                  type: "boolean",
                  description:
                    "Set to true to enable read-only mode, false to disable"
                }
              },
              required: ["readonly"]
            }
          }
        ]
      };
    });

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related Tools

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/sussa3007/mysql-mcp'

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