Skip to main content
Glama
imankamyabi

DynamoDB MCP Server

by imankamyabi

create_lsi

Enables creation of a local secondary index during DynamoDB table setup, specifying keys, types, projection, and capacity units for efficient data querying.

Instructions

Creates a local secondary index on a table (must be done during table creation)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexNameYesName of the new index
nonKeyAttributesNoNon-key attributes to project (optional)
partitionKeyYesPartition key for the table
partitionKeyTypeYesType of partition key
projectionTypeYesType of projection
readCapacityNoProvisioned read capacity units (optional, default: 5)
sortKeyYesSort key for the index
sortKeyTypeYesType of sort key
tableNameYesName of the table
writeCapacityNoProvisioned write capacity units (optional, default: 5)

Implementation Reference

  • The handler function createLSI that executes the tool logic: creates a DynamoDB table with a local secondary index (LSI) using CreateTableCommand, since LSIs must be defined at table creation time.
    async function createLSI(params: any) {
      try {
        // Note: LSIs must be created during table creation, so we need the table's primary key info
        const command = new CreateTableCommand({
          TableName: params.tableName,
          AttributeDefinitions: [
            { AttributeName: params.partitionKey, AttributeType: params.partitionKeyType },
            { AttributeName: params.sortKey, AttributeType: params.sortKeyType },
          ],
          KeySchema: [
            { AttributeName: params.partitionKey, KeyType: "HASH" as const },
          ],
          LocalSecondaryIndexes: [
            {
              IndexName: params.indexName,
              KeySchema: [
                { AttributeName: params.partitionKey, KeyType: "HASH" as const },
                { AttributeName: params.sortKey, KeyType: "RANGE" as const },
              ],
              Projection: {
                ProjectionType: params.projectionType,
                ...(params.projectionType === "INCLUDE" ? { NonKeyAttributes: params.nonKeyAttributes } : {}),
              },
            },
          ],
          ProvisionedThroughput: {
            ReadCapacityUnits: params.readCapacity || 5,
            WriteCapacityUnits: params.writeCapacity || 5,
          },
        });
        
        const response = await dynamoClient.send(command);
        return {
          success: true,
          message: `LSI ${params.indexName} created on table ${params.tableName}`,
          details: response.TableDescription,
        };
      } catch (error) {
        console.error("Error creating LSI:", error);
        return {
          success: false,
          message: `Failed to create LSI: ${error}`,
        };
      }
    }
  • Tool definition including name, description, and input schema for validating parameters like tableName, indexName, keys, projection, etc.
    const CREATE_LSI_TOOL: Tool = {
      name: "create_lsi",
      description: "Creates a local secondary index on a table (must be done during table creation)",
      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 table" },
          partitionKeyType: { type: "string", enum: ["S", "N", "B"], description: "Type of partition key" },
          sortKey: { type: "string", description: "Sort key for the index" },
          sortKeyType: { type: "string", enum: ["S", "N", "B"], description: "Type of sort key" },
          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 (optional, default: 5)" },
          writeCapacity: { type: "number", description: "Provisioned write capacity units (optional, default: 5)" },
        },
        required: ["tableName", "indexName", "partitionKey", "partitionKeyType", "sortKey", "sortKeyType", "projectionType"],
      },
    };
  • src/index.ts:598-600 (registration)
    Registration of CREATE_LSI_TOOL in the list of available tools returned by ListToolsRequestSchema handler.
    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:620-622 (registration)
    Dispatch registration in the CallToolRequestSchema switch statement that maps 'create_lsi' to the createLSI handler.
    case "create_lsi":
      result = await createLSI(args);
      break;
Install Server

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