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

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

B3.3/5.0
Behavior2/5

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

With no annotations, the description carries the full burden. It states an action but does not disclose side effects (e.g., impact on subsequent queries, reversibility, validation of database names). Minimal transparency beyond the stated purpose.

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, concise and front-loaded. It communicates the core action without wasted words.

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?

For a simple tool with one parameter and no output schema, the description covers the basic purpose. However, it lacks behavioral details (e.g., what 'switch' means for state or session) which would be beneficial for 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?

Schema coverage is 100%, so the parameter description already exists. The tool description adds no extra meaning beyond the schema's 'Name of the database to switch to'. Baseline 3 is appropriate as no additional semantics are provided.

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 'Switch to a different database' clearly states the verb (switch) and resource (database). It distinguishes the tool from siblings like 'connect' (establish connection) and 'list_databases' (list databases), making its unique purpose obvious.

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?

No guidance is provided on when to use this tool versus alternatives. For example, it does not mention prerequisites (e.g., a current connection) or contrast with 'connect' or 'set_readonly'. The implicit usage is clear, but explicit context is missing.

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

Deploy Server

Other Tools

Related Tools