](https://mseep.ai/app/jjikky-dynamo-readonly-mcp)
DynamoDB只读MCP
](https://badge.fury.io/js/dynamo-readonly-mcp) ](https://smithery.ai/server/@jjikky/dynamo-readonly-mcp)
利用模型上下文协议(MCP)查询AWS DynamoDB数据库的服务器。该服务器允许像Claude这样的LLM通过自然语言请求查询DynamoDB数据。
特性
此MCP服务器提供以下功能:
- 表管理工具:
- list-tables:查看所有DynamoDB表的列表 - describe-table:查看特定表的详细信息
- 数据查询工具:
- scan-table:扫描表的全部或部分数据 - query-table:在表中搜索符合特定条件的数据 - paginate-query-table:跨多个页面检索符合特定条件的数据 - get-item:使用特定密钥检索项目 - count-items:计算表中的项目数
- 资源:
- dynamodb-tables-info:为所有表提供元数据的资源 - dynamodb-table-schema:为特定表提供架构信息的资源
- 提示:
- dynamodb-query-help:编写DynamoDB查询的帮助提示
安装和执行
您可以使用 Run with NPX 方法如下。
通过Smithery安装
通过以下方式自动安装用于Claude Desktop的DynamoDB只读服务器 史密瑟里:
npx -y @smithery/cli install @jjikky/dynamo-readonly-mcp --client claude安装
- 克隆存储库:
git clone https://github.com/jjikky/dynamo-readonly-mcp.git
cd dynamo-readonly-mcp- 安装所需的软件包:
npm install- 创建一个
.env文件并设置您的AWS凭据:
AWS_ACCESS_KEY_ID=your_access_key
AWS_SECRET_ACCESS_KEY=your_secret_key
AWS_REGION=your_region构建并运行
npm run build
npm start连接到克劳德桌面
要将此MCP服务器与Claude Desktop一起使用,您需要修改Claude Desktop配置文件。
- 打开Claude Desktop配置文件:
- macOS: ~/Library/Application Support/Claude/claude_desktop_config.json - 窗户: %APPDATA%\Claude\claude_desktop_config.json
- 添加服务器配置如下:
{
"mcpServers": {
"dynamodb-readonly": {
"command": "node",
"args": ["/absolute-path/dynamo-readonly-mcp/dist/index.js"],
"env": {
"AWS_ACCESS_KEY_ID": "your_access_key",
"AWS_SECRET_ACCESS_KEY": "your_secret_key",
"AWS_REGION": "your_region"
}
}
}
}- 重新启动克劳德桌面。
使用NPX运行
您还可以使用以下命令运行此服务器 npx 无需全局安装:
{
"mcpServers": {
"dynamodb-readonly": {
"command": "npx",
"args": ["-y", "dynamo-readonly-mcp"],
"env": {
"AWS_ACCESS_KEY_ID": "your_access_key",
"AWS_SECRET_ACCESS_KEY": "your_secret_key",
"AWS_REGION": "your_region"
}
}
}
}使用示例
你可以问克劳德这样的问题:
- “你能告诉我DynamoDB中有哪些表吗?”
- “解释Users表的结构”
- 在“users”表中查找groupId为“0lxp4paxk7”的用户数
______________________________________________________________________
建筑
此MCP服务器由以下分层结构组成:
- 客户端界面(克劳德桌面) -用户与LLM之间的交互
- MCP协议层 -提供标准化的消息交换方法
- DynamoDB服务器 -实现与DynamoDB交互的函数
- AWS SDK -与AWS DynamoDB服务通信
关键运行机制
1.初始化和连接
服务器启动时,会发生以下过程:
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
console.error('DynamoDB read-only MCP server is running...');
}StdioServerTransport通过标准输入/输出建立通信信道。server.connect(transport)通过MCP协议连接到克劳德桌面。- 在连接期间,服务器向客户端发送有关支持的工具、资源和提示的信息。
2.工具请求处理
当用户问Claude“显示DynamoDB表列表”这样的问题时:
- Claude分析了这个请求并调用
list-tables工具。 - 此请求通过MCP协议发送到服务器。
- 服务器执行相应的工具处理程序:
server.tool('list-tables', 'Gets a list of all DynamoDB tables', {}, async () => {
try {
const tables = await listTables();
return {
content: [{ type: 'text', text: JSON.stringify(tables, null, 2) }],
};
} catch (error) {
return { isError: true, content: [{ type: 'text', text: `Error: ${error.message}` }] };
}
});- 结果通过MCP协议返回给Claude。
- Claude将这个结果处理成自然语言并呈现给用户。
3.具体参数处理
当用户请求“告诉我Users表的结构”时:
- Claude确定此请求应使用
describe-table工具。 - Claude将参数配置为
{ tableName: "Users" }. - 此信息将发送到MCP服务器:
server.tool(
'describe-table',
'Gets detailed information about a DynamoDB table',
{
tableName: z.string().describe('Name of the table to get detailed information for'),
},
async ({ tableName }) => {
// Query table information using the tableName parameter
const tableInfo = await describeTable(tableName);
// Return results
}
);在这里, z.string() 使用Zod库来验证参数。
4.资源处理
资源是另一个提供只读数据的MCP功能:
server.resource('dynamodb-tables-info', 'DynamoDB table information', async () => {
// Create and return resource data
const tables = await listTables();
const tablesInfo = await Promise.all(/* Query table information */);
return {
contents: [
{
uri: 'dynamodb://tables-info',
text: JSON.stringify(tablesInfo, null, 2),
mimeType: 'application/json',
},
],
};
});Claude访问资源并将其用作上下文信息。
5.及时处理
MCP服务器可以为特定任务提供提示模板:
server.prompt(
'dynamodb-query-help',
'A prompt that helps write DynamoDB queries',
{
tableName: z.string().describe('Table name to query'),
queryType: z.enum(['basic', 'advanced']).default('basic'),
},
async ({ tableName, queryType }) => {
// Generate prompt content
return {
messages: [
{
role: 'user',
content: { type: 'text', text: helpContent },
},
],
};
}
);当用户请求“显示如何为Users表编写查询”时,会使用此提示
数据流摘要
- 用户用自然语言向Claude发出请求
- Claude分析请求并选择适当的MCP工具/资源/提示
- MCP客户端以标准化格式向服务器发送请求
- 服务器处理请求并调用AWS DynamoDB API
- DynamoDB返回结果
- 服务器将结果转换为MCP格式并将其发送到客户端
- Claude将结果处理成自然语言并呈现给用户
许可证
此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。

