Skip to main content
Glama
nilsir

MCP Server MySQL

by nilsir

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
NameRequiredDescriptionDefault
databaseYesDatabase name
charsetNoCharacter set (default: utf8mb4)
collationNoCollation (default: utf8mb4_unicode_ci)

Implementation Reference

  • 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,
      };
    }
  • 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,
        };
      }
    );

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