use_database
Switch between MySQL databases to manage, query, or modify data in different database contexts within the MCP Server MySQL environment.
Instructions
Switch to a different database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | Database name |
Implementation Reference
- src/index.ts:501-517 (handler)The handler function for the 'use_database' tool. It acquires a database pool connection, executes the 'USE `database`' SQL command to switch databases, constructs a success output, and returns a structured response with text content.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, }; }
- src/index.ts:498-500 (schema)Input schema definition using Zod for the 'use_database' tool, requiring a 'database' string parameter.{ database: z.string().describe("Database name"), },
- src/index.ts:495-518 (registration)Registration of the 'use_database' tool via server.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, }; } );