mcp-dbutils 0.3.0__py3-none-any.whl → 0.4.0__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.
- mcp_dbutils/postgres/config.py +89 -5
- {mcp_dbutils-0.3.0.dist-info → mcp_dbutils-0.4.0.dist-info}/METADATA +1 -1
- {mcp_dbutils-0.3.0.dist-info → mcp_dbutils-0.4.0.dist-info}/RECORD +6 -6
- {mcp_dbutils-0.3.0.dist-info → mcp_dbutils-0.4.0.dist-info}/WHEEL +0 -0
- {mcp_dbutils-0.3.0.dist-info → mcp_dbutils-0.4.0.dist-info}/entry_points.txt +0 -0
- {mcp_dbutils-0.3.0.dist-info → mcp_dbutils-0.4.0.dist-info}/licenses/LICENSE +0 -0
mcp_dbutils/postgres/config.py
CHANGED
@@ -1,8 +1,40 @@
|
|
1
1
|
"""PostgreSQL configuration module"""
|
2
2
|
from dataclasses import dataclass
|
3
3
|
from typing import Optional, Dict, Any, Literal
|
4
|
+
from urllib.parse import urlparse
|
4
5
|
from ..config import DatabaseConfig
|
5
6
|
|
7
|
+
def parse_jdbc_url(jdbc_url: str) -> Dict[str, str]:
|
8
|
+
"""Parse JDBC URL into connection parameters
|
9
|
+
|
10
|
+
Args:
|
11
|
+
jdbc_url: JDBC URL (e.g. jdbc:postgresql://host:port/dbname)
|
12
|
+
|
13
|
+
Returns:
|
14
|
+
Dictionary of connection parameters
|
15
|
+
"""
|
16
|
+
if not jdbc_url.startswith('jdbc:postgresql://'):
|
17
|
+
raise ValueError("Invalid PostgreSQL JDBC URL format")
|
18
|
+
|
19
|
+
# Remove jdbc: prefix and ensure no credentials in URL
|
20
|
+
url = jdbc_url[5:]
|
21
|
+
if '@' in url:
|
22
|
+
raise ValueError("JDBC URL should not contain credentials. Please provide username and password separately.")
|
23
|
+
|
24
|
+
# Parse URL
|
25
|
+
parsed = urlparse(url)
|
26
|
+
|
27
|
+
params = {
|
28
|
+
'host': parsed.hostname or 'localhost',
|
29
|
+
'port': str(parsed.port or 5432),
|
30
|
+
'dbname': parsed.path.lstrip('/') if parsed.path else '',
|
31
|
+
}
|
32
|
+
|
33
|
+
if not params['dbname']:
|
34
|
+
raise ValueError("Database name must be specified in URL")
|
35
|
+
|
36
|
+
return params
|
37
|
+
|
6
38
|
@dataclass
|
7
39
|
class PostgresConfig(DatabaseConfig):
|
8
40
|
dbname: str
|
@@ -35,12 +67,64 @@ class PostgresConfig(DatabaseConfig):
|
|
35
67
|
if db_config['type'] != 'postgres':
|
36
68
|
raise ValueError(f"Configuration is not PostgreSQL type: {db_config['type']}")
|
37
69
|
|
70
|
+
# Check required credentials
|
71
|
+
if not db_config.get('user'):
|
72
|
+
raise ValueError("User must be specified in database configuration")
|
73
|
+
if not db_config.get('password'):
|
74
|
+
raise ValueError("Password must be specified in database configuration")
|
75
|
+
|
76
|
+
# Get connection parameters
|
77
|
+
if 'jdbc_url' in db_config:
|
78
|
+
# Parse JDBC URL for connection parameters
|
79
|
+
params = parse_jdbc_url(db_config['jdbc_url'])
|
80
|
+
config = cls(
|
81
|
+
dbname=params['dbname'],
|
82
|
+
user=db_config['user'],
|
83
|
+
password=db_config['password'],
|
84
|
+
host=params['host'],
|
85
|
+
port=params['port'],
|
86
|
+
local_host=local_host,
|
87
|
+
)
|
88
|
+
else:
|
89
|
+
if not db_config.get('dbname'):
|
90
|
+
raise ValueError("Database name must be specified in configuration")
|
91
|
+
if not db_config.get('host'):
|
92
|
+
raise ValueError("Host must be specified in configuration")
|
93
|
+
if not db_config.get('port'):
|
94
|
+
raise ValueError("Port must be specified in configuration")
|
95
|
+
config = cls(
|
96
|
+
dbname=db_config['dbname'],
|
97
|
+
user=db_config['user'],
|
98
|
+
password=db_config['password'],
|
99
|
+
host=db_config['host'],
|
100
|
+
port=str(db_config['port']),
|
101
|
+
local_host=local_host,
|
102
|
+
)
|
103
|
+
config.debug = cls.get_debug_mode()
|
104
|
+
return config
|
105
|
+
|
106
|
+
@classmethod
|
107
|
+
def from_jdbc_url(cls, jdbc_url: str, user: str, password: str,
|
108
|
+
local_host: Optional[str] = None) -> 'PostgresConfig':
|
109
|
+
"""Create configuration from JDBC URL and credentials
|
110
|
+
|
111
|
+
Args:
|
112
|
+
jdbc_url: JDBC URL (jdbc:postgresql://host:port/dbname)
|
113
|
+
user: Username for database connection
|
114
|
+
password: Password for database connection
|
115
|
+
local_host: Optional local host address
|
116
|
+
|
117
|
+
Raises:
|
118
|
+
ValueError: If URL format is invalid or required parameters are missing
|
119
|
+
"""
|
120
|
+
params = parse_jdbc_url(jdbc_url)
|
121
|
+
|
38
122
|
config = cls(
|
39
|
-
dbname=
|
40
|
-
user=
|
41
|
-
password=
|
42
|
-
host=
|
43
|
-
port=
|
123
|
+
dbname=params['dbname'],
|
124
|
+
user=user,
|
125
|
+
password=password,
|
126
|
+
host=params['host'],
|
127
|
+
port=params['port'],
|
44
128
|
local_host=local_host,
|
45
129
|
)
|
46
130
|
config.debug = cls.get_debug_mode()
|
@@ -4,15 +4,15 @@ mcp_dbutils/config.py,sha256=EwnPNuQVCBKd5WOXQfROyDTM-YpM_Odp0GhCPRg8YwE,1863
|
|
4
4
|
mcp_dbutils/log.py,sha256=fibVIwsb1HVU5zriGrDZTMEirKjgIuxuN_B_YTdAJ7I,996
|
5
5
|
mcp_dbutils/stats.py,sha256=2hiKi_M8V4xhVHlH5FS-Df5GuMEpuzif12C8ik06Khs,2538
|
6
6
|
mcp_dbutils/postgres/__init__.py,sha256=Y6v_RsI79pqAfpKM3SrT1T1I9r5yWuKT0GUUNmHD3DE,146
|
7
|
-
mcp_dbutils/postgres/config.py,sha256=
|
7
|
+
mcp_dbutils/postgres/config.py,sha256=Np0GS5iUaUuWpYI8QfnyjUDy7v-vResQEAexR4W92-o,5447
|
8
8
|
mcp_dbutils/postgres/handler.py,sha256=JC_Qyw1s6qjVR0tdH7FLAEAs9EPl_-wgFQLryQyMq5c,6089
|
9
9
|
mcp_dbutils/postgres/server.py,sha256=_S3HF1KooxPB9gX1FedoOOGn93tHlIevCab6vjCt2TU,8715
|
10
10
|
mcp_dbutils/sqlite/__init__.py,sha256=QV4th2ywzUmCCa3GHCcBf8blJ_E8OYy0dJ2fSf1TfSU,134
|
11
11
|
mcp_dbutils/sqlite/config.py,sha256=QK1JlY-ZBB5VyhydbiU-aAKNESTWMtyBfawbv2DAVCQ,2452
|
12
12
|
mcp_dbutils/sqlite/handler.py,sha256=bf_k93rCcJn09zc7tsqrlbiTGUg3FspimfWKxK_JQTs,4970
|
13
13
|
mcp_dbutils/sqlite/server.py,sha256=7Bbq9l7Ca_4dzkAbbdRcXxvHoO_NFLzZHwlhKB0HIJc,7724
|
14
|
-
mcp_dbutils-0.
|
15
|
-
mcp_dbutils-0.
|
16
|
-
mcp_dbutils-0.
|
17
|
-
mcp_dbutils-0.
|
18
|
-
mcp_dbutils-0.
|
14
|
+
mcp_dbutils-0.4.0.dist-info/METADATA,sha256=1c8QEdqJmgHUCjsMxJEMh1C5Qdpq0EdXWAO07yIv77k,9478
|
15
|
+
mcp_dbutils-0.4.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
16
|
+
mcp_dbutils-0.4.0.dist-info/entry_points.txt,sha256=XTjt0QmYRgKOJQT6skR9bp1EMUfIrgpHeZJPZ3CJffs,49
|
17
|
+
mcp_dbutils-0.4.0.dist-info/licenses/LICENSE,sha256=1A_CwpWVlbjrKdVEYO77vYfnXlW7oxcilZ8FpA_BzCI,1065
|
18
|
+
mcp_dbutils-0.4.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|