Skip to main content
Glama
imankamyabi

DynamoDB MCP Server

by imankamyabi

create_gsi

Add a global secondary index to a DynamoDB table by specifying the index name, partition key, projection type, and read/write capacities for optimized query performance.

Instructions

Creates a global secondary index on a table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexNameYesName of the new index
nonKeyAttributesNoNon-key attributes to project (optional)
partitionKeyYesPartition key for the index
partitionKeyTypeYesType of partition key
projectionTypeYesType of projection
readCapacityYesProvisioned read capacity units
sortKeyNoSort key for the index (optional)
sortKeyTypeNoType of sort key (optional)
tableNameYesName of the table
writeCapacityYesProvisioned write capacity units

Implementation Reference

  • The handler function that implements the core logic of the 'create_gsi' tool by constructing and sending an UpdateTableCommand to DynamoDB to create a Global Secondary Index.
    async function createGSI(params: any) { try { const command = new UpdateTableCommand({ TableName: params.tableName, AttributeDefinitions: [ { AttributeName: params.partitionKey, AttributeType: params.partitionKeyType }, ...(params.sortKey ? [{ AttributeName: params.sortKey, AttributeType: params.sortKeyType }] : []), ], GlobalSecondaryIndexUpdates: [ { Create: { IndexName: params.indexName, KeySchema: [ { AttributeName: params.partitionKey, KeyType: "HASH" as const }, ...(params.sortKey ? [{ AttributeName: params.sortKey, KeyType: "RANGE" as const }] : []), ], Projection: { ProjectionType: params.projectionType, ...(params.projectionType === "INCLUDE" ? { NonKeyAttributes: params.nonKeyAttributes } : {}), }, ProvisionedThroughput: { ReadCapacityUnits: params.readCapacity, WriteCapacityUnits: params.writeCapacity, }, }, }, ], }); const response = await dynamoClient.send(command); return { success: true, message: `GSI ${params.indexName} creation initiated on table ${params.tableName}`, details: response.TableDescription, }; } catch (error) { console.error("Error creating GSI:", error); return { success: false, message: `Failed to create GSI: ${error}`, }; } }
  • The tool object definition for 'create_gsi', including name, description, and detailed inputSchema for parameter validation.
    const CREATE_GSI_TOOL: Tool = { name: "create_gsi", description: "Creates a global secondary index on a table", inputSchema: { type: "object", properties: { tableName: { type: "string", description: "Name of the table" }, indexName: { type: "string", description: "Name of the new index" }, partitionKey: { type: "string", description: "Partition key for the index" }, partitionKeyType: { type: "string", enum: ["S", "N", "B"], description: "Type of partition key" }, sortKey: { type: "string", description: "Sort key for the index (optional)" }, sortKeyType: { type: "string", enum: ["S", "N", "B"], description: "Type of sort key (optional)" }, projectionType: { type: "string", enum: ["ALL", "KEYS_ONLY", "INCLUDE"], description: "Type of projection" }, nonKeyAttributes: { type: "array", items: { type: "string" }, description: "Non-key attributes to project (optional)" }, readCapacity: { type: "number", description: "Provisioned read capacity units" }, writeCapacity: { type: "number", description: "Provisioned write capacity units" }, }, required: ["tableName", "indexName", "partitionKey", "partitionKeyType", "projectionType", "readCapacity", "writeCapacity"], }, };
  • src/index.ts:598-600 (registration)
    Registers the CREATE_GSI_TOOL in the list of available tools served by the MCP server in response to ListToolsRequest.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [CREATE_TABLE_TOOL, UPDATE_CAPACITY_TOOL, PUT_ITEM_TOOL, GET_ITEM_TOOL, QUERY_TABLE_TOOL, SCAN_TABLE_TOOL, DESCRIBE_TABLE_TOOL, LIST_TABLES_TOOL, CREATE_GSI_TOOL, UPDATE_GSI_TOOL, CREATE_LSI_TOOL, UPDATE_ITEM_TOOL], }));
  • src/index.ts:614-616 (registration)
    Dispatch/registration case in the CallToolRequestHandler switch statement that invokes the createGSI handler for the 'create_gsi' tool.
    case "create_gsi": result = await createGSI(args); break;

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/imankamyabi/dynamodb-mcp-server'

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