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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(ui): key the edit form's browser-held token handling off the effective auth type
Tinbff2c952e033
diff --git a/ui/litellm-dashboard/src/components/mcp_tools/mcp_server_edit.test.tsx b/ui/litellm-dashboard/src/components/mcp_tools/mcp_server_edit.test.tsxindex 0579a3208d1..d55f993b926 100644--- a/ui/litellm-dashboard/src/components/mcp_tools/mcp_server_edit.test.tsx+++ b/ui/litellm-dashboard/src/components/mcp_tools/mcp_server_edit.test.tsx@@ -1173,6 +1173,76 @@ describe("MCPServerEdit (OAuth token persistence on save)", () => {expect(onSuccess).not.toHaveBeenCalled();});+ it.each([["true_passthrough"], ["oauth_delegate"]])(+ "persists the staged token to sessionStorage on save for the %s mode",+ async (authType) => {+ // Regression: the save path classified the staged token with getMcpOAuthMode, which returns+ // null for the client-forwarded modes, so setToken was never called and the browser-held+ // token was dropped on save; the create form's submit path already committed it.+ mockOauth.tokenResponse = { access_token: "cf-tok", expires_in: 1800, token_type: "bearer" };+ vi.mocked(networking.updateMCPServer).mockResolvedValue({+ ...interactiveOAuthServer,+ auth_type: authType,+ });++ render(+ <MCPServerEdit+ mcpServer={{ ...interactiveOAuthServer, auth_type: authType }}+ accessToken="access-token"+ userID="user-1"+ onCancel={vi.fn()}+ onSuccess={vi.fn()}+ availableAccessGroups={[]}+ />,+ );++ await act(async () => {+ fireEvent.click(screen.getAllByRole("button", { name: "Save Changes" })[0]);+ });++ await waitFor(() => {+ expect(mockSetToken).toHaveBeenCalledWith(+ "oauth_server_1",+ expect.objectContaining({ access_token: "cf-tok" }),+ "user-1",+ );+ });+ expect(networking.storeMCPOAuthUserCredential).not.toHaveBeenCalled();+ const [, payload] = vi.mocked(networking.updateMCPServer).mock.calls[0];+ expect(payload.credentials).toBeUndefined();+ },+ );++ it("forwards a newly authorized browser-held token for tool loading before the form is saved", async () => {+ // Regression: fetchTools keyed the browser-held decision off the saved mcpServer.auth_type, so+ // after switching the form to true_passthrough and authorizing, the fresh token was not sent as+ // the x-mcp header until the server was saved.+ vi.mocked(networking.listMCPTools).mockResolvedValue({ tools: [], error: null });+ mockIsTokenValid.mockReturnValue(false);++ render(+ <MCPServerEdit+ mcpServer={{ ...interactiveOAuthServer, auth_type: "api_key" }}+ accessToken="access-token"+ userID="user-1"+ onCancel={vi.fn()}+ onSuccess={vi.fn()}+ availableAccessGroups={[]}+ />,+ );++ await selectAntOption("Authentication", "OAuth Delegate (client-supplied upstream token)");+ mockOauth.tokenResponse = { access_token: "fresh-tok", token_type: "bearer" };+ await selectAntOption("Authentication", "True Passthrough (no LiteLLM auth)");++ await waitFor(() => {+ const withHeaders = vi+ .mocked(networking.listMCPTools)+ .mock.calls.find(([, , headers]) => headers && JSON.stringify(headers).includes("fresh-tok"));+ expect(withHeaders).toBeTruthy();+ });+ });+it("persists the passthrough token to sessionStorage on save after authorize", async () => {mockOauth.tokenResponse = { access_token: "pt-tok", expires_in: 1800, token_type: "bearer" };vi.mocked(networking.updateMCPServer).mockResolvedValue({diff --git a/ui/litellm-dashboard/src/components/mcp_tools/mcp_server_edit.tsx b/ui/litellm-dashboard/src/components/mcp_tools/mcp_server_edit.tsxindex 59d7b28aacb..ee7938d2904 100644--- a/ui/litellm-dashboard/src/components/mcp_tools/mcp_server_edit.tsx+++ b/ui/litellm-dashboard/src/components/mcp_tools/mcp_server_edit.tsx@@ -131,6 +131,11 @@ const MCPServerEdit: React.FC<MCPServerEditProps> = ({}};+ // The auth mode every decision must key off: the admin's in-flight form selection wins over the+ // saved record, so authorizing, loading tools, and saving all agree with what the form shows. Paths+ // that read only mcpServer.auth_type go stale the moment the admin switches modes in the form.+ const getEffectiveAuthType = () => form.getFieldValue("auth_type") ?? mcpServer.auth_type;+const {startOAuthFlow,status: oauthStatus,@@ -178,8 +183,7 @@ const MCPServerEdit: React.FC<MCPServerEditProps> = ({return;}- const effectiveAuthType = form.getFieldValue("auth_type") ?? mcpServer.auth_type;- if (isClientForwardedTokenMode(effectiveAuthType)) {+ if (isClientForwardedTokenMode(getEffectiveAuthType())) {const browserHeldToken = {access_token: token.access_token,expires_in: token.expires_in,@@ -388,7 +392,7 @@ const MCPServerEdit: React.FC<MCPServerEditProps> = ({oauth2_flow: mcpServer.oauth2_flow,delegate_auth_to_upstream: mcpServer.delegate_auth_to_upstream,}) === "passthrough";- const isBrowserHeldTokenMode = isClientForwardedTokenMode(mcpServer.auth_type);+ const isBrowserHeldTokenMode = isClientForwardedTokenMode(getEffectiveAuthType());if (isPassthrough || isBrowserHeldTokenMode) {const token =oauthTokenResponse?.access_token ??@@ -749,8 +753,9 @@ const MCPServerEdit: React.FC<MCPServerEditProps> = ({const updated = await updateMCPServer(accessToken, payload);// Persist the token staged via "Authorize & Fetch" (mirrors the create flow's- // commit-on-submit): OBO writes the per-user token to the DB, passthrough keeps- // it in sessionStorage. M2M/static auth resolve server-side and need neither.+ // commit-on-submit): OBO writes the per-user token to the DB; legacy passthrough and the+ // client-forwarded modes (true_passthrough / oauth_delegate) keep it in sessionStorage and+ // never in the server row. M2M/static auth resolve server-side and need neither.if (oauthTokenResponse?.access_token) {const oauthMode = getMcpOAuthMode({auth_type: restValues.auth_type,@@ -767,7 +772,7 @@ const MCPServerEdit: React.FC<MCPServerEditProps> = ({scopes: typeof scope === "string" && scope ? scope.split(" ") : undefined,};await storeMCPOAuthUserCredential(accessToken, mcpServer.server_id, oauthCredentialPayload);- } else if (oauthMode === "passthrough") {+ } else if (oauthMode === "passthrough" || isClientForwardedTokenMode(restValues.auth_type)) {const browserHeldToken = {access_token: oauthTokenResponse.access_token,expires_in: oauthTokenResponse.expires_in,