@@ -35,6 +35,7 @@ async def create_sqlalchemy_engine(
3535 ip_type : str = "public" ,
3636 refresh_strategy : str = "background" ,
3737 resolver : Union [type [DefaultResolver ], type [DnsResolver ]] = DefaultResolver ,
38+ ** kwargs : Any ,
3839) -> tuple [sqlalchemy .ext .asyncio .engine .AsyncEngine , Connector ]:
3940 """Creates a connection pool for a Cloud SQL instance and returns the pool
4041 and the connector. Callers are responsible for closing the pool and the
@@ -92,6 +93,7 @@ async def create_sqlalchemy_engine(
9293 password = password ,
9394 db = db ,
9495 ip_type = ip_type , # can be "public", "private" or "psc"
96+ ** kwargs , # additional asyncpg connection args
9597 ),
9698 execution_options = {"isolation_level" : "AUTOCOMMIT" },
9799 )
@@ -220,6 +222,30 @@ async def test_custom_SAN_with_dns_sqlalchemy_connection_with_asyncpg() -> None:
220222 await connector .close_async ()
221223
222224
225+ async def test_MCP_sqlalchemy_connection_with_asyncpg () -> None :
226+ """Basic test to get time from database using MCP enabled instance."""
227+ inst_conn_name = os .environ ["POSTGRES_MCP_CONNECTION_NAME" ]
228+ user = os .environ ["POSTGRES_USER" ]
229+ password = os .environ ["POSTGRES_MCP_PASS" ]
230+ db = os .environ ["POSTGRES_DB" ]
231+ ip_type = os .environ .get ("IP_TYPE" , "public" )
232+
233+ pool , connector = await create_sqlalchemy_engine (
234+ inst_conn_name ,
235+ user ,
236+ password ,
237+ db ,
238+ ip_type ,
239+ statement_cache_size = 0 ,
240+ )
241+
242+ async with pool .connect () as conn :
243+ res = (await conn .execute (sqlalchemy .text ("SELECT 1" ))).fetchone ()
244+ assert res [0 ] == 1
245+
246+ await connector .close_async ()
247+
248+
223249async def test_connection_with_asyncpg () -> None :
224250 """Basic test to get time from database."""
225251 inst_conn_name = os .environ ["POSTGRES_CONNECTION_NAME" ]
0 commit comments