Skip to main content
Glama
nilsir

MCP Server MySQL

by nilsir

use_database

Switch to a different database within MySQL to manage tables, query data, and perform operations in the selected database context.

Instructions

Switch to a different database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesDatabase name

Implementation Reference

  • The handler function for the 'use_database' tool. It switches the current database context by executing a 'USE' SQL statement on the MySQL connection pool.
    async ({ database }) => { const p = await getPool(); await p.query(`USE \`${database}\``); const output = { success: true, database }; return { content: [ { type: "text" as const, text: `Switched to database ${database}`, }, ], structuredContent: output, }; }
  • Zod schema defining the input parameters for the 'use_database' tool, requiring a 'database' string.
    { database: z.string().describe("Database name"), },
  • src/index.ts:495-518 (registration)
    Registration of the 'use_database' tool using McpServer.tool(), including name, description, input schema, and handler function.
    server.tool( "use_database", "Switch to a different database", { database: z.string().describe("Database name"), }, async ({ database }) => { const p = await getPool(); await p.query(`USE \`${database}\``); const output = { success: true, database }; return { content: [ { type: "text" as const, text: `Switched to database ${database}`, }, ], structuredContent: output, }; } );
  • Helper function to initialize and return the MySQL connection pool, used by the 'use_database' handler.
    async function getPool(): Promise<Pool> { if (!pool) { pool = mysql.createPool(getConnectionConfig()); } return pool; }

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

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