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]

feat(ui): browser-only Authorize & Fetch for the client-forwarded token modes

Tin22ab51807171
diff --git a/litellm/proxy/_experimental/mcp_server/rest_endpoints.py b/litellm/proxy/_experimental/mcp_server/rest_endpoints.py
index b917530dd52..21682b4dd3e 100644
--- a/litellm/proxy/_experimental/mcp_server/rest_endpoints.py
+++ b/litellm/proxy/_experimental/mcp_server/rest_endpoints.py
@@ -1322,7 +1322,11 @@ if MCP_AVAILABLE:
mcp_auth_header = credentials.get("auth_value")
oauth2_headers: Optional[Dict[str, str]] = None
- if new_mcp_server_request.auth_type == MCPAuth.oauth2:
+ if new_mcp_server_request.auth_type in {
+ MCPAuth.oauth2,
+ MCPAuth.true_passthrough,
+ MCPAuth.oauth_delegate,
+ }:
oauth2_headers = MCPRequestHandler._get_oauth2_headers_from_headers(headers)
async def _list_tools_operation(client):
diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/test_rest_endpoints.py b/tests/test_litellm/proxy/_experimental/mcp_server/test_rest_endpoints.py
index 3d9afd8f250..090b4711dc9 100644
--- a/tests/test_litellm/proxy/_experimental/mcp_server/test_rest_endpoints.py
+++ b/tests/test_litellm/proxy/_experimental/mcp_server/test_rest_endpoints.py
@@ -593,6 +593,59 @@ class TestTestToolsList:
assert captured["oauth2_headers"] == oauth_headers
assert oauth_call_counter["count"] == 1
+ @pytest.mark.parametrize("auth_type", [MCPAuth.true_passthrough, MCPAuth.oauth_delegate])
+ async def test_extracts_oauth2_headers_for_client_forwarded_modes(self, monkeypatch, auth_type):
+ """The browser-only authorize flow sends the upstream token as Authorization; the preview
+ must thread it through for the client-forwarded token modes so the passthrough arm can
+ forward it, instead of probing the upstream unauthenticated."""
+
+ captured: dict = {}
+
+ async def fake_execute(
+ request,
+ operation,
+ mcp_auth_header=None,
+ oauth2_headers=None,
+ raw_headers=None,
+ ):
+ captured["mcp_auth_header"] = mcp_auth_header
+ captured["oauth2_headers"] = oauth2_headers
+ return {
+ "tools": [],
+ "error": None,
+ "message": "Successfully retrieved tools",
+ }
+
+ monkeypatch.setattr(rest_endpoints, "_execute_with_mcp_client", fake_execute, raising=False)
+
+ oauth_headers = {"Authorization": "Bearer upstream-token"}
+
+ monkeypatch.setattr(
+ auth_mcp.MCPRequestHandler,
+ "_get_oauth2_headers_from_headers",
+ staticmethod(lambda headers: oauth_headers),
+ raising=False,
+ )
+
+ request = _build_request({"authorization": "Bearer upstream-token"})
+ payload = NewMCPServerRequest(
+ server_name="example",
+ url="https://example.com",
+ auth_type=auth_type,
+ )
+
+ from litellm.proxy._types import LitellmUserRoles
+
+ result = await rest_endpoints.test_tools_list(
+ request,
+ payload,
+ user_api_key_dict=UserAPIKeyAuth(user_role=LitellmUserRoles.PROXY_ADMIN),
+ )
+
+ assert result["message"] == "Successfully retrieved tools"
+ assert captured["mcp_auth_header"] is None
+ assert captured["oauth2_headers"] == oauth_headers
+
class TestListToolsRestAPI:
pytestmark = pytest.mark.asyncio
diff --git a/ui/litellm-dashboard/src/components/mcp_tools/PassthroughAuthorizeSection.tsx b/ui/litellm-dashboard/src/components/mcp_tools/PassthroughAuthorizeSection.tsx
new file mode 100644
index 00000000000..453e3024000
--- /dev/null
+++ b/ui/litellm-dashboard/src/components/mcp_tools/PassthroughAuthorizeSection.tsx
@@ -0,0 +1,74 @@
+import React from "react";
+import { Button, Form, Input } from "antd";
+import { AUTH_TYPE } from "./types";
+
+interface PassthroughOAuthFlow {
+ startOAuthFlow: () => void | Promise<void>;
+ status: string;
+ error: string | null;
+ tokenResponse: { access_token?: string; expires_in?: number } | null;
+}
+
+/**
+ * Browser-only Authorize & Fetch for the client-forwarded token modes
+ * (true_passthrough / oauth_delegate). LiteLLM never stores upstream
+ * credentials for these modes, so the token obtained here lives in this
+ * browser session only: it is forwarded per-server for the tools preview and
+ * allowlist configuration, and is never written to the server row or the
+ * per-user credential store. The optional client credentials cover IdPs
+ * without dynamic client registration (e.g. a pre-registered Slack app) and
+ * ride the temporary authorize session only.
+ */
+export default function PassthroughAuthorizeSection({
+ authType,
+ oauthFlow,
+}: {
+ authType?: string | null;
+ oauthFlow: PassthroughOAuthFlow;
+}) {
+ if (authType !== AUTH_TYPE.TRUE_PASSTHROUGH && authType !== AUTH_TYPE.OAUTH_DELEGATE) return null;
+ return (
+ <div className="rounded-lg border border-dashed border-gray-300 p-4 space-y-2 mb-4">
+ <p className="text-sm text-gray-600">
+ Callers bring their own upstream token for this auth type, so LiteLLM stores no upstream credentials. To preview
+ tools and configure the tool allowlist, authorize against the upstream here: the token stays in this browser
+ session only and is never saved to LiteLLM.
+ </p>
+ <Form.Item
+ label={<span className="text-sm font-medium text-gray-700">OAuth Client ID (optional, not saved)</span>}
+ name={["credentials", "client_id"]}
+ extra="Only needed when the upstream does not support dynamic client registration (e.g. a pre-registered Slack app). Used for this browser authorization only."
+ >
+ <Input.Password
+ placeholder="Leave blank to use dynamic client registration"
+ className="rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500"
+ />
+ </Form.Item>
+ <Form.Item
+ label={<span className="text-sm font-medium text-gray-700">OAuth Client Secret (optional, not saved)</span>}
+ name={["credentials", "client_secret"]}
+ >
+ <Input.Password
+ placeholder="Leave blank for public clients / PKCE"
+ className="rounded-lg border-gray-300 focus:border-blue-500 focus:ring-blue-500"
+ />
+ </Form.Item>
+ <Button
+ onClick={oauthFlow.startOAuthFlow}
+ disabled={oauthFlow.status === "authorizing" || oauthFlow.status === "exchanging"}
+ >
+ {oauthFlow.status === "authorizing"
+ ? "Waiting for authorization..."
+ : oauthFlow.status === "exchanging"
+ ? "Exchanging authorization code..."
+ : "Authorize & Fetch Tools (browser-only)"}
+ </Button>
+ {oauthFlow.error && <p className="text-sm text-red-500">{oauthFlow.error}</p>}
+ {oauthFlow.status === "success" && oauthFlow.tokenResponse?.access_token && (
+ <p className="text-sm text-green-600">
+ Token held for this browser session. Tools can now be previewed and configured; nothing was saved to LiteLLM.
+ </p>
+ )}
+ </div>
+ );
+}
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 27e6d6a8e3d..ca94aae20e9 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
@@ -189,6 +189,32 @@ describe("CreateMCPServer", () => {
).not.toBeInTheDocument();
});
+ it.each([["True Passthrough (no LiteLLM auth)"], ["OAuth Delegate (client-supplied upstream token)"]])(
+ "should show the browser-only authorize section when %s is selected",
+ async (optionLabel) => {
+ await selectHttpTransport();
+
+ await selectAntOption("Authentication", optionLabel);
+
+ await waitFor(() => {
+ expect(screen.getByRole("button", { name: "Authorize & Fetch Tools (browser-only)" })).toBeInTheDocument();
+ });
+ expect(screen.getByText("OAuth Client ID (optional, not saved)")).toBeInTheDocument();
+ expect(screen.getByText("OAuth Client Secret (optional, not saved)")).toBeInTheDocument();
+ },
+ );
+
+ it("should not show the browser-only authorize section for API Key auth", async () => {
+ await selectHttpTransport();
+
+ await selectAntOption("Authentication", "API Key");
+
+ await waitFor(() => {
+ expect(screen.getByText("Authentication Value")).toBeInTheDocument();
+ });
+ expect(screen.queryByRole("button", { name: "Authorize & Fetch Tools (browser-only)" })).not.toBeInTheDocument();
+ });
+
it("should not require auth value when creating a server with API Key auth type", async () => {
await selectHttpTransport();
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 1362835f475..b123e3397a1 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
@@ -17,6 +17,7 @@ import {
} from "./types";
import OAuthFormFields from "./OAuthFormFields";
import TruePassthroughWarning from "./TruePassthroughWarning";
+import PassthroughAuthorizeSection from "./PassthroughAuthorizeSection";
import TokenExchangeFormFields from "./TokenExchangeFormFields";
import MCPServerCostConfig from "./mcp_server_cost_config";
import MCPConnectionStatus from "./mcp_connection_status";
@@ -980,6 +981,16 @@ const CreateMCPServer: React.FC<CreateMCPServerProps> = ({
<TruePassthroughWarning authType={authType} />
+ <PassthroughAuthorizeSection
+ authType={authType}
+ oauthFlow={{
+ startOAuthFlow,
+ status: oauthStatus,
+ error: oauthError,
+ tokenResponse: oauthTokenResponse,
+ }}
+ />
+
{shouldShowAuthValueField && (
<Form.Item
label={
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.tsx
index cf07dccea66..f071e247466 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
@@ -922,6 +922,55 @@ describe("MCPServerEdit (tool list fetch)", () => {
expect(mockGetToken).toHaveBeenCalledWith("oauth_server_1", "user-1");
});
+ it("forwards the sessionStorage token as the x-mcp header for an oauth_delegate server", async () => {
+ mockIsTokenValid.mockReturnValue(true);
+ mockGetToken.mockReturnValue({ access_token: "browser-token" });
+
+ render(
+ <MCPServerEdit
+ mcpServer={{ ...interactiveOAuthServer, auth_type: "oauth_delegate" }}
+ accessToken="access-token"
+ userID="user-1"
+ onCancel={vi.fn()}
+ onSuccess={vi.fn()}
+ availableAccessGroups={[]}
+ />,
+ );
+
+ await waitFor(() => {
+ expect(networking.listMCPTools).toHaveBeenCalledWith(
+ "access-token",
+ "oauth_server_1",
+ { "x-mcp-oauth_server-authorization": "Bearer browser-token" },
+ true,
+ );
+ });
+ expect(mockGetToken).toHaveBeenCalledWith("oauth_server_1", "user-1");
+ });
+
+ it("prompts for the browser-only authorize when a true_passthrough server has no token", async () => {
+ mockIsTokenValid.mockReturnValue(false);
+
+ render(
+ <MCPServerEdit
+ mcpServer={{ ...interactiveOAuthServer, auth_type: "true_passthrough" }}
+ accessToken="access-token"
+ userID="user-1"
+ onCancel={vi.fn()}
+ onSuccess={vi.fn()}
+ availableAccessGroups={[]}
+ />,
+ );
+
+ await waitFor(() => {
+ expect(screen.getByTestId("mcp-tool-config").getAttribute("data-external-error")).toContain(
+ "Authorize with the upstream (browser-only",
+ );
+ });
+ expect(networking.listMCPTools).not.toHaveBeenCalled();
+ expect(screen.getByRole("button", { name: "Authorize & Fetch Tools (browser-only)" })).toBeInTheDocument();
+ });
+
it("uses the staged OAuth token to load passthrough tools after authorize", async () => {
const passthroughServer = { ...interactiveOAuthServer, delegate_auth_to_upstream: true };
mockIsTokenValid.mockReturnValue(false);
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.tsx
index 2c4f674c14b..ee67ead8121 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
@@ -19,6 +19,7 @@ import { buildMcpPassthroughAuthHeader } from "@/utils/mcpHeaderUtils";
import MCPServerCostConfig from "./mcp_server_cost_config";
import MCPPermissionManagement from "./MCPPermissionManagement";
import TruePassthroughWarning from "./TruePassthroughWarning";
+import PassthroughAuthorizeSection from "./PassthroughAuthorizeSection";
import MCPToolConfiguration from "./mcp_tool_configuration";
import StdioConfiguration from "./StdioConfiguration";
import TokenExchangeFormFields from "./TokenExchangeFormFields";
@@ -172,20 +173,40 @@ const MCPServerEdit: React.FC<MCPServerEditProps> = ({
};
},
onTokenReceived: (token) => {
- if (token?.access_token) {
- const credentials = {
- access_token: token.access_token,
- ...(token.refresh_token && { refresh_token: token.refresh_token }),
- ...(token.expires_in && { expires_in: token.expires_in }),
- ...(token.scope && { scope: token.scope }),
- };
-
- form.setFieldsValue({ credentials });
+ if (!token?.access_token) {
+ return;
+ }
+ const effectiveAuthType = form.getFieldValue("auth_type") ?? mcpServer.auth_type;
+ if (effectiveAuthType === AUTH_TYPE.TRUE_PASSTHROUGH || effectiveAuthType === AUTH_TYPE.OAUTH_DELEGATE) {
+ setToken(
+ mcpServer.server_id,
+ {
+ access_token: token.access_token,
+ expires_in: token.expires_in,
+ refresh_token: token.refresh_token,
+ token_type: token.token_type,
+ },
+ userID,
+ );
NotificationsManager.success(
- "OAuth authorization successful! Please click 'Update MCP Server' to save the credentials.",
+ "Token held for this browser session. Tools can now be loaded and configured; nothing was saved to LiteLLM.",
);
+ return;
}
+
+ const credentials = {
+ access_token: token.access_token,
+ ...(token.refresh_token && { refresh_token: token.refresh_token }),
+ ...(token.expires_in && { expires_in: token.expires_in }),
+ ...(token.scope && { scope: token.scope }),
+ };
+
+ form.setFieldsValue({ credentials });
+
+ NotificationsManager.success(
+ "OAuth authorization successful! Please click 'Update MCP Server' to save the credentials.",
+ );
},
onBeforeRedirect: persistEditUiState,
flowSource: "edit",
@@ -369,7 +390,9 @@ const MCPServerEdit: React.FC<MCPServerEditProps> = ({
oauth2_flow: mcpServer.oauth2_flow,
delegate_auth_to_upstream: mcpServer.delegate_auth_to_upstream,
}) === "passthrough";
- if (isPassthrough) {
+ const isBrowserHeldTokenMode =
+ mcpServer.auth_type === AUTH_TYPE.TRUE_PASSTHROUGH || mcpServer.auth_type === AUTH_TYPE.OAUTH_DELEGATE;
+ if (isPassthrough || isBrowserHeldTokenMode) {
const token =
oauthTokenResponse?.access_token ??
(isTokenValid(mcpServer.server_id, userID)
@@ -377,7 +400,11 @@ const MCPServerEdit: React.FC<MCPServerEditProps> = ({
: null);
if (!token) {
setTools([]);
- setToolsError("Authenticate with this server in the Tools tab to load and configure its tools.");
+ setToolsError(
+ isBrowserHeldTokenMode
+ ? "Authorize with the upstream (browser-only, in the Authentication section) to load and configure this server's tools."
+ : "Authenticate with this server in the Tools tab to load and configure its tools.",
+ );
return;
}
customHeaders = buildMcpPassthroughAuthHeader(mcpServer.alias, token);
@@ -893,6 +920,15 @@ const MCPServerEdit: React.FC<MCPServerEditProps> = ({
</Select>
</Form.Item>
<TruePassthroughWarning authType={authType} />
+ <PassthroughAuthorizeSection
+ authType={authType}
+ oauthFlow={{
+ startOAuthFlow,
+ status: oauthStatus,
+ error: oauthError,
+ tokenResponse: oauthTokenResponse,
+ }}
+ />
</>
)}
diff --git a/ui/litellm-dashboard/src/hooks/useTestMCPConnection.tsx b/ui/litellm-dashboard/src/hooks/useTestMCPConnection.tsx
index 055e15350ca..3208b6b02b2 100644
--- a/ui/litellm-dashboard/src/hooks/useTestMCPConnection.tsx
+++ b/ui/litellm-dashboard/src/hooks/useTestMCPConnection.tsx
@@ -56,7 +56,9 @@ export const useTestMCPConnection = ({
// Check if we have the minimum required fields to fetch tools
const isM2MOAuth = formValues.auth_type === AUTH_TYPE.OAUTH2 && formValues.oauth_flow_type === OAUTH_FLOW.M2M;
- const requiresOAuthToken = formValues.auth_type === AUTH_TYPE.OAUTH2 && !isM2MOAuth;
+ const isBrowserHeldTokenMode =
+ formValues.auth_type === AUTH_TYPE.TRUE_PASSTHROUGH || formValues.auth_type === AUTH_TYPE.OAUTH_DELEGATE;
+ const requiresOAuthToken = (formValues.auth_type === AUTH_TYPE.OAUTH2 && !isM2MOAuth) || isBrowserHeldTokenMode;
const isOpenAPITransport = formValues.transport === TRANSPORT.OPENAPI;
const hasEndpoint = isOpenAPITransport ? !!formValues.spec_path : !!formValues.url;