Skip to main content
Glama

create_index

Create an index on specific columns in an MSSQL Database table to enhance query performance and enforce unique constraints, if needed. Specify schema, table, index name, and columns for precise indexing.

Instructions

Creates an index on a specified column or columns in an MSSQL Database table

Input Schema

NameRequiredDescriptionDefault
columnsYesArray of column names to include in the index
indexNameYesName for the new index
isClusteredNoWhether the index should be clustered (default: false)
isUniqueNoWhether the index should enforce uniqueness (default: false)
schemaNameNoName of the schema containing the table
tableNameYesName of the table to create index on

Input Schema (JSON Schema)

{ "properties": { "columns": { "description": "Array of column names to include in the index", "items": { "type": "string" }, "type": "array" }, "indexName": { "description": "Name for the new index", "type": "string" }, "isClustered": { "default": false, "description": "Whether the index should be clustered (default: false)", "type": "boolean" }, "isUnique": { "default": false, "description": "Whether the index should enforce uniqueness (default: false)", "type": "boolean" }, "schemaName": { "description": "Name of the schema containing the table", "type": "string" }, "tableName": { "description": "Name of the table to create index on", "type": "string" } }, "required": [ "tableName", "indexName", "columns" ], "type": "object" }

Implementation Reference

  • The run method that implements the core logic of the create_index tool, constructing and executing a CREATE INDEX SQL query using mssql.
    async run(params: any) { try { const { schemaName, tableName, indexName, columns, isUnique = false, isClustered = false } = params; let indexType = isClustered ? "CLUSTERED" : "NONCLUSTERED"; if (isUnique) { indexType = `UNIQUE ${indexType}`; } const columnNames = columns.join(", "); const request = new sql.Request(); const query = `CREATE ${indexType} INDEX ${indexName} ON ${schemaName}.${tableName} (${columnNames})`; await request.query(query); return { success: true, message: `Index [${indexName}] created successfully on table [${schemaName}.${tableName}]`, details: { schemaName, tableName, indexName, columnNames, isUnique, isClustered } }; } catch (error) { console.error("Error creating index:", error); return { success: false, message: `Failed to create index: ${error}`, }; } }
  • Defines the input schema/validation for the create_index tool parameters.
    inputSchema = { type: "object", properties: { schemaName: { type: "string", description: "Name of the schema containing the table" }, tableName: { type: "string", description: "Name of the table to create index on" }, indexName: { type: "string", description: "Name for the new index" }, columns: { type: "array", items: { type: "string" }, description: "Array of column names to include in the index" }, isUnique: { type: "boolean", description: "Whether the index should enforce uniqueness (default: false)", default: false }, isClustered: { type: "boolean", description: "Whether the index should be clustered (default: false)", default: false }, }, required: ["tableName", "indexName", "columns"], } as any;
  • src/index.ts:109-113 (registration)
    Registers createIndexTool in the list returned by ListToolsRequestSchema handler (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:132-134 (registration)
    Registers handling of create_index tool calls in the switch statement of CallToolRequestSchema handler.
    case createIndexTool.name: result = await createIndexTool.run(args); break;
  • src/index.ts:87-87 (registration)
    Instantiates the CreateIndexTool instance referenced in registrations.
    const createIndexTool = new CreateIndexTool();

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