Skip to main content
Glama

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
NameRequiredDescriptionDefault
queryYesThe SQL CREATE TABLE query to execute.

Implementation Reference

  • 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; } }
  • 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'], }, },
  • 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);

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