create_database
Create a new MySQL database with configurable character set and collation settings for organizing and storing data.
Instructions
Create a new database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | Database name | |
| charset | No | Character set (default: utf8mb4) | |
| collation | No | Collation (default: utf8mb4_unicode_ci) |
Implementation Reference
- src/index.ts:445-465 (handler)The handler function for the 'create_database' tool. It creates a new MySQL database using the provided name, charset, and collation, then returns a success response with structured output.async ({ database, charset, collation }) => { const p = await getPool(); const cs = charset || "utf8mb4"; const col = collation || "utf8mb4_unicode_ci"; await p.execute( `CREATE DATABASE \`${database}\` CHARACTER SET ${cs} COLLATE ${col}` ); const output = { success: true, database, charset: cs, collation: col }; return { content: [ { type: "text" as const, text: `Database ${database} created successfully`, }, ], structuredContent: output, }; }
- src/index.ts:440-444 (schema)The input schema (Zod) for the 'create_database' tool defining parameters: database (required string), charset and collation (optional strings).{ database: z.string().describe("Database name"), charset: z.string().optional().describe("Character set (default: utf8mb4)"), collation: z.string().optional().describe("Collation (default: utf8mb4_unicode_ci)"), },
- src/index.ts:437-466 (registration)The registration of the 'create_database' tool using server.tool(), including name, description, input schema, and handler function.server.tool( "create_database", "Create a new database", { database: z.string().describe("Database name"), charset: z.string().optional().describe("Character set (default: utf8mb4)"), collation: z.string().optional().describe("Collation (default: utf8mb4_unicode_ci)"), }, async ({ database, charset, collation }) => { const p = await getPool(); const cs = charset || "utf8mb4"; const col = collation || "utf8mb4_unicode_ci"; await p.execute( `CREATE DATABASE \`${database}\` CHARACTER SET ${cs} COLLATE ${col}` ); const output = { success: true, database, charset: cs, collation: col }; return { content: [ { type: "text" as const, text: `Database ${database} created successfully`, }, ], structuredContent: output, }; } );