create_table
Execute SQL CREATE TABLE queries to define new database tables in MySQL, enabling structured data storage and organization.
Instructions
Creates a new table in the MySQL database.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The SQL CREATE TABLE query to execute. |
Implementation Reference
- src/index.ts:258-308 (handler)The handler function for the 'create_table' tool. Validates input, checks if it's a CREATE TABLE query, executes it on the MySQL pool, and returns success or error response.private async handleCreateTable(request: any, transactionId: string) { if (!isValidSqlQueryArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid SQL query arguments.' ); } const query = request.params.arguments.query; if (!isCreateTableQuery(query)) { throw new McpError( ErrorCode.InvalidParams, 'Only CREATE TABLE queries are allowed with create_table tool.' ); } console.error(`[${transactionId}] Executing CREATE TABLE query: ${query}`); try { const [result] = await this.pool.query(query); console.error(`[${transactionId}] Table created successfully`); return { content: [ { type: 'text', text: JSON.stringify({ success: true, message: 'Table created successfully', result }, null, 2), }, ], }; } catch (error) { console.error(`[${transactionId}] Query error:`, error); if (error instanceof Error) { return { content: [ { type: 'text', text: `MySQL error: ${error.message}`, }, ], isError: true, }; } throw error; } }
- src/index.ts:111-120 (schema)Input schema for the 'create_table' tool, defining the expected 'query' parameter.inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'The SQL CREATE TABLE query to execute.', }, }, required: ['query'], },
- src/index.ts:108-121 (registration)Registration of the 'create_table' tool in the ListTools response, including name, description, and schema.{ name: 'create_table', description: 'Creates a new table in the MySQL database.', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'The SQL CREATE TABLE query to execute.', }, }, required: ['query'], }, },
- src/index.ts:34-35 (helper)Helper function used to validate if the provided query starts with 'CREATE TABLE'.const isCreateTableQuery = (query: string): boolean => query.trim().toLowerCase().startsWith('create table');
- src/index.ts:189-190 (registration)Switch case in CallToolRequestHandler that routes 'create_table' calls to the handler function.case 'create_table': return this.handleCreateTable(request, transactionId);