-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
fix(ui): honor LITELLM_UI_API_DOC_BASE_URL on the MCP Servers Connect and Toolsets tabs #35587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bharatr21
wants to merge
1
commit into
BerriAI:litellm_internal_staging
Choose a base branch
from
bharatr21:litellm_ui_mcp_connect_doc_base_url
base: litellm_internal_staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
ui/litellm-dashboard/src/app/(dashboard)/hooks/proxySettings/useDocBaseUrl.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { resolveDocBaseUrl } from "./useDocBaseUrl"; | ||
|
|
||
| const FALLBACK = "http://proxy.internal:4000"; | ||
| const DOC_BASE = "https://gateway.public.example.com"; | ||
|
|
||
| describe("resolveDocBaseUrl", () => { | ||
| it("prefers the doc base url over the fallback when it is set", () => { | ||
| expect(resolveDocBaseUrl(DOC_BASE, FALLBACK)).toBe(DOC_BASE); | ||
| }); | ||
|
|
||
| it("falls back when the doc base url is undefined", () => { | ||
| expect(resolveDocBaseUrl(undefined, FALLBACK)).toBe(FALLBACK); | ||
| }); | ||
|
|
||
| it("falls back when the doc base url is null", () => { | ||
| expect(resolveDocBaseUrl(null, FALLBACK)).toBe(FALLBACK); | ||
| }); | ||
|
|
||
| it("falls back when the doc base url is an empty string", () => { | ||
| expect(resolveDocBaseUrl("", FALLBACK)).toBe(FALLBACK); | ||
| }); | ||
|
|
||
| it("falls back when the doc base url is whitespace only", () => { | ||
| expect(resolveDocBaseUrl(" ", FALLBACK)).toBe(FALLBACK); | ||
| }); | ||
| }); |
15 changes: 15 additions & 0 deletions
15
ui/litellm-dashboard/src/app/(dashboard)/hooks/proxySettings/useDocBaseUrl.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| "use client"; | ||
|
|
||
| import { getProxyBaseUrl } from "@/components/networking"; | ||
| import useAuthorized from "@/app/(dashboard)/hooks/useAuthorized"; | ||
| import useProxySettings from "@/app/(dashboard)/hooks/proxySettings/useProxySettings"; | ||
|
|
||
| export function resolveDocBaseUrl(docBaseUrl: string | null | undefined, fallback: string): string { | ||
| return docBaseUrl && docBaseUrl.trim() ? docBaseUrl : fallback; | ||
| } | ||
|
|
||
| export default function useDocBaseUrl(): string { | ||
| const { accessToken } = useAuthorized(); | ||
| const { LITELLM_UI_API_DOC_BASE_URL } = useProxySettings(accessToken); | ||
| return resolveDocBaseUrl(LITELLM_UI_API_DOC_BASE_URL, getProxyBaseUrl()); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/MCPToolsetsTab.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import React from "react"; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { describe, it, expect, vi } from "vitest"; | ||
| import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; | ||
| import { MCPToolsetsTab } from "./MCPToolsetsTab"; | ||
| import useProxySettings from "@/app/(dashboard)/hooks/proxySettings/useProxySettings"; | ||
|
|
||
| const DOC_BASE_URL = "https://gateway.public.example.com"; | ||
| const PROXY_BASE_URL = "http://proxy.internal:4000"; | ||
|
|
||
| vi.mock("@/components/networking", () => ({ | ||
| getProxyBaseUrl: () => PROXY_BASE_URL, | ||
| createMCPToolset: vi.fn(), | ||
| updateMCPToolset: vi.fn(), | ||
| deleteMCPToolset: vi.fn(), | ||
| listMCPTools: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@/app/(dashboard)/hooks/useAuthorized", () => ({ | ||
| default: () => ({ accessToken: "sk-test" }), | ||
| })); | ||
|
|
||
| vi.mock("@/app/(dashboard)/hooks/proxySettings/useProxySettings", () => ({ | ||
| default: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock("@/app/(dashboard)/hooks/mcpServers/useMCPToolsets", () => ({ | ||
| useMCPToolsets: () => ({ | ||
| data: [ | ||
| { | ||
| toolset_id: "ts-1", | ||
| toolset_name: "github-tools", | ||
| description: "GitHub helpers", | ||
| tools: [{ server_id: "srv-1", tool_name: "create_issue" }], | ||
| created_at: "2026-01-01T00:00:00Z", | ||
| }, | ||
| ], | ||
| isLoading: false, | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock("@/app/(dashboard)/hooks/mcpServers/useMCPServers", () => ({ | ||
| useMCPServers: () => ({ data: [{ server_id: "srv-1", alias: "github", server_name: "github" }] }), | ||
| })); | ||
|
|
||
| const mockedUseProxySettings = vi.mocked(useProxySettings); | ||
|
|
||
| function renderTab(docBaseUrl: string | null) { | ||
| mockedUseProxySettings.mockReturnValue({ | ||
| PROXY_BASE_URL, | ||
| PROXY_LOGOUT_URL: "", | ||
| LITELLM_UI_API_DOC_BASE_URL: docBaseUrl, | ||
| }); | ||
| render( | ||
| <QueryClientProvider client={new QueryClient()}> | ||
| <MCPToolsetsTab accessToken="sk-test" userRole="Admin" /> | ||
| </QueryClientProvider>, | ||
| ); | ||
| } | ||
|
|
||
| describe("MCPToolsetsTab", () => { | ||
| it("builds the usage guide and row endpoint urls from LITELLM_UI_API_DOC_BASE_URL when set", () => { | ||
| renderTab(DOC_BASE_URL); | ||
|
|
||
| expect(screen.getByText(new RegExp(`${DOC_BASE_URL}/toolset/<toolset-name>/mcp`))).toBeInTheDocument(); | ||
| expect(screen.getByText(`${DOC_BASE_URL}/toolset/github-tools/mcp`)).toBeInTheDocument(); | ||
| expect(screen.queryAllByText(/proxy\.internal/)).toHaveLength(0); | ||
| }); | ||
|
|
||
| it("falls back to the proxy base url when LITELLM_UI_API_DOC_BASE_URL is unset", () => { | ||
| renderTab(null); | ||
|
|
||
| expect(screen.getByText(new RegExp(`${PROXY_BASE_URL}/toolset/<toolset-name>/mcp`))).toBeInTheDocument(); | ||
| expect(screen.getByText(`${PROXY_BASE_URL}/toolset/github-tools/mcp`)).toBeInTheDocument(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
ui/litellm-dashboard/src/app/(dashboard)/mcp-servers/_components/mcp_connect.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import React from "react"; | ||
| import { render, screen } from "@testing-library/react"; | ||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
| import MCPConnect from "./mcp_connect"; | ||
| import useProxySettings from "@/app/(dashboard)/hooks/proxySettings/useProxySettings"; | ||
|
|
||
| vi.mock("@/components/networking", () => ({ | ||
| getProxyBaseUrl: () => "http://proxy.internal:4000", | ||
| })); | ||
|
|
||
| vi.mock("@/app/(dashboard)/hooks/useAuthorized", () => ({ | ||
| default: () => ({ accessToken: "sk-test" }), | ||
| })); | ||
|
|
||
| vi.mock("@/app/(dashboard)/hooks/proxySettings/useProxySettings", () => ({ | ||
| default: vi.fn(), | ||
| })); | ||
|
|
||
| const mockedUseProxySettings = vi.mocked(useProxySettings); | ||
|
|
||
| const proxySettings = (docBaseUrl: string | null) => ({ | ||
| PROXY_BASE_URL: "http://proxy.internal:4000", | ||
| PROXY_LOGOUT_URL: "", | ||
| LITELLM_UI_API_DOC_BASE_URL: docBaseUrl, | ||
| }); | ||
|
|
||
| describe("MCPConnect", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it("renders the Server URL from LITELLM_UI_API_DOC_BASE_URL when it is set", () => { | ||
| mockedUseProxySettings.mockReturnValue(proxySettings("https://gateway.public.example.com")); | ||
|
|
||
| render(<MCPConnect />); | ||
|
|
||
| expect(screen.getAllByText("https://gateway.public.example.com/mcp").length).toBeGreaterThan(0); | ||
| expect(screen.queryAllByText(/proxy\.internal/)).toHaveLength(0); | ||
| }); | ||
|
|
||
| it("renders the Server URL from the proxy base url when LITELLM_UI_API_DOC_BASE_URL is unset", () => { | ||
| mockedUseProxySettings.mockReturnValue(proxySettings(null)); | ||
|
|
||
| render(<MCPConnect />); | ||
|
|
||
| expect(screen.getAllByText("http://proxy.internal:4000/mcp").length).toBeGreaterThan(0); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
LITELLM_UI_API_DOC_BASE_URLcontains surrounding whitespace or a trailing slash, this returns the raw value and the changed consumers append paths directly, producing copied endpoints such ashttps://gateway.example.com/mcporhttps://gateway.example.com//toolset/name/mcpthat clients can reject or route incorrectly.Knowledge Base Used: Admin dashboard (ui/litellm-dashboard)