create_database
Create a new MySQL database with configurable character set and collation settings for organizing and managing 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 gets a connection pool, sets default charset and collation if not provided, executes the CREATE DATABASE SQL statement, and returns success response with details.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)Zod input schema defining parameters for the create_database tool: required database name, optional charset and collation.{ 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)Registration of the create_database tool on the MCP server using server.tool(name, description, inputSchema, handler).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, }; } );