File tree 1 file changed +6
-1
lines changed
1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 5
5
import uuid
6
6
import yaml
7
7
import importlib .metadata
8
+ import time
8
9
9
10
from mcp .server .models import InitializationOptions
10
11
import mcp .types as types
@@ -29,23 +30,27 @@ def data_to_yaml(data: Any) -> str:
29
30
30
31
31
32
class SnowflakeDB :
33
+ AUTH_EXPIRATION_TIME = 1800
34
+
32
35
def __init__ (self , connection_config : dict ):
33
36
self .connection_config = connection_config
34
37
self .session = None
35
38
self .insights : list [str ] = []
39
+ self .auth_time = 0
36
40
37
41
def _init_database (self ):
38
42
"""Initialize connection to the Snowflake database"""
39
43
try :
40
44
self .session = Session .builder .configs (self .connection_config ).create ()
41
45
for component in ["database" , "schema" , "warehouse" ]:
42
46
self .session .sql (f"USE { component .upper ()} { self .connection_config [component ].upper ()} " )
47
+ self .auth_time = time .time ()
43
48
except Exception as e :
44
49
raise ValueError (f"Failed to connect to Snowflake database: { e } " )
45
50
46
51
def execute_query (self , query : str ) -> list [dict [str , Any ]]:
47
52
"""Execute a SQL query and return results as a list of dictionaries"""
48
- if not self .session :
53
+ if not self .session or time . time () - self . auth_time > self . AUTH_EXPIRATION_TIME :
49
54
self ._init_database ()
50
55
51
56
logger .debug (f"Executing query: { query } " )
You can’t perform that action at this time.
0 commit comments