Skip to content

Commit f909354

Browse files
feat: postgres mcp kiro integration (#1910)
* initial change for postgres mcp kiro integration by supporting creating cluster and connect to any cluster * add support for direction connection and connection map unit test * cp_api_connection unit test * add support for UFC. add support for connect to any database through prompt * support get connection information and fix get_table_schema bug * remove delete cluster options * fix policy attachment * fix Kiro integration issue * allow connection to RPG and make connection method and database type explicitly in MCP tool * support expiry for IAM auth tokens * remove outdated function * Fix and add unit tests * check for pgwire_iam conn in map * MCP steering file * remove UFC in this release * Fix pyright errors * fix ruff * sync uv.lock * Add license header to missing file * Add baseline secrets * Add more UT * Add more unit tests * Add tests * Fix pre-commit * support user agent in boto3 * update README.md * Kiro power * Fix tests * Accept pre-commit fixes * fix secrets * fix init.py * fix * fix * fix * Accept precommit * fix precommit --------- Co-authored-by: Sharu Goel <[email protected]> Co-authored-by: Sharu Goel <[email protected]>
1 parent 603ae19 commit f909354

28 files changed

+8254
-1186
lines changed

.secrets.baseline

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,80 @@
869869
"is_secret": false
870870
}
871871
],
872+
"src/postgres-mcp-server/kiro_power/steering/aurora-postgres.md": [
873+
{
874+
"type": "Secret Keyword",
875+
"filename": "src/postgres-mcp-server/kiro_power/steering/aurora-postgres.md",
876+
"hashed_secret": "91dfd9ddb4198affc5c194cd8ce6d338fde470e2",
877+
"is_verified": false,
878+
"line_number": 506,
879+
"is_secret": false
880+
}
881+
],
882+
"src/postgres-mcp-server/tests/test_cp_api_simple_functions.py": [
883+
{
884+
"type": "Secret Keyword",
885+
"filename": "src/postgres-mcp-server/tests/test_cp_api_simple_functions.py",
886+
"hashed_secret": "102b223470fdcb13103b4144fdd24975d9ef2387",
887+
"is_verified": false,
888+
"line_number": 52,
889+
"is_secret": false
890+
}
891+
],
892+
"src/postgres-mcp-server/tests/test_psycopg_connector.py": [
893+
{
894+
"type": "Secret Keyword",
895+
"filename": "src/postgres-mcp-server/tests/test_psycopg_connector.py",
896+
"hashed_secret": "72cb70dbbafe97e5ea13ad88acd65d08389439b0",
897+
"is_verified": false,
898+
"line_number": 422,
899+
"is_secret": false
900+
},
901+
{
902+
"type": "Secret Keyword",
903+
"filename": "src/postgres-mcp-server/tests/test_psycopg_connector.py",
904+
"hashed_secret": "9fb7fe1217aed442b04c0f5e43b5d5a7d3287097",
905+
"is_verified": false,
906+
"line_number": 500,
907+
"is_secret": false
908+
},
909+
{
910+
"type": "Secret Keyword",
911+
"filename": "src/postgres-mcp-server/tests/test_psycopg_connector.py",
912+
"hashed_secret": "f84864c6bffa2e0843a4ab2abdca91df7995c462",
913+
"is_verified": false,
914+
"line_number": 563,
915+
"is_secret": false
916+
},
917+
{
918+
"type": "Secret Keyword",
919+
"filename": "src/postgres-mcp-server/tests/test_psycopg_connector.py",
920+
"hashed_secret": "43b5a7ccc96b402d0fc814b5e03f8e23c2d9d1d8",
921+
"is_verified": false,
922+
"line_number": 891,
923+
"is_secret": false
924+
}
925+
],
926+
"src/postgres-mcp-server/tests/test_rds_api_connection.py": [
927+
{
928+
"type": "Secret Keyword",
929+
"filename": "src/postgres-mcp-server/tests/test_rds_api_connection.py",
930+
"hashed_secret": "102b223470fdcb13103b4144fdd24975d9ef2387",
931+
"is_verified": false,
932+
"line_number": 29,
933+
"is_secret": false
934+
}
935+
],
936+
"src/postgres-mcp-server/tests/test_server_internal_functions.py": [
937+
{
938+
"type": "Secret Keyword",
939+
"filename": "src/postgres-mcp-server/tests/test_server_internal_functions.py",
940+
"hashed_secret": "43b5a7ccc96b402d0fc814b5e03f8e23c2d9d1d8",
941+
"is_verified": false,
942+
"line_number": 120,
943+
"is_secret": false
944+
}
945+
],
872946
"src/stepfunctions-tool-mcp-server/README.md": [
873947
{
874948
"type": "Base64 High Entropy String",
@@ -906,5 +980,5 @@
906980
}
907981
]
908982
},
909-
"generated_at": "2025-12-01T14:26:01Z"
983+
"generated_at": "2025-12-10T01:04:18Z"
910984
}

src/postgres-mcp-server/README.md

Lines changed: 44 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ An AWS Labs Model Context Protocol (MCP) server for Aurora Postgres
1212

1313
1. Install `uv` from [Astral](https://docs.astral.sh/uv/getting-started/installation/) or the [GitHub README](https://github.com/astral-sh/uv#installation)
1414
2. Install Python using `uv python install 3.10`
15-
3. Aurora Postgres Cluster with Postgres username and password stored in AWS Secrets Manager
16-
4. Enable RDS Data API for your Aurora Postgres Cluster, see [instructions here](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html)
17-
5. This MCP server can only be run locally on the same host as your LLM client.
18-
6. Docker runtime
19-
7. Set up AWS credentials with access to AWS services
15+
3. This MCP server can only be run locally on the same host as your LLM client.
16+
4. Docker runtime
17+
5. Set up AWS credentials with access to AWS services
2018
- You need an AWS account with appropriate permissions
2119
- Configure AWS credentials with `aws configure` or environment variables
2220

@@ -28,20 +26,14 @@ An AWS Labs Model Context Protocol (MCP) server for Aurora Postgres
2826

2927
Configure the MCP server in your MCP client configuration (e.g., for Amazon Q Developer CLI, edit `~/.aws/amazonq/mcp.json`):
3028

31-
### Option 1: Using RDS Data API Connection (for Aurora Postgres)
32-
3329
```json
3430
{
3531
"mcpServers": {
3632
"awslabs.postgres-mcp-server": {
3733
"command": "uvx",
3834
"args": [
3935
"awslabs.postgres-mcp-server@latest",
40-
"--resource_arn", "[your data]",
41-
"--secret_arn", "[your data]",
42-
"--database", "[your data]",
43-
"--region", "[your data]",
44-
"--readonly", "True"
36+
"--allow_write_query"
4537
],
4638
"env": {
4739
"AWS_PROFILE": "your-aws-profile",
@@ -55,35 +47,6 @@ Configure the MCP server in your MCP client configuration (e.g., for Amazon Q De
5547
}
5648
```
5749

58-
### Option 2: Using Direct PostgreSQL(psycopg) Connection (for Aurora Postgres and RDS Postgres)
59-
60-
```json
61-
{
62-
"mcpServers": {
63-
"awslabs.postgres-mcp-server": {
64-
"command": "uvx",
65-
"args": [
66-
"awslabs.postgres-mcp-server@latest",
67-
"--hostname", "[your data]",
68-
"--secret_arn", "[your data]",
69-
"--database", "[your data]",
70-
"--region", "[your data]",
71-
"--readonly", "True"
72-
],
73-
"env": {
74-
"AWS_PROFILE": "your-aws-profile",
75-
"AWS_REGION": "us-east-1",
76-
"FASTMCP_LOG_LEVEL": "ERROR"
77-
},
78-
"disabled": false,
79-
"autoApprove": []
80-
}
81-
}
82-
}
83-
```
84-
85-
Note: The `--port` parameter is optional and defaults to 5432 (the standard PostgreSQL port). You only need to specify it if your PostgreSQL instance uses a non-standard port.
86-
8750
### Windows Installation
8851

8952
For Windows users, the MCP server configuration format is slightly different:
@@ -136,56 +99,61 @@ For Windows users, the MCP server configuration format is slightly different:
13699
"-e", "AWS_SECRET_ACCESS_KEY=[your data]",
137100
"-e", "AWS_REGION=[your data]",
138101
"awslabs/postgres-mcp-server:latest",
139-
"--resource_arn", "[your data]",
140-
"--secret_arn", "[your data]",
141-
"--database", "[your data]",
142-
"--region", "[your data]",
143-
"--readonly", "True"
102+
"--allow_write_query"
144103
]
145104
}
146105
}
147106
}
148107
```
149108

150-
#### Option 2: Using Direct PostgreSQL (psycopg) Connection (for Aurora Postgres and RDS Postgres)
109+
NOTE: the MCP config example include --allow_write_query illustrate how to enable write queries. If you want to disable write queries, remove --allow_write_query option.
151110

152-
```
153-
{
154-
"mcpServers": {
155-
"awslabs.postgres-mcp-server": {
156-
"command": "docker",
157-
"args": [
158-
"run",
159-
"-i",
160-
"--rm",
161-
"-e", "AWS_ACCESS_KEY_ID=[your data]",
162-
"-e", "AWS_SECRET_ACCESS_KEY=[your data]",
163-
"-e", "AWS_REGION=[your data]",
164-
"awslabs/postgres-mcp-server:latest",
165-
"--hostname", "[your data]",
166-
"--secret_arn", "[your data]",
167-
"--database", "[your data]",
168-
"--region", "[your data]",
169-
"--readonly", "True"
170-
]
171-
}
172-
}
173-
}
174-
```
111+
## Support for Database Cluster Creation
175112

176-
Note: The `--port` parameter is optional and defaults to 5432 (the standard PostgreSQL port). You only need to specify it if your PostgreSQL instance uses a non-standard port.
113+
You can use the following LLM prompt to create a new Aurora PostgreSQL cluster:
177114

178-
NOTE: By default, only read-only queries are allowed and it is controlled by --readonly parameter above. Set it to False if you also want to allow writable DML or DDL.
115+
> Create an Aurora PostgreSQL cluster named 'mycluster' in us-west-2 region
116+
117+
---
179118

180119
## Connection Methods
181120

182-
This MCP server supports two connection methods:
121+
The MCP server supports connecting to multiple database endpoints using different connection methods via LLM prompts.
122+
123+
### Database Types
124+
- **APG**: Amazon Aurora PostgreSQL
125+
- **RPG**: Amazon RDS for PostgreSQL
126+
127+
### Example Prompts
128+
129+
**Connect using RDS Data API:**
130+
> Connect to database named postgres in Aurora PostgreSQL cluster 'my-cluster' with database_type as APG, using rdsapi as connection method in us-west-2 region
131+
132+
**Connect using pgwire (Aurora PostgreSQL):**
133+
> Connect to database named postgres with database endpoint as my-apg17-instance-1.ctgfg6yyo9df.us-west-2.rds.amazonaws.com with database_type as APG, using pgwire as connection method in us-west-2 region
134+
135+
**Connect using pgwire (RDS PostgreSQL):**
136+
> Connect to database named postgres with database endpoint as test-apg17-instance-1.ctgfg6yyo9df.us-west-2.rds.amazonaws.com with database_type as RPG, using pgwire as connection method in us-west-2 region
137+
138+
---
139+
140+
### Supported Connection Methods
141+
142+
| Method | Description | Supported Database Types |
143+
|--------|-------------|--------------------------|
144+
| `pgwire` | Connect to PostgreSQL instance directly using the PostgreSQL wire protocol. Requires proper VPC security group configuration for direct database connectivity. | APG, RPG |
145+
| `pgwire_iam` | Same as `pgwire`, but uses IAM authentication. Requires IAM authentication to be enabled on the Aurora PostgreSQL cluster. | APG only |
146+
| `rdsapi` | Connect to Aurora PostgreSQL using the RDS Data API. Requires the RDS Data API to be enabled on the cluster. | APG only |
183147

184-
1. **RDS Data API Connection** (using `--resource_arn`): Uses the AWS RDS Data API to connect to Aurora PostgreSQL. This method requires that your Aurora cluster has the Data API enabled.
148+
### Prerequisites by Connection Method
185149

186-
2. **Direct PostgreSQL Connection** (using `--hostname`): Uses psycopg to connect directly to any PostgreSQL database, including Aurora PostgreSQL, RDS PostgreSQL, or self-hosted PostgreSQL instances. This method provides better performance for frequent queries but requires direct network access to the database.
150+
#### pgwire / pgwire_iam
151+
- VPC security group must allow inbound connections from your MCP server to the database
152+
- For `pgwire_iam`: IAM authentication must be enabled on the Aurora PostgreSQL cluster
187153

188-
Choose the connection method that best fits your environment and requirements.
154+
#### rdsapi
155+
- RDS Data API must be enabled on the Aurora PostgreSQL cluster
156+
- Appropriate IAM permissions for Data API access
189157

190158
### AWS Authentication
191159

src/postgres-mcp-server/awslabs/postgres_mcp_server/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,11 @@
1414

1515
"""awslabs.postgres-mcp-server"""
1616

17-
__version__ = '1.0.9'
17+
from importlib.metadata import version
18+
19+
try:
20+
__version__ = version('awslabs.postgres-mcp-server')
21+
except Exception:
22+
__version__ = '0.0.0+dev'
23+
24+
__user_agent__ = f'awslabs/mcp/postgres_mcp_server/{__version__}'

src/postgres-mcp-server/awslabs/postgres_mcp_server/connection/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@
1414

1515
"""aws.postgres-mcp-server.connection"""
1616

17-
from awslabs.postgres_mcp_server.connection.db_connection_singleton import DBConnectionSingleton
1817
from awslabs.postgres_mcp_server.connection.abstract_db_connection import AbstractDBConnection

0 commit comments

Comments
 (0)