Skip to main content
Glama

create_table

Generate a new table in MSSQL databases by defining table name and column specifications. Supports precise SQL data types and constraints for structured data storage.

Instructions

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

Input Schema

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

Input Schema (JSON Schema)

{ "properties": { "columns": { "description": "Array of column definitions (e.g., [{ name: 'id', type: 'INT PRIMARY KEY' }, ...])", "items": { "properties": { "name": { "description": "Column name", "type": "string" }, "type": { "description": "SQL type and constraints (e.g., 'INT PRIMARY KEY', 'NVARCHAR(255) NOT NULL')", "type": "string" } }, "required": [ "name", "type" ], "type": "object" }, "type": "array" }, "tableName": { "description": "Name of the table to create", "type": "string" } }, "required": [ "tableName", "columns" ], "type": "object" }

Implementation Reference

  • The `run` method that implements the core logic of the `create_table` tool: parses input parameters, constructs a CREATE TABLE SQL query, executes it using the MSSQL library, and returns success or 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}` }; } } }
  • The `inputSchema` property defining the expected input structure for the `create_table` tool, including `tableName` (string) and `columns` (array of objects with `name` and `type`).
    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)
    In the `ListToolsRequestSchema` handler, the `createTableTool` instance is included in the list of available tools returned to MCP clients (unless in read-only 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)
    In the `CallToolRequestSchema` handler's switch statement, the case for `createTableTool.name` dispatches execution to `createTableTool.run(args)`.
    case createTableTool.name: result = await createTableTool.run(args);
  • src/index.ts:86-86 (registration)
    Instantiation of the `CreateTableTool` class as the `createTableTool` instance used throughout the server.
    const createTableTool = new CreateTableTool();

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

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