Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
}));

vi.mock("./mcp_connection_status", () => ({
default: ({ tools }: { tools?: any[] }) => (

Check warning on line 83 in ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.test.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Unexpected any. Specify a different type
<div data-testid="mcp-connection-status" data-tool-count={tools?.length ?? 0} />
),
}));
Expand Down Expand Up @@ -1067,6 +1067,22 @@
const reopenedUrlInput = screen.getByPlaceholderText("https://your-mcp-server.com") as HTMLInputElement;
expect(reopenedUrlInput.value).toBe("");
});

it("does not reset an in-flight OAuth resume when mounted with the modal closed (post-redirect restore)", () => {
// After the "Authorize & Fetch Token" redirect the page reloads and this
// component mounts with isModalVisible=false while useMcpOAuthFlow is still
// exchanging the authorization code. Calling reset() during that mount bumps
// the hook's reset version and the fetched token is silently discarded, so
// the user sees no Connection Status / Tool Configuration and must authorize
// again after saving.
const { rerender } = render(<CreateMCPServer {...defaultProps} isModalVisible={false} />);
expect(oauthHook.reset).not.toHaveBeenCalled();

// A real open -> closed transition must still reset (the #30000 leak fix).
rerender(<CreateMCPServer {...defaultProps} isModalVisible={true} />);
rerender(<CreateMCPServer {...defaultProps} isModalVisible={false} />);
expect(oauthHook.reset).toHaveBeenCalled();
});
});

describe("when stdio transport is selected", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
const [form] = Form.useForm();
const [isLoading, setIsLoading] = useState(false);
const [costConfig, setCostConfig] = useState<MCPServerCostInfo>({});
const [formValues, setFormValues] = useState<Record<string, any>>({});

Check warning on line 83 in ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Unexpected any. Specify a different type
const [pendingRestoredValues, setPendingRestoredValues] = useState<{
values: Record<string, any>;

Check warning on line 85 in ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Unexpected any. Specify a different type
transport?: string;
} | null>(null);
const [aliasManuallyEdited, setAliasManuallyEdited] = useState(false);
Expand Down Expand Up @@ -302,7 +302,7 @@
const transport = prefillData.transport || "";
setTransportType(transport);

const prefillValues: Record<string, any> = {

Check warning on line 305 in ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Unexpected any. Specify a different type
server_name: sanitizedName,
alias: sanitizedName,
description: prefillData.description || "",
Expand All @@ -310,7 +310,7 @@
};

if (transport === "stdio") {
const stdioObj: Record<string, any> = {};

Check warning on line 313 in ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Unexpected any. Specify a different type
if (prefillData.command) stdioObj.command = prefillData.command;
if (prefillData.args && prefillData.args.length > 0) stdioObj.args = prefillData.args;
if (prefillData.env_vars && prefillData.env_vars.length > 0) {
Expand All @@ -332,7 +332,7 @@
setAliasManuallyEdited(false);
}, [isModalVisible, prefillData, form]);

const handleCreate = async (values: Record<string, any>) => {

Check warning on line 335 in ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Async arrow function has a complexity of 40. Maximum allowed is 20

Check warning on line 335 in ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Unexpected any. Specify a different type
const invalidDisplayName = Object.entries(toolNameToDisplayName).find(
([, displayName]) => displayName && !TOOL_DISPLAY_NAME_PATTERN.test(displayName),
);
Expand Down Expand Up @@ -365,7 +365,7 @@

const credentialsPayload =
credentialValues && typeof credentialValues === "object"
? Object.entries(credentialValues).reduce((acc: Record<string, any>, [key, value]) => {

Check warning on line 368 in ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Unexpected any. Specify a different type
if (value === undefined || value === null || value === "") {
return acc;
}
Expand Down Expand Up @@ -398,12 +398,12 @@
// If it's the full mcpServers structure, extract the first server config
if (stdioConfig.mcpServers && typeof stdioConfig.mcpServers === "object") {
const serverNames = Object.keys(stdioConfig.mcpServers);
if (serverNames.length > 0) {

Check warning on line 401 in ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Blocks are nested too deeply (5). Maximum allowed is 4
const firstServerName = serverNames[0];
actualConfig = stdioConfig.mcpServers[firstServerName];

// If no alias is provided, use the server name from the JSON
if (!restValues.server_name) {

Check warning on line 406 in ui/litellm-dashboard/src/components/mcp_tools/create_mcp_server.tsx

View workflow job for this annotation

GitHub Actions / frontend-lint

Blocks are nested too deeply (6). Maximum allowed is 4
restValues.server_name = firstServerName.replace(/-/g, "_"); // Replace hyphens with underscores
}
}
Expand Down Expand Up @@ -626,9 +626,15 @@
// Clear form, tools, and OAuth state when the modal closes so a previous server's
// authorization, credentials, or tool list never bleed into the next "Add New MCP
// Server" session, including when a parent dismisses the modal without routing
// through handleCancel or handleCreate.
// through handleCancel or handleCreate. Only a real open -> closed transition may
// trigger this: on the post-OAuth-redirect remount the modal starts closed while
// resumeOAuthFlow's token exchange is in flight, and resetting then discards the
// fetched token.
const wasModalVisibleRef = React.useRef(isModalVisible);
React.useEffect(() => {
if (!isModalVisible) {
const wasVisible = wasModalVisibleRef.current;
wasModalVisibleRef.current = isModalVisible;
if (!isModalVisible && wasVisible) {
form.resetFields();
setFormValues({});
setOauthAccessToken(null);
Expand Down
Loading