@@ -1103,7 +1103,57 @@ def purge_cross_workspace_mcp_residue(state: dict, workspace: str) -> None:
11031103 )
11041104
11051105
1106- def configure_mcp_command () -> int :
1106+ def _resolve_location_mcp_servers (
1107+ workspace : str ,
1108+ profile : str | None ,
1109+ clients : list [str ],
1110+ location : str ,
1111+ original_servers : list [dict ],
1112+ ) -> list [dict ]:
1113+ """Build the desired MCP server list for ``--location <cat>.<schema>``.
1114+
1115+ Strict replacement: the returned list is exactly the mcp-services
1116+ discovered at ``location``. Any previously-registered MCP entries outside
1117+ that location are removed by ``apply_mcp_server_changes``. Raises ``RuntimeError`` for an invalid
1118+ location (HTTP 404 from the listing API) or any other listing failure."""
1119+ if location .count ("." ) != 1 or not all (part .strip () for part in location .split ("." )):
1120+ raise RuntimeError (f"--location must be `<catalog>.<schema>`, got `{ location } `." )
1121+
1122+ token = get_databricks_token (workspace , profile )
1123+ with spinner (f"Discovering MCP services in { location } ..." ):
1124+ names , reason = list_mcp_services (workspace , token , parent = location )
1125+
1126+ if reason and reason .startswith ("HTTP 404" ):
1127+ raise RuntimeError (
1128+ f"Invalid location: `{ location } ` is not a valid Unity Catalog schema "
1129+ "in this workspace (or you lack USE permission on it)."
1130+ )
1131+ if reason :
1132+ raise RuntimeError (f"Failed to list MCP services at `{ location } `: { reason } " )
1133+ if not names :
1134+ print_note (f"No MCP services exist at `{ location } `." )
1135+
1136+ original_by_name = _servers_by_name (original_servers )
1137+ working_servers : list [dict ] = []
1138+ for full_name in names :
1139+ entry_name = full_name .replace ("." , "-" )
1140+ original = original_by_name .get (entry_name )
1141+ original_clients = list ((original or {}).get ("clients" ) or [])
1142+ merged_clients = original_clients + [c for c in clients if c not in original_clients ]
1143+ candidate = {
1144+ "name" : entry_name ,
1145+ "url" : build_mcp_service_url (workspace , full_name ),
1146+ "auth" : f"env:{ MCP_AUTH_TOKEN_ENV_VAR } " ,
1147+ "clients" : merged_clients ,
1148+ }
1149+ if original is not None and original == candidate :
1150+ working_servers .append (original .copy ())
1151+ else :
1152+ working_servers .append (candidate )
1153+ return working_servers
1154+
1155+
1156+ def configure_mcp_command (location : str | None = None ) -> int :
11071157 state = load_state ()
11081158 workspace = state .get ("workspace" )
11091159 if not workspace :
@@ -1141,6 +1191,20 @@ def configure_mcp_command() -> int:
11411191 "skipping MCP config."
11421192 )
11431193
1194+ original_mcp_servers_for_location : list [dict ] = list (state .get ("mcp_servers" ) or [])
1195+ if location is not None :
1196+ working_mcp_servers = _resolve_location_mcp_servers (
1197+ workspace , profile , clients , location , original_mcp_servers_for_location
1198+ )
1199+ changed = apply_mcp_server_changes (
1200+ original_mcp_servers_for_location , working_mcp_servers , clients
1201+ )
1202+ if changed or original_mcp_servers_for_location != working_mcp_servers :
1203+ state ["mcp_servers" ] = working_mcp_servers
1204+ save_state (state )
1205+ print_success ("Saved" )
1206+ return 0
1207+
11441208 available_external_mcp_names = _discover_mcp_source (
11451209 "external connections" ,
11461210 lambda : discover_external_mcp_connection_names (workspace , profile ),
0 commit comments