Skip to main content
Glama

MCP-MongoDB-MySQL-Server

create_table

Generate a new table in MySQL or MongoDB databases by defining table name, fields, and indexes using the MCP server's standardized interface.

Instructions

Create a new table in the database

Input Schema

NameRequiredDescriptionDefault
fieldsYes
indexesNo
tableYesTable name

Input Schema (JSON Schema)

{ "properties": { "fields": { "items": { "properties": { "autoIncrement": { "optional": true, "type": "boolean" }, "default": { "optional": true, "type": [ "string", "number", "null" ] }, "length": { "optional": true, "type": "number" }, "name": { "type": "string" }, "nullable": { "optional": true, "type": "boolean" }, "primary": { "optional": true, "type": "boolean" }, "type": { "type": "string" } }, "required": [ "name", "type" ], "type": "object" }, "type": "array" }, "indexes": { "items": { "properties": { "columns": { "items": { "type": "string" }, "type": "array" }, "name": { "type": "string" }, "unique": { "optional": true, "type": "boolean" } }, "required": [ "name", "columns" ], "type": "object" }, "optional": true, "type": "array" }, "table": { "description": "Table name", "type": "string" } }, "required": [ "table", "fields" ], "type": "object" }

Implementation Reference

  • The handler function that executes the create_table tool logic. Constructs and executes the CREATE TABLE SQL statement based on provided table name, fields, and optional indexes.
    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)}` ); } }
  • src/index.ts:324-372 (registration)
    Registration of the create_table tool in the tools list returned by ListToolsRequestSchema, including description and input schema definition.
    { 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'] } },
  • TypeScript interface defining the structure of a table field used in the create_table tool input schema.
    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 input schema.
    interface IndexDefinition { name: string; columns: string[]; unique?: boolean; }
  • src/index.ts:547-548 (registration)
    Dispatch case in the CallToolRequestSchema handler that routes create_table calls to the handleCreateTable method.
    case 'create_table': return await this.handleCreateTable(request.params.arguments);

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

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