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"]
            }
          }
        ]
      };
    });
Behavior2/5

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

With no annotations provided, the description carries full burden but only states the action without behavioral details. It doesn't disclose whether switching databases requires existing connections, affects ongoing queries, has permission requirements, or provides confirmation feedback. This leaves significant behavioral gaps for a mutation operation.

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, efficient sentence with zero wasted words. It's appropriately sized for a simple tool and front-loads the essential information without unnecessary elaboration.

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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what 'switch' entails operationally, what happens to existing connections/queries, what success/failure looks like, or how it relates to sibling tools. The context demands more behavioral disclosure than provided.

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 description coverage is 100% with one well-documented parameter, so the baseline is 3. The description adds no additional parameter semantics beyond what the schema already provides ('Name of the database to switch to'), maintaining but not enhancing the parameter understanding.

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

Purpose4/5

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

The description clearly states the action ('Switch') and target resource ('different database'), providing a specific verb+resource combination. However, it doesn't explicitly differentiate from sibling tools like 'connect' or 'list_databases', which prevents a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'connect' (for initial connection) or 'list_databases' (for discovery). It lacks context about prerequisites, timing, or exclusions, offering only the basic function without usage context.

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

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