数据库MCP服务器设置指南
本指南解释了如何为各种AWS数据库服务设置模型上下文协议(MCP)服务器,以与Amazon Bedrock模型一起使用。
支持的数据库
- 亚马逊RDS MySQL:SQL数据库服务
- 亚马逊文档数据库:MongoDB兼容文档数据库
- 亚马逊DynamoDB:NoSQL键值和文档数据库
- 亚马逊红移:数据仓库服务
- 亚马逊ElastiCache Redis:内存数据存储
先决条件
在设置MCP服务器之前,请确保:
- 访问AWS服务和适当权限
- 已创建并可访问的数据库实例
- 已安装Node.js和npm
- Python 3已安装
- Git已安装
- 已安装Docker(可选,适用于容器化MCP服务器)
您可以通过以下方式检查并安装必备组件:
chmod +x check_prerequisites.sh
./check_prerequisites.sh设置过程
1.配置数据库凭据
使用数据库连接信息创建凭据文件:
cp db_credentials_template.sh set_db_credentials.sh编辑 set_db_credentials.sh 并填写您的实际数据库凭据。
2.验证数据库连接
在设置MCP服务器之前,请验证您的数据库连接是否正常工作:
chmod +x validate_db_connections.sh
source ./set_db_credentials.sh
./validate_db_connections.sh此脚本将测试与所有已配置数据库的连接,并报告任何问题。
3.设置MCP服务器
运行安全安装脚本以安装和配置所有数据库MCP服务器:
chmod +x setup_db_mcp_servers_secure.sh
./setup_db_mcp_servers_secure.sh此脚本将:
- 克隆必要的存储库
- 构建所需组件
- 更新MCP配置
- 重新启动MCP服务
4.测试MCP服务器
设置后,测试所有MCP服务器是否正常工作:
chmod +x test_mcp_servers.sh
./test_mcp_servers.sh使用示例
设置好MCP服务器后,您可以通过MCP框架将其与Amazon Bedrock模型一起使用。以下是一些示例提示:
MySQL
Show me all tables in the MySQL database.
Run a query to select the first 10 rows from the customers table.
What are the column names and data types in the orders table?MongoDB/文档数据库
List all collections in the MongoDB database.
Find documents in the users collection where age is greater than 30.
Show me the schema of the products collection.DynamoDB
List all tables in DynamoDB.
Get items from the Orders table where CustomerId equals 'CUST001'.
What are the primary key attributes for the Products table?红移
Show me all tables in the Redshift database.
Run a query to analyze sales data by region.
Explain the schema of the customer_transactions table.瑞迪斯
Get all keys in Redis.
What is the value of the key 'session:user123'?
Show me all members of the set 'active_users'.安全考虑
- 从不将凭据提交到版本控制
- 考虑使用AWS Secrets Manager或参数存储进行凭据管理
- 尽可能使用IAM角色而不是访问密钥
- 为数据库用户实现最低权限访问
- 在MCP服务器配置中设置适当的读/写权限
故障排除
如果您遇到问题:
- 检查日志
logs目录 - 使用验证脚本验证数据库连接
- 确保设置了所有必需的环境变量
- 检查MCP服务是否正在运行(
http://127.0.0.1:7002) - 验证聊天机器人UI是否可访问(
http://localhost:8502)
