fix(mcp): refresh expired OAuth tokens automatically (#5573)

* fix(mcp): refresh expired OAuth tokens

* fix(mcp): bind refreshed tokens to OAuth issuer

* fix(mcp): activate OAuth tools before probe cleanup

* fix(webui): preserve failed MCP OAuth status

* fix(mcp): preserve OAuth refresh across discovery retries

* test(mcp): align OAuth issuer fixture with SDK validation
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-10 13:27:50 +08:00
1 parent 6a8647cfb6
commit 55093dd75b
8 files changed
+1174 -60

No files matched your search

@@ -545,7 +545,7 @@ function McpAppsCatalogRow({
const readyInstalled = preset.enabled ?? configuredInstalled;
const runtimeConnected = !toggleable && preset.runtime_status === "connected";
const runtimeConnecting = !toggleable && preset.runtime_status === "connecting";
const runtimeFailed = !toggleable && preset.runtime_status === "failed";
const runtimeFailed = !toggleable && preset.installed && preset.runtime_status === "failed";
const statusLabel = toggleable
? tx("settings.nanobotFeatures.enabled", "Enabled")
: runtimeConnected
@@ -601,14 +601,14 @@ function McpAppsCatalogRow({
<p
className={cn(
"mt-0.5 flex min-w-0 items-center gap-1.5 text-[12.5px] leading-5 text-muted-foreground",
runtimeFailed && configuredInstalled && "font-medium text-destructive",
runtimeFailed && "font-medium text-destructive",
)}
>
{runtimeFailed && configuredInstalled ? (
{runtimeFailed ? (
<TriangleAlert className="h-3.5 w-3.5 shrink-0" aria-hidden />
) : null}
<span className="truncate">
{runtimeFailed && configuredInstalled ? failureLabel : detail}
{runtimeFailed ? failureLabel : detail}
</span>
</p>
</div>
@@ -647,7 +647,7 @@ function McpAppsCatalogRow({
<Trash2 className="h-4 w-4" aria-hidden />
</AppsActionButton>
</>
) : runtimeFailed && configuredInstalled ? (
) : runtimeFailed ? (
<AppsActionButton
ariaLabel={t("settings.mcp.manageTitle", {
name: preset.display_name,
@@ -857,7 +857,7 @@ function McpAppsCatalogRow({
preset={preset}
values={values}
actionKey={actionKey}
statusLabel={runtimeFailed && configuredInstalled ? failureStatusLabel : statusLabel}
statusLabel={runtimeFailed ? failureStatusLabel : statusLabel}
statusTone={runtimeFailed ? "warning" : configuredInstalled ? "success" : "neutral"}
tab={managementTab}
icon={<McpPresetLogo preset={preset} showBrandLogos={showBrandLogos} compact />}
@@ -200,6 +200,40 @@ describe("SettingsView Apps catalog", () => {
await act(() => i18n.changeLanguage("en"));
});
it("keeps an OAuth runtime failure visible after credentials are cleared", async () => {
const failedPreset = {
...xmindMcpPreset,
installed: true,
configured: false,
available: false,
status: "authorization_required",
runtime_status: "failed",
connection_summary: "https://app.xmind.com/api/mcp",
};
const fetchMock = vi.fn(async (input: RequestInfo | URL) => {
const url = String(input);
if (url === "/api/settings") return jsonResponse(settingsPayload());
if (url === "/api/settings/cli-apps") {
return jsonResponse({ apps: [], installed_count: 0 });
}
if (url === "/api/settings/mcp-presets") {
return jsonResponse({ presets: [failedPreset], installed_count: 1 });
}
return { ok: false, status: 404, text: async () => "Not found" } as Response;
});
vi.stubGlobal("fetch", fetchMock);
renderSettingsView({ initialSection: "apps" });
fireEvent.click(await screen.findByRole("button", { name: "MCP" }));
const heading = await screen.findByRole("heading", { name: "Xmind" });
const row = heading.closest("article");
expect(row).not.toBeNull();
expect(within(row as HTMLElement).getByText("Connection failed.")).toBeInTheDocument();
expect(within(row as HTMLElement).getByRole("button", { name: "Manage Xmind" }))
.toHaveTextContent("Fix connection");
});
it("refreshes a connecting MCP snapshot until the runtime attempt settles", async () => {
const connectingPreset = {
...xmindMcpPreset,