Skip to main content
Glama

create_table

Execute SQL CREATE TABLE queries to establish new tables in a MySQL database, enabling structured data storage and management for efficient operations.

Instructions

Creates a new table in the MySQL database.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe SQL CREATE TABLE query to execute.

Implementation Reference

  • The handler function that validates the input, checks if it's a CREATE TABLE query, executes it on the MySQL database, and returns a formatted response with success or error details.
    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; } }
  • The input schema for the create_table tool, defining the expected 'query' parameter as a string for the CREATE TABLE SQL statement.
    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:189-190 (registration)
    The switch case that registers and routes calls to the create_table tool to its handler function.
    case 'create_table': return this.handleCreateTable(request, transactionId);
  • Helper function used by the handler to validate that the provided query starts with 'CREATE TABLE'.
    const isCreateTableQuery = (query: string): boolean => query.trim().toLowerCase().startsWith('create table');
  • Helper function used by the handler to validate that the arguments contain a 'query' string.
    const isValidSqlQueryArgs = (args: any): args is SqlQueryArgs => typeof args === 'object' && args !== null && typeof args.query === 'string';

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

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