Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(mcp): clear the DCR client ref and upstream warning on modal close, and reuse the ref in the temp OAuth payload

Tin1e78e96c5dac
diff --git a/ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.test.tsx b/ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.test.tsx
index 0ff015e0862..bc33ed79e49 100644
--- a/ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.test.tsx
+++ b/ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.test.tsx
@@ -31,6 +31,7 @@ const oauthHook = vi.hoisted(() => ({
| ((token: Record<string, unknown> | null, registeredClient?: { clientId?: string; clientSecret?: string }) => void)
| null,
getCredentials: null as (() => Record<string, unknown> | undefined) | null,
+ getTemporaryPayload: null as (() => Record<string, unknown> | null) | null,
}));
vi.mock("@/hooks/useMcpOAuthFlow", () => ({
useMcpOAuthFlow: (opts: {
@@ -39,9 +40,11 @@ vi.mock("@/hooks/useMcpOAuthFlow", () => ({
registeredClient?: { clientId?: string; clientSecret?: string },
) => void;
getCredentials?: () => Record<string, unknown> | undefined;
+ getTemporaryPayload?: () => Record<string, unknown> | null;
}) => {
oauthHook.onTokenReceived = opts.onTokenReceived;
oauthHook.getCredentials = opts.getCredentials ?? null;
+ oauthHook.getTemporaryPayload = opts.getTemporaryPayload ?? null;
return {
startOAuthFlow: vi.fn(),
status: "idle",
@@ -627,6 +630,38 @@ describe("CreateMCPServer", () => {
// The DCR client must NOT be in the form store (or it could be collected as a CF server's app),
// but getCredentials merges it so a re-authorize reuses the registered client instead of re-DCRing.
expect(oauthHook.getCredentials?.()?.client_id).toBe("dcr-client");
+ // getTemporaryPayload must mirror getCredentials for oauth2, or a re-authorize's temp session omits
+ // the registered client and useMcpOAuthFlow re-registers instead of reusing it.
+ expect(oauthHook.getTemporaryPayload?.()?.credentials).toMatchObject({ client_id: "dcr-client" });
+ });
+
+ it("clears the DCR ref and the upstream warning when the modal closes so nothing leaks to the next session", async () => {
+ const { rerender } = render(<CreateMCPServer {...defaultProps} />);
+ await selectAntOption("Transport Type", "Streamable HTTP");
+ await waitFor(() => expect(screen.getByPlaceholderText("https://your-mcp-server.com")).toBeInTheDocument());
+ const user = userEvent.setup({ delay: null });
+ await user.type(getServerNameInput(), "Leak_Server");
+ await user.type(screen.getByPlaceholderText("https://your-mcp-server.com"), "https://example.com/mcp");
+ await selectAntOption("Authentication", "OAuth");
+
+ await waitFor(() => expect(oauthHook.onTokenReceived).toBeTruthy());
+ await act(async () => {
+ oauthHook.onTokenReceived!(
+ { access_token: "oauth2-tok", token_type: "Bearer" },
+ { clientId: "leak-client", clientSecret: "leak-secret" },
+ );
+ });
+ // Ref is held while the modal is open.
+ expect(oauthHook.getCredentials?.()?.client_id).toBe("leak-client");
+
+ // A parent dismiss (isModalVisible -> false) that does not route through Cancel/Create must still
+ // clear the DCR ref, or the next server's oauth2 submit would carry this server's registered client.
+ await act(async () => {
+ rerender(<CreateMCPServer {...defaultProps} isModalVisible={false} />);
+ });
+
+ expect(oauthHook.getCredentials?.()?.client_id).toBeUndefined();
+ expect(oauthHook.getTemporaryPayload?.()?.credentials ?? {}).not.toMatchObject({ client_id: "leak-client" });
});
it("persists the DCR client on an oauth2 submit via the ref", async () => {
diff --git a/ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx b/ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx
index 52abd40db93..5172a487562 100644
--- a/ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx
+++ b/ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx
@@ -204,9 +204,12 @@ const CreateMCPServer: React.FC<CreateMCPServerProps> = ({
url,
transport: transport === TRANSPORT.OPENAPI ? "http" : transport,
auth_type: isClientForwardedTokenMode(values.auth_type) ? values.auth_type : AUTH_TYPE.OAUTH2,
+ // Mirror getCredentials: merge the ref-held DCR client for oauth2 so a re-authorize reuses the
+ // registered client (useMcpOAuthFlow keys reuse off credentials.client_id) instead of re-DCRing;
+ // the client-forwarded modes carry only the declared app.
credentials: isClientForwardedTokenMode(values.auth_type)
? preservedDeclaredAppCredentials(values.credentials)
- : values.credentials,
+ : { ...((values.credentials as Record<string, unknown> | undefined) ?? {}), ...(dcrClientRef.current ?? {}) },
authorization_url: values.authorization_url,
token_url: values.token_url,
registration_url: values.registration_url,
@@ -728,6 +731,8 @@ const CreateMCPServer: React.FC<CreateMCPServerProps> = ({
clearTools();
resetOAuthFlow();
setAuthorizedIdentity(undefined);
+ dcrClientRef.current = null;
+ setAppMayNotMatchUpstream(false);
}
}, [isModalVisible, form, clearTools, resetOAuthFlow]);