1919from testgen .mcp .permissions import get_project_permissions , mcp_permission
2020from testgen .mcp .tools .common import (
2121 SQL_FLAVOR_CODE_TO_LABEL ,
22+ DocGroup ,
2223 apply_connection_params ,
23- connection_display_fields ,
24+ effective_mode ,
2425 format_flavor_label ,
2526 format_page_footer ,
2627 format_page_info ,
27- infer_mode ,
2828 parse_sql_flavor ,
29+ raise_validation_error ,
30+ render_connection_body ,
2931 resolve_connection ,
3032 validate_connection_fields ,
3133 validate_limit ,
3234 validate_page ,
3335)
3436from testgen .mcp .tools .markdown import MdDoc
3537
38+ _DOC_GROUP = DocGroup .MANAGE
39+
3640
3741@with_database_session
3842@mcp_permission ("view" )
@@ -99,7 +103,7 @@ def get_connection(connection_id: int) -> str:
99103 connection = resolve_connection (connection_id )
100104 doc = MdDoc ()
101105 doc .heading (1 , f"Connection `{ connection .connection_name } `" )
102- _render_connection_body (doc , connection )
106+ render_connection_body (doc , connection )
103107 return doc .render ()
104108
105109
@@ -151,7 +155,7 @@ def test_connection(
151155 connection = Connection (sql_flavor = family , sql_flavor_code = code )
152156
153157 if connection_params is not None or connection_mode is not None :
154- mode = connection_mode if inline else _effective_mode (connection , connection_mode )
158+ mode = connection_mode if inline else effective_mode (connection , connection_mode )
155159 apply_connection_params (connection , connection .sql_flavor_code , mode , connection_params or {})
156160
157161 normalize_auth_fields (connection )
@@ -160,7 +164,7 @@ def test_connection(
160164
161165 errors = validate_connection_fields (connection )
162166 if errors :
163- _raise_validation_error (errors , "Cannot test connection. Required fields missing or invalid." )
167+ raise_validation_error (errors , "Cannot test connection. Required fields missing or invalid." )
164168
165169 status = test_connection_status (connection )
166170
@@ -181,59 +185,3 @@ def test_connection(
181185 if status .details :
182186 doc .code_block (status .details )
183187 return doc .render ()
184-
185-
186- # ---------------------------------------------------------------------------
187- # Helpers
188- # ---------------------------------------------------------------------------
189-
190-
191- def _effective_mode (connection : Connection , connection_mode : str | None ) -> str | None :
192- """Mode label to apply: the explicit override, else the connection's current mode."""
193- if connection_mode is not None :
194- return connection_mode
195- inferred = infer_mode (connection )
196- return str (inferred ) if inferred is not None else None
197-
198-
199- def _raise_validation_error (errors : list [str ], header : str ) -> None :
200- bullets = "\n " .join (f"- { err } " for err in errors )
201- raise MCPUserError (f"{ header } \n \n { bullets } " )
202-
203-
204- def _render_connection_body (doc : MdDoc , connection : Connection ) -> None :
205- """Render every non-secret connection field below the heading.
206-
207- Encrypted columns are filtered out via ``ConnField.secret``.
208- """
209- doc .field ("ID" , connection .connection_id , code = True )
210- doc .field ("Project" , connection .project_code , code = True )
211- doc .field ("Type" , format_flavor_label (connection .sql_flavor_code ))
212-
213- # Each populated, non-secret field under its flavor-specific label
214- # (e.g. "Catalog" for Databricks, "Login URL" for Salesforce).
215- for fld in connection_display_fields (connection ):
216- if fld .secret :
217- continue
218- value = getattr (connection , fld .column , None )
219- if value in (None , "" ):
220- continue
221- doc .field (fld .label , value , code = fld .column != "project_port" )
222-
223- doc .field ("Authentication" , _authentication_label (connection ))
224- if connection .max_threads is not None :
225- doc .field ("Max Threads" , connection .max_threads )
226- if connection .max_query_chars is not None :
227- doc .field ("Max Expression Length" , connection .max_query_chars )
228-
229-
230- def _authentication_label (connection : Connection ) -> str :
231- """The connection's auth method: the active connection mode for multi-mode
232- flavors, else the implicit method (service account key, else password).
233- """
234- mode = infer_mode (connection )
235- if mode is not None :
236- return str (mode )
237- if connection .service_account_key :
238- return "Service Account Key"
239- return "Password"
0 commit comments