DynamoDB操作服务器

一个基于FastMCP的AWS DynamoDB操作模型上下文协议(MCP)服务器,提供表管理、项目操作、查询扫描和索引管理功能。

  • by vigneshkumarravisankar
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 vigneshkumarravisankar/custom-dynamodb-mcp-python

使用说明

DynamoDB MCP服务器

使用FastMCP进行AWS DynamoDB操作的模型上下文协议(MCP)服务器。

设置

  1. 创建虚拟环境:
python -m venv venv
venv\Scripts\activate  # Windows
  1. 安装依赖项:
pip install -r requirements.txt
  1. 设置环境变量:
set AWS_ACCESS_KEY_ID=your_access_key
set AWS_SECRET_ACCESS_KEY=your_secret_key
set AWS_REGION=your_region

示例用法

创建表

create_table(
    tableName="users",
    partitionKey="userId", 
    partitionKeyType="S",
    sortKey="timestamp",
    sortKeyType="N",
    readCapacity=5,
    writeCapacity=5
)

放置物品

put_item(
    tableName="users",
    item={"userId": "123", "name": "John", "age": 30}
)

查询表

query_table(
    tableName="users",
    keyConditionExpression="userId = :uid",
    expressionAttributeValues={":uid": "123"}
)

运行服务器

python server.py

可用工具

表格管理

  • list_tables(limit, exclusiveStartTableName) -列出所有DynamoDB表
  • describe_table(tableName) -获取详细的表格信息
  • create_table(tableName, partitionKey, partitionKeyType, sortKey, sortKeyType, readCapacity, writeCapacity) -创建表格
  • update_capacity(tableName, readCapacity, writeCapacity) -更新表容量

项目操作

  • put_item(tableName, item) -插入/替换项目
  • get_item(tableName, key) -按关键字检索项目
  • update_item(tableName, key, updateExpression, expressionAttributeNames, expressionAttributeValues, conditionExpression, returnValues) -更新项目

查询和扫描

  • scan_table(tableName, filterExpression, expressionAttributeValues, expressionAttributeNames, limit) -扫描表
  • query_table(tableName, keyConditionExpression, expressionAttributeValues, expressionAttributeNames, filterExpression, limit) -查询表

索引管理

  • create_gsi(tableName, indexName, partitionKey, partitionKeyType, sortKey, sortKeyType, projectionType, nonKeyAttributes, readCapacity, writeCapacity) -创建全球二级指数
  • update_gsi(tableName, indexName, readCapacity, writeCapacity) -更新GSI容量
  • create_lsi(tableName, indexName, partitionKey, partitionKeyType, sortKey, sortKeyType, projectionType, nonKeyAttributes) -创建本地二级索引(仅用于创建表)