awslabs.postgres-mcp-server 1.0.9__py3-none-any.whl → 1.0.12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: awslabs.postgres-mcp-server
3
- Version: 1.0.9
3
+ Version: 1.0.12
4
4
  Summary: An AWS Labs Model Context Protocol (MCP) server for postgres
5
5
  Project-URL: homepage, https://awslabs.github.io/mcp/
6
6
  Project-URL: docs, https://awslabs.github.io/mcp/servers/postgres-mcp-server/
@@ -21,11 +21,12 @@ Classifier: Programming Language :: Python :: 3.11
21
21
  Classifier: Programming Language :: Python :: 3.12
22
22
  Classifier: Programming Language :: Python :: 3.13
23
23
  Requires-Python: >=3.10
24
- Requires-Dist: boto3>=1.38.5
25
- Requires-Dist: botocore>=1.38.5
24
+ Requires-Dist: aiorwlock
25
+ Requires-Dist: boto3>=1.42.4
26
+ Requires-Dist: botocore>1.42.4
26
27
  Requires-Dist: loguru>=0.7.0
27
- Requires-Dist: mcp[cli]>=1.11.0
28
- Requires-Dist: psycopg[pool]>=3.1.12
28
+ Requires-Dist: mcp[cli]>=1.23.0
29
+ Requires-Dist: psycopg[binary,pool]>=3.1.12
29
30
  Requires-Dist: pydantic>=2.10.6
30
31
  Description-Content-Type: text/markdown
31
32
 
@@ -43,11 +44,9 @@ An AWS Labs Model Context Protocol (MCP) server for Aurora Postgres
43
44
 
44
45
  1. Install `uv` from [Astral](https://docs.astral.sh/uv/getting-started/installation/) or the [GitHub README](https://github.com/astral-sh/uv#installation)
45
46
  2. Install Python using `uv python install 3.10`
46
- 3. Aurora Postgres Cluster with Postgres username and password stored in AWS Secrets Manager
47
- 4. Enable RDS Data API for your Aurora Postgres Cluster, see [instructions here](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/data-api.html)
48
- 5. This MCP server can only be run locally on the same host as your LLM client.
49
- 6. Docker runtime
50
- 7. Set up AWS credentials with access to AWS services
47
+ 3. This MCP server can only be run locally on the same host as your LLM client.
48
+ 4. Docker runtime
49
+ 5. Set up AWS credentials with access to AWS services
51
50
  - You need an AWS account with appropriate permissions
52
51
  - Configure AWS credentials with `aws configure` or environment variables
53
52
 
@@ -59,8 +58,6 @@ An AWS Labs Model Context Protocol (MCP) server for Aurora Postgres
59
58
 
60
59
  Configure the MCP server in your MCP client configuration (e.g., for Amazon Q Developer CLI, edit `~/.aws/amazonq/mcp.json`):
61
60
 
62
- ### Option 1: Using RDS Data API Connection (for Aurora Postgres)
63
-
64
61
  ```json
65
62
  {
66
63
  "mcpServers": {
@@ -68,11 +65,7 @@ Configure the MCP server in your MCP client configuration (e.g., for Amazon Q De
68
65
  "command": "uvx",
69
66
  "args": [
70
67
  "awslabs.postgres-mcp-server@latest",
71
- "--resource_arn", "[your data]",
72
- "--secret_arn", "[your data]",
73
- "--database", "[your data]",
74
- "--region", "[your data]",
75
- "--readonly", "True"
68
+ "--allow_write_query"
76
69
  ],
77
70
  "env": {
78
71
  "AWS_PROFILE": "your-aws-profile",
@@ -86,35 +79,6 @@ Configure the MCP server in your MCP client configuration (e.g., for Amazon Q De
86
79
  }
87
80
  ```
88
81
 
89
- ### Option 2: Using Direct PostgreSQL(psycopg) Connection (for Aurora Postgres and RDS Postgres)
90
-
91
- ```json
92
- {
93
- "mcpServers": {
94
- "awslabs.postgres-mcp-server": {
95
- "command": "uvx",
96
- "args": [
97
- "awslabs.postgres-mcp-server@latest",
98
- "--hostname", "[your data]",
99
- "--secret_arn", "[your data]",
100
- "--database", "[your data]",
101
- "--region", "[your data]",
102
- "--readonly", "True"
103
- ],
104
- "env": {
105
- "AWS_PROFILE": "your-aws-profile",
106
- "AWS_REGION": "us-east-1",
107
- "FASTMCP_LOG_LEVEL": "ERROR"
108
- },
109
- "disabled": false,
110
- "autoApprove": []
111
- }
112
- }
113
- }
114
- ```
115
-
116
- 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.
117
-
118
82
  ### Windows Installation
119
83
 
120
84
  For Windows users, the MCP server configuration format is slightly different:
@@ -167,56 +131,61 @@ For Windows users, the MCP server configuration format is slightly different:
167
131
  "-e", "AWS_SECRET_ACCESS_KEY=[your data]",
168
132
  "-e", "AWS_REGION=[your data]",
169
133
  "awslabs/postgres-mcp-server:latest",
170
- "--resource_arn", "[your data]",
171
- "--secret_arn", "[your data]",
172
- "--database", "[your data]",
173
- "--region", "[your data]",
174
- "--readonly", "True"
134
+ "--allow_write_query"
175
135
  ]
176
136
  }
177
137
  }
178
138
  }
179
139
  ```
180
140
 
181
- #### Option 2: Using Direct PostgreSQL (psycopg) Connection (for Aurora Postgres and RDS Postgres)
141
+ 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.
182
142
 
183
- ```
184
- {
185
- "mcpServers": {
186
- "awslabs.postgres-mcp-server": {
187
- "command": "docker",
188
- "args": [
189
- "run",
190
- "-i",
191
- "--rm",
192
- "-e", "AWS_ACCESS_KEY_ID=[your data]",
193
- "-e", "AWS_SECRET_ACCESS_KEY=[your data]",
194
- "-e", "AWS_REGION=[your data]",
195
- "awslabs/postgres-mcp-server:latest",
196
- "--hostname", "[your data]",
197
- "--secret_arn", "[your data]",
198
- "--database", "[your data]",
199
- "--region", "[your data]",
200
- "--readonly", "True"
201
- ]
202
- }
203
- }
204
- }
205
- ```
143
+ ## Support for Database Cluster Creation
206
144
 
207
- 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.
145
+ You can use the following LLM prompt to create a new Aurora PostgreSQL cluster:
208
146
 
209
- 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.
147
+ > Create an Aurora PostgreSQL cluster named 'mycluster' in us-west-2 region
148
+
149
+ ---
210
150
 
211
151
  ## Connection Methods
212
152
 
213
- This MCP server supports two connection methods:
153
+ The MCP server supports connecting to multiple database endpoints using different connection methods via LLM prompts.
154
+
155
+ ### Database Types
156
+ - **APG**: Amazon Aurora PostgreSQL
157
+ - **RPG**: Amazon RDS for PostgreSQL
158
+
159
+ ### Example Prompts
160
+
161
+ **Connect using RDS Data API:**
162
+ > 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
163
+
164
+ **Connect using pgwire (Aurora PostgreSQL):**
165
+ > 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
166
+
167
+ **Connect using pgwire (RDS PostgreSQL):**
168
+ > 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
169
+
170
+ ---
171
+
172
+ ### Supported Connection Methods
173
+
174
+ | Method | Description | Supported Database Types |
175
+ |--------|-------------|--------------------------|
176
+ | `pgwire` | Connect to PostgreSQL instance directly using the PostgreSQL wire protocol. Requires proper VPC security group configuration for direct database connectivity. | APG, RPG |
177
+ | `pgwire_iam` | Same as `pgwire`, but uses IAM authentication. Requires IAM authentication to be enabled on the Aurora PostgreSQL cluster. | APG only |
178
+ | `rdsapi` | Connect to Aurora PostgreSQL using the RDS Data API. Requires the RDS Data API to be enabled on the cluster. | APG only |
214
179
 
215
- 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.
180
+ ### Prerequisites by Connection Method
216
181
 
217
- 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.
182
+ #### pgwire / pgwire_iam
183
+ - VPC security group must allow inbound connections from your MCP server to the database
184
+ - For `pgwire_iam`: IAM authentication must be enabled on the Aurora PostgreSQL cluster
218
185
 
219
- Choose the connection method that best fits your environment and requirements.
186
+ #### rdsapi
187
+ - RDS Data API must be enabled on the Aurora PostgreSQL cluster
188
+ - Appropriate IAM permissions for Data API access
220
189
 
221
190
  ### AWS Authentication
222
191
 
@@ -0,0 +1,16 @@
1
+ awslabs/__init__.py,sha256=WuqxdDgUZylWNmVoPKiK7qGsTB_G4UmuXIrJ-VBwDew,731
2
+ awslabs/postgres_mcp_server/__init__.py,sha256=wQc_2CAtV2yzhVEIq70CSlMzE4VTLaWEr0WE_J7I2Ck,865
3
+ awslabs/postgres_mcp_server/mutable_sql_detector.py,sha256=bivLNglukgfi0IWcQSfDcwxFae4Q8CSvb--yWW617l0,2717
4
+ awslabs/postgres_mcp_server/server.py,sha256=-43tNzPiZqnjEpefV_7NcrVRNq7oMimms33CIcN5f0s,26911
5
+ awslabs/postgres_mcp_server/connection/__init__.py,sha256=ogj0dR6Lbr-WqXqXeRErIM1nlHTs9iqeD_ws6m86Y0E,753
6
+ awslabs/postgres_mcp_server/connection/abstract_db_connection.py,sha256=BGdyRoF1fgjLoFSiWg-XdS0KJ1UKuNgV03gGcRXOG8U,2080
7
+ awslabs/postgres_mcp_server/connection/cp_api_connection.py,sha256=mansXmSROE6_CtQZGLzqKdggyu0rCfeSPd9aQNYgkn0,24498
8
+ awslabs/postgres_mcp_server/connection/db_connection_map.py,sha256=DxFI0er9o_xTcu341f8FavC_AV77RDAiUrH66F8mKxY,4008
9
+ awslabs/postgres_mcp_server/connection/psycopg_pool_connection.py,sha256=p8iFe_1gV4lMxA9OS9IWBBqOww9SS9EFQ6ZVdmq9GSQ,14307
10
+ awslabs/postgres_mcp_server/connection/rds_api_connection.py,sha256=myKQYHhDiY5i0LK0ui0UsBjGCvSgJODdBHLjjTtRyyw,5587
11
+ awslabs_postgres_mcp_server-1.0.12.dist-info/METADATA,sha256=OirbVvefZ4kozEr3lsh4u14WSqta_ikRrTgWK-ET9sY,8265
12
+ awslabs_postgres_mcp_server-1.0.12.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
13
+ awslabs_postgres_mcp_server-1.0.12.dist-info/entry_points.txt,sha256=qHCxq_MTANxTB8-mA7Wl6H71qWEMwmG-I6_koII4AXY,88
14
+ awslabs_postgres_mcp_server-1.0.12.dist-info/licenses/LICENSE,sha256=CeipvOyAZxBGUsFoaFqwkx54aPnIKEtm9a5u2uXxEws,10142
15
+ awslabs_postgres_mcp_server-1.0.12.dist-info/licenses/NOTICE,sha256=qMIIe3h7I1Y4-CKejn50wbSKXEZLWhYHdKaRwKdXN9M,95
16
+ awslabs_postgres_mcp_server-1.0.12.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.27.0
2
+ Generator: hatchling 1.28.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,117 +0,0 @@
1
- # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- #
3
- # Licensed under the Apache License, Version 2.0 (the "License");
4
- # you may not use this file except in compliance with the License.
5
- # You may obtain a copy of the License at
6
- #
7
- # http://www.apache.org/licenses/LICENSE-2.0
8
- #
9
- # Unless required by applicable law or agreed to in writing, software
10
- # distributed under the License is distributed on an "AS IS" BASIS,
11
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- # See the License for the specific language governing permissions and
13
- # limitations under the License.
14
-
15
- """Database connection singleton for postgres MCP Server."""
16
-
17
- import asyncio
18
- from awslabs.postgres_mcp_server.connection.rds_api_connection import RDSDataAPIConnection
19
- from loguru import logger
20
-
21
-
22
- class DBConnectionSingleton:
23
- """Manages a single RDS Data API connection instance across the application."""
24
-
25
- _instance = None
26
-
27
- def __init__(
28
- self,
29
- resource_arn: str,
30
- secret_arn: str,
31
- database: str,
32
- region: str,
33
- readonly: bool = True,
34
- is_test: bool = False,
35
- ):
36
- """Initialize a new DB connection singleton for RDS Data API.
37
-
38
- Args:
39
- resource_arn: The ARN of the RDS cluster
40
- secret_arn: The ARN of the secret containing credentials
41
- database: The name of the database to connect to
42
- region: The AWS region where the RDS instance is located
43
- readonly: Whether the connection should be read-only (default: True)
44
- is_test: Whether this is a test connection (default: False)
45
- """
46
- if not all([resource_arn, secret_arn, database, region]):
47
- raise ValueError(
48
- 'Missing required connection parameters for RDS Data API. '
49
- 'Please provide resource_arn, secret_arn, database, and region.'
50
- )
51
-
52
- self._db_connection = RDSDataAPIConnection(
53
- cluster_arn=resource_arn,
54
- secret_arn=secret_arn,
55
- database=database,
56
- region=region,
57
- readonly=readonly,
58
- is_test=is_test,
59
- )
60
-
61
- @classmethod
62
- def initialize(
63
- cls,
64
- resource_arn: str,
65
- secret_arn: str,
66
- database: str,
67
- region: str,
68
- readonly: bool = True,
69
- is_test: bool = False,
70
- ):
71
- """Initialize the singleton instance if it doesn't exist.
72
-
73
- Args:
74
- resource_arn: The ARN of the RDS cluster
75
- secret_arn: The ARN of the secret containing credentials
76
- database: The name of the database to connect to
77
- region: The AWS region where the RDS instance is located
78
- readonly: Whether the connection should be read-only (default: True)
79
- is_test: Whether this is a test connection (default: False)
80
- """
81
- if cls._instance is None:
82
- cls._instance = cls(
83
- resource_arn=resource_arn,
84
- secret_arn=secret_arn,
85
- database=database,
86
- region=region,
87
- readonly=readonly,
88
- is_test=is_test,
89
- )
90
-
91
- @classmethod
92
- def get(cls):
93
- """Get the singleton instance."""
94
- if cls._instance is None:
95
- raise RuntimeError('DBConnectionSingleton is not initialized.')
96
- return cls._instance
97
-
98
- @property
99
- def db_connection(self):
100
- """Get the database connection."""
101
- return self._db_connection
102
-
103
- @classmethod
104
- def cleanup(cls):
105
- """Clean up resources when shutting down."""
106
- if cls._instance and cls._instance._db_connection:
107
- # Handle calling async close method from sync context
108
- try:
109
- loop = asyncio.get_event_loop()
110
- if loop.is_running():
111
- # If we're in an async context, create a task
112
- asyncio.create_task(cls._instance._db_connection.close())
113
- else:
114
- # If we're in a sync context, run the coroutine to completion
115
- loop.run_until_complete(cls._instance._db_connection.close())
116
- except Exception as e:
117
- logger.error(f'Error during connection cleanup: {str(e)}')
@@ -1,15 +0,0 @@
1
- awslabs/__init__.py,sha256=WuqxdDgUZylWNmVoPKiK7qGsTB_G4UmuXIrJ-VBwDew,731
2
- awslabs/postgres_mcp_server/__init__.py,sha256=W5_481HOI7iYfOK8foDzV68US73mBfZmPR6LOSS7JcU,673
3
- awslabs/postgres_mcp_server/mutable_sql_detector.py,sha256=bivLNglukgfi0IWcQSfDcwxFae4Q8CSvb--yWW617l0,2717
4
- awslabs/postgres_mcp_server/server.py,sha256=wenII8rWhhUVVo-m2C2cPWVwS1S_Us3LUKmKQrr9ebw,11621
5
- awslabs/postgres_mcp_server/connection/__init__.py,sha256=9j_gZeLcWoXu_Fny1PkC3RsnDMOHr9M3OM9EWvlGR7o,850
6
- awslabs/postgres_mcp_server/connection/abstract_db_connection.py,sha256=BGdyRoF1fgjLoFSiWg-XdS0KJ1UKuNgV03gGcRXOG8U,2080
7
- awslabs/postgres_mcp_server/connection/db_connection_singleton.py,sha256=Fwm6uTwB-bhprx-UgiOttDFtczeMUfW5M79wGL0x1Go,4279
8
- awslabs/postgres_mcp_server/connection/psycopg_pool_connection.py,sha256=qHbRR8-P__v5_-_Q-AQdZVD_nTHj-2Y1p-j1RnKRmrs,12593
9
- awslabs/postgres_mcp_server/connection/rds_api_connection.py,sha256=1G4qfik5Nu-KbAxRLFNshQ5DJxFnJQI6eqLJPXp-Qn4,5419
10
- awslabs_postgres_mcp_server-1.0.9.dist-info/METADATA,sha256=2gNeSfP8bN2bbXtFqnJH937jRJ7__eDgYL-xWUkkCDE,8992
11
- awslabs_postgres_mcp_server-1.0.9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
12
- awslabs_postgres_mcp_server-1.0.9.dist-info/entry_points.txt,sha256=qHCxq_MTANxTB8-mA7Wl6H71qWEMwmG-I6_koII4AXY,88
13
- awslabs_postgres_mcp_server-1.0.9.dist-info/licenses/LICENSE,sha256=CeipvOyAZxBGUsFoaFqwkx54aPnIKEtm9a5u2uXxEws,10142
14
- awslabs_postgres_mcp_server-1.0.9.dist-info/licenses/NOTICE,sha256=qMIIe3h7I1Y4-CKejn50wbSKXEZLWhYHdKaRwKdXN9M,95
15
- awslabs_postgres_mcp_server-1.0.9.dist-info/RECORD,,