Skip to main content
Glama
yaoxiaolinglong

MCP-MongoDB-MySQL-Server

create_table

Create a new database table by defining table name, field specifications, and optional indexes for structured data storage.

Instructions

Create a new table in the database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableYesTable name
fieldsYes
indexesNo

Implementation Reference

  • The main handler function for the 'create_table' tool. It constructs a CREATE TABLE SQL statement using the provided table name, fields (with type, length, nullable, default, autoIncrement, primary), and optional indexes, then executes the query on the MySQL connection.
    private async handleCreateTable(args: any) {
      await this.ensureConnection();
    
      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      ')}
      )`;
    
      try {
        await this.connection!.query(sql);
        return {
          content: [
            {
              type: 'text',
              text: `Table ${args.table} created successfully`
            }
          ]
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to create table: ${getErrorMessage(error)}`
        );
      }
    }
  • Input schema definition for the 'create_table' tool, specifying the structure for table name, fields array (each with name, type, optional length, nullable, default, autoIncrement, primary), and optional indexes array (with name, columns, unique).
    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:324-372 (registration)
    Tool registration in the ListToolsRequestSchema handler, defining the 'create_table' tool with its name, description, and inputSchema.
    {
      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:547-548 (registration)
    Dispatch case in the CallToolRequestSchema handler that routes 'create_table' tool calls to the handleCreateTable method.
    case 'create_table':
      return await this.handleCreateTable(request.params.arguments);
  • TypeScript interface defining the structure of a schema field used in the create_table tool handler.
    interface SchemaField {
      name: string;
      type: string;
      length?: number;
      nullable?: boolean;
      default?: string | number | null;
      autoIncrement?: boolean;
      primary?: boolean;
    }
  • TypeScript interface defining the structure of an index used in the create_table tool handler.
    interface IndexDefinition {
      name: string;
      columns: string[];
      unique?: boolean;
    }
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 a new table' which implies a write/mutation operation, but doesn't mention permissions required, whether the operation is idempotent, error handling, or what happens on success/failure. For a tool that modifies database structure, this lack of detail is a significant gap in transparency.

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, clear sentence that gets straight to the point with zero wasted words. It's appropriately sized for a basic tool description and front-loads the essential information. Every word earns its place by communicating the core functionality without unnecessary elaboration.

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 database mutation tool with 3 parameters, no annotations, no output schema, and only 33% schema description coverage, the description is incomplete. It doesn't address behavioral aspects like permissions or side effects, provides minimal parameter guidance, and offers no context about the database system or constraints. The agent would need to guess about many important usage aspects.

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

Parameters2/5

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

Schema description coverage is only 33% (only the 'table' parameter has a description), leaving most parameters undocumented. The description adds no parameter semantics beyond what's implied by the tool name - it doesn't explain what 'fields', 'indexes', or their sub-properties mean, nor provide examples or constraints. With 3 parameters and poor schema coverage, the description fails to compensate adequately.

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. It distinguishes this tool from siblings like 'add_column' or 'describe_table' by focusing on table creation rather than modification or inspection. However, it doesn't specify what kind of database or table characteristics, leaving some ambiguity.

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. It doesn't mention prerequisites (e.g., needing an established database connection via 'connect_db'), nor does it differentiate from similar tools like 'mongodb_create_collection' for MongoDB-specific operations. Without context, an agent might struggle to choose between this and sibling tools.

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

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

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