Skip to content

Commit 31774be

Browse files
mturleyclaude
andauthored
fix(model-registry): auto-select project after MCP server deployment (opendatahub-io#7135)
After deploying an MCP server from the catalog, navigate to the deployments page with ?namespace= so the project selector is pre-populated. The deployments page reads this param on mount, sets the preferred namespace, then removes it from the URL. Fixes: RHOAIENG-57265 Signed-off-by: Mike Turley <mike.turley@alum.cs.umass.edu> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cf0d320 commit 31774be

3 files changed

Lines changed: 24 additions & 2 deletions

File tree

packages/model-registry/upstream/frontend/src/app/pages/mcpDeployments/McpDeploymentsPage.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as React from 'react';
2+
import { useSearchParams } from 'react-router-dom';
23
import { ApplicationsPage } from 'mod-arch-shared';
34
import { useNamespaceSelector, useModularArchContext } from 'mod-arch-core';
45
import {
@@ -20,6 +21,7 @@ import DeleteMcpDeploymentModal from './DeleteMcpDeploymentModal';
2021
import { getDeploymentDisplayName } from './utils';
2122

2223
const McpDeploymentsPage: React.FC = () => {
24+
const [searchParams, setSearchParams] = useSearchParams();
2325
const [deployments, loaded, loadError, refresh] = useMcpDeployments();
2426
const [filterText, setFilterText] = React.useState('');
2527
const [deleteTarget, setDeleteTarget] = React.useState<McpDeployment | undefined>();
@@ -30,6 +32,23 @@ const McpDeploymentsPage: React.FC = () => {
3032
const isMandatoryNamespace = Boolean(config.mandatoryNamespace);
3133
const selectedProject = preferredNamespace?.name || '';
3234

35+
// If a namespace query param is present (e.g. after deploying from the catalog),
36+
// use it to pre-select the project, then remove it from the URL.
37+
// TODO: Remove this when the page switches to ProjectsContext (RHOAIENG-56566).
38+
const namespaceParamConsumedRef = React.useRef(false);
39+
React.useEffect(() => {
40+
if (namespaceParamConsumedRef.current) {
41+
return;
42+
}
43+
const ns = searchParams.get('namespace');
44+
if (ns) {
45+
namespaceParamConsumedRef.current = true;
46+
updatePreferredNamespace({ name: ns });
47+
searchParams.delete('namespace');
48+
setSearchParams(searchParams, { replace: true });
49+
}
50+
}, [searchParams, setSearchParams, updatePreferredNamespace]);
51+
3352
const handleProjectChange = React.useCallback(
3453
(projectName: string) => {
3554
if (!projectName || isMandatoryNamespace) {

packages/model-registry/upstream/frontend/src/app/routes/mcpCatalog/mcpCatalog.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ export const mcpCatalogUrl = (): string => '/ai-hub/mcp-servers/catalog';
33
export const mcpServerDetailsUrl = (serverId: string | number): string =>
44
`${mcpCatalogUrl()}/${encodeURIComponent(String(serverId))}`;
55

6-
export const mcpDeploymentsUrl = (): string => '/ai-hub/mcp-deployments';
6+
export const mcpDeploymentsUrl = (namespace?: string): string =>
7+
namespace
8+
? `/ai-hub/mcp-deployments?namespace=${encodeURIComponent(namespace)}`
9+
: '/ai-hub/mcp-deployments';

packages/model-registry/upstream/frontend/src/odh/components/McpDeployModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const McpDeployModal: React.FC<McpDeployModalProps> = ({
152152
'MCP server deployed successfully',
153153
`${displayName || k8sName} has been deployed to ${selectedNamespace}.`,
154154
);
155-
navigate(mcpDeploymentsUrl());
155+
navigate(mcpDeploymentsUrl(selectedNamespace));
156156
}
157157
} catch (e) {
158158
setSubmitError(

0 commit comments

Comments
 (0)