Skip to main content
Glama

MSSQL MCP Server

by Nirmal123K
CreateIndexTool.ts2.15 kB
import sql from "mssql"; import { Tool } from "@modelcontextprotocol/sdk/types.js"; export class CreateIndexTool implements Tool { [key: string]: any; name = "create_index"; description = "Creates an index on a specified column or columns in an MSSQL Database table"; 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; 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}`, }; } } }

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/Nirmal123K/mssql-mcp'

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