Skip to main content
Glama
kevinbin

MCP MySQL Server

by kevinbin

create_table

Define and generate a new table in a MySQL database by specifying table name, fields, data types, indexes, and other properties using the MCP MySQL Server interface.

Instructions

Create a new table in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fieldsYes
indexesNo
tableYesTable name

Implementation Reference

  • The handler function for create_table tool. It constructs the CREATE TABLE SQL statement from the provided table name, fields, and optional indexes, then executes it using executeQuery.
    private async handleCreateTable(args: any) {
      const fields = args.fields.map((field: SchemaField) => {
        let def = `\`${field.name}\` ${field.type.toUpperCase()}`;
        if (field.length) def += `(${field.length})`;
        if (field.nullable === false) def += ' NOT NULL';
        if (field.default !== undefined) {
          def += ` DEFAULT ${field.default === null ? 'NULL' : `'${field.default}'`}`;
        }
        if (field.autoIncrement) def += ' AUTO_INCREMENT';
        if (field.primary) def += ' PRIMARY KEY';
        return def;
      });
    
      const indexes = args.indexes?.map((idx: IndexDefinition) => {
        const type = idx.unique ? 'UNIQUE INDEX' : 'INDEX';
        return `${type} \`${idx.name}\` (\`${idx.columns.join('`, `')}\`)`;
      }) || [];
    
      const sql = `CREATE TABLE \`${args.table}\` (
        ${[...fields, ...indexes].join(',\n      ')}
      )`;
    
      await this.executeQuery(sql);
      return {
        content: [
          {
            type: 'text',
            text: `Table ${args.table} created successfully`
          }
        ]
      };
    }
  • Input schema for the create_table tool, defining the structure for table name, fields (with name, type, etc.), and optional indexes.
    inputSchema: {
      type: 'object',
      properties: {
        table: {
          type: 'string',
          description: 'Table name',
        },
        fields: {
          type: 'array',
          items: {
            type: 'object',
            properties: {
              name: { type: 'string' },
              type: { type: 'string' },
              length: { type: 'number', optional: true },
              nullable: { type: 'boolean', optional: true },
              default: {
                type: ['string', 'number', 'null'],
                optional: true
              },
              autoIncrement: { type: 'boolean', optional: true },
              primary: { type: 'boolean', optional: true }
            },
            required: ['name', 'type']
          }
        },
        indexes: {
          type: 'array',
          items: {
            type: 'object',
            properties: {
              name: { type: 'string' },
              columns: {
                type: 'array',
                items: { type: 'string' }
              },
              unique: { type: 'boolean', optional: true }
            },
            required: ['name', 'columns']
          },
          optional: true
        }
      },
      required: ['table', 'fields']
  • src/index.ts:440-488 (registration)
    Registration of the create_table tool in the ListTools response, including name, description, and input schema.
    {
      name: 'create_table',
      description: 'Create a new table in the database',
      inputSchema: {
        type: 'object',
        properties: {
          table: {
            type: 'string',
            description: 'Table name',
          },
          fields: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                name: { type: 'string' },
                type: { type: 'string' },
                length: { type: 'number', optional: true },
                nullable: { type: 'boolean', optional: true },
                default: {
                  type: ['string', 'number', 'null'],
                  optional: true
                },
                autoIncrement: { type: 'boolean', optional: true },
                primary: { type: 'boolean', optional: true }
              },
              required: ['name', 'type']
            }
          },
          indexes: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                name: { type: 'string' },
                columns: {
                  type: 'array',
                  items: { type: 'string' }
                },
                unique: { type: 'boolean', optional: true }
              },
              required: ['name', 'columns']
            },
            optional: true
          }
        },
        required: ['table', 'fields']
      }
    },
  • src/index.ts:529-530 (registration)
    Registration of the create_table handler in the CallToolRequest switch statement dispatcher.
    case 'create_table':
      return await this.handleCreateTable(request.params.arguments);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states 'create' implies a write operation but doesn't cover critical aspects like permissions required, whether the operation is idempotent, error handling (e.g., if the table already exists), or side effects. This leaves significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, direct sentence with zero wasted words, making it highly efficient and front-loaded. It immediately conveys the core purpose without unnecessary elaboration, which is ideal for conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with 3 parameters, no annotations, and no output schema, the description is insufficient. It lacks details on behavior, error cases, dependencies (e.g., connection state), and doesn't explain what 'create' entails operationally (e.g., atomicity, rollback). This leaves the agent poorly equipped to use the tool effectively in complex scenarios.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is low at 33%, with only the 'table' parameter having a description. The tool description doesn't add any parameter details beyond the schema, failing to compensate for the coverage gap. However, the schema itself provides clear structure for 'fields' and 'indexes', so a baseline score of 3 is appropriate given the schema's clarity despite missing descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('create') and resource ('new table in the database'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'add_column' or 'execute', which could also involve table creation operations, so it doesn't reach the highest score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'execute' (which might create tables via SQL) or 'add_column' (which modifies existing tables). There's no mention of prerequisites, such as needing an established database connection via 'connect_db', leaving the agent without contextual usage cues.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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

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