Skip to main content
Glama

create_table

Create new tables in Microsoft SQL Server databases by defining column names, data types, and constraints for structured data storage.

Instructions

Creates a new table in the MSSQL Database with the specified columns.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableNameYesName of the table to create
columnsYesArray of column definitions (e.g., [{ name: 'id', type: 'INT PRIMARY KEY' }, ...])

Implementation Reference

  • The main execution logic for the create_table tool: validates input, builds SQL CREATE TABLE query from columns, executes it via mssql, returns success/error response.
    async run(params: any) { try { const { tableName, columns } = params; if (!Array.isArray(columns) || columns.length === 0) { throw new Error("'columns' must be a non-empty array"); } const columnDefs = columns.map((col: any) => `[${col.name}] ${col.type}`).join(", "); const query = `CREATE TABLE [${tableName}] (${columnDefs})`; await new sql.Request().query(query); return { success: true, message: `Table '${tableName}' created successfully.` }; } catch (error) { console.error("Error creating table:", error); return { success: false, message: `Failed to create table: ${error}` }; } } }
  • JSON schema defining input parameters: tableName (string) and columns (array of {name, type} objects).
    inputSchema = { type: "object", properties: { tableName: { type: "string", description: "Name of the table to create" }, columns: { type: "array", description: "Array of column definitions (e.g., [{ name: 'id', type: 'INT PRIMARY KEY' }, ...])", items: { type: "object", properties: { name: { type: "string", description: "Column name" }, type: { type: "string", description: "SQL type and constraints (e.g., 'INT PRIMARY KEY', 'NVARCHAR(255) NOT NULL')" } }, required: ["name", "type"] } } }, required: ["tableName", "columns"], } as any;
  • src/index.ts:109-113 (registration)
    Registers createTableTool instance in the list of available tools for ListToolsRequest (non-readonly mode).
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: isReadOnly ? [listTableTool, readDataTool, describeTableTool] // todo: add searchDataTool to the list of tools available in readonly mode once implemented : [insertDataTool, readDataTool, describeTableTool, updateDataTool, createTableTool, createIndexTool, dropTableTool, listTableTool], // add all new tools here }));
  • src/index.ts:129-130 (registration)
    Switch case in CallToolRequestHandler that invokes createTableTool.run() when 'create_table' is called.
    case createTableTool.name: result = await createTableTool.run(args);
  • src/index.ts:86-86 (registration)
    Instantiation of the CreateTableTool class for use in the MCP server.
    const createTableTool = new CreateTableTool();

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/EvilPhatBoi/McpSqlServer'

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