Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: handle mcp no found (#21278)

ecmadaof79ba544180f
diff --git a/frontend/src/routes/workspace/mcp/MCPAccessPolicySection.test.tsx b/frontend/src/routes/workspace/mcp/MCPAccessPolicySection.test.tsx
index 24bb4f77f1..7e12d37bc9 100644
--- a/frontend/src/routes/workspace/mcp/MCPAccessPolicySection.test.tsx
+++ b/frontend/src/routes/workspace/mcp/MCPAccessPolicySection.test.tsx
@@ -1,7 +1,12 @@
import type { ReactElement } from "react";
import { act } from "react";
import { createRoot } from "react-dom/client";
+import { Code, ConnectError } from "@connectrpc/connect";
import { beforeEach, describe, expect, test, vi } from "vitest";
+import {
+ MCPSetting_Capability,
+ type Setting,
+} from "@/types/proto-es/v1/setting_service_pb";
(
globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
@@ -15,6 +20,7 @@ const mocks = vi.hoisted(() => ({
upsertSetting: vi.fn(),
hasFeature: vi.fn(() => true),
sheetProps: [] as Record<string, unknown>[],
+ settingsByName: { value: {} as Record<string, Setting> },
mcpSetting: {
value: undefined as
| {
@@ -55,12 +61,23 @@ vi.mock("@/stores", () => ({ pushNotification: vi.fn() }));
vi.mock("@/stores/app", () => {
const state = {
- settingsByName: {},
+ get settingsByName() {
+ return mocks.settingsByName.value;
+ },
getSettingByName: () =>
mocks.mcpSetting.value === undefined
? undefined
: { value: { value: { case: "mcp", value: mocks.mcpSetting.value } } },
- setSettingByName: mocks.setSettingByName,
+ setSettingByName: (setting: Setting) => {
+ mocks.setSettingByName(setting);
+ mocks.settingsByName.value = {
+ ...mocks.settingsByName.value,
+ [setting.name]: setting,
+ };
+ if (setting.value?.value?.case === "mcp") {
+ mocks.mcpSetting.value = setting.value.value.value;
+ }
+ },
upsertSetting: mocks.upsertSetting,
hasFeature: mocks.hasFeature,
};
@@ -122,6 +139,7 @@ const clickText = (container: HTMLElement, text: string) => {
beforeEach(async () => {
vi.clearAllMocks();
mocks.sheetProps.length = 0;
+ mocks.settingsByName.value = {};
mocks.mcpSetting.value = {
capability: 3, // READ_ONLY
ignoreMaskingExemptions: false,
@@ -189,6 +207,60 @@ describe("MCPAccessPolicySection", () => {
unmount();
});
+ test("a missing row uses the READ_WRITE compatibility default", async () => {
+ mocks.getSetting.mockRejectedValue(
+ new ConnectError("setting MCP not found", Code.NotFound)
+ );
+ const { container, render, unmount } = renderIntoContainer(
+ <MCPAccessPolicySection />
+ );
+ render();
+ await flush();
+
+ expect(mocks.setSettingByName).toHaveBeenCalledWith(
+ expect.objectContaining({
+ name: "settings/MCP",
+ value: expect.objectContaining({
+ value: expect.objectContaining({
+ case: "mcp",
+ value: expect.objectContaining({
+ capability: MCPSetting_Capability.READ_WRITE,
+ ignoreMaskingExemptions: false,
+ }),
+ }),
+ }),
+ })
+ );
+ expect(container.textContent).toContain("settings.mcp.policy.in-force");
+ expect(container.textContent).not.toContain(
+ "settings.mcp.policy.read-failed.title"
+ );
+
+ clickText(container, "settings.mcp.policy.edit");
+ await flush();
+ toggleMasking(container);
+ await flush();
+ clickText(container, "settings.mcp.policy.save");
+ await flush();
+
+ expect(mocks.upsertSetting).toHaveBeenCalledWith(
+ expect.objectContaining({
+ value: expect.objectContaining({
+ value: expect.objectContaining({
+ value: expect.objectContaining({
+ capability: MCPSetting_Capability.READ_WRITE,
+ }),
+ }),
+ }),
+ updateMask: expect.objectContaining({
+ paths: ["value.mcp.ignore_masking_exemptions"],
+ }),
+ })
+ );
+
+ unmount();
+ });
+
test("repairs an unspecified capability without a frontend fallback", async () => {
mocks.mcpSetting.value = {
capability: 0,
diff --git a/frontend/src/routes/workspace/mcp/MCPAccessPolicySection.tsx b/frontend/src/routes/workspace/mcp/MCPAccessPolicySection.tsx
index 8353f62bdd..0ce00129f2 100644
--- a/frontend/src/routes/workspace/mcp/MCPAccessPolicySection.tsx
+++ b/frontend/src/routes/workspace/mcp/MCPAccessPolicySection.tsx
@@ -1,6 +1,6 @@
import { create } from "@bufbuild/protobuf";
import { FieldMaskSchema } from "@bufbuild/protobuf/wkt";
-import { createContextValues } from "@connectrpc/connect";
+import { Code, ConnectError, createContextValues } from "@connectrpc/connect";
import { Rows3 } from "lucide-react";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
@@ -29,6 +29,7 @@ import {
MCPSetting_Capability,
MCPSettingSchema,
Setting_SettingName,
+ SettingSchema,
SettingValueSchema,
} from "@/types/proto-es/v1/setting_service_pb";
import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";
@@ -59,6 +60,8 @@ const MODES: Record<
},
};
+const mcpSettingName = `${settingNamePrefix}${Setting_SettingName[Setting_SettingName.MCP]}`;
+
export function MCPAccessPolicySection() {
const { t } = useTranslation();
@@ -150,7 +153,7 @@ export function MCPAccessPolicySection() {
settingServiceClientConnect
.getSetting(
{
- name: `${settingNamePrefix}${Setting_SettingName[Setting_SettingName.MCP]}`,
+ name: mcpSettingName,
},
{
contextValues: createContextValues().set(silentContextKey, true),
@@ -166,10 +169,32 @@ export function MCPAccessPolicySection() {
useAppStore.getState().setSettingByName(setting);
settle(false);
})
- // A row this build cannot unmarshal fails this read. The store may still
- // hold a value from an earlier visit, and rendering that would report a
- // ceiling nobody is enforcing — the failure outranks it below.
- .catch(() => settle(true));
+ .catch((error: unknown) => {
+ if (generation !== settingGeneration.current) {
+ return;
+ }
+ // Older workspaces can legitimately have no row. Match the backend's
+ // effective READ_WRITE policy; all other read failures still win over
+ // any value left in the frontend store.
+ if (error instanceof ConnectError && error.code === Code.NotFound) {
+ useAppStore.getState().setSettingByName(
+ create(SettingSchema, {
+ name: mcpSettingName,
+ value: create(SettingValueSchema, {
+ value: {
+ case: "mcp",
+ value: create(MCPSettingSchema, {
+ capability: MCPSetting_Capability.READ_WRITE,
+ }),
+ },
+ }),
+ })
+ );
+ settle(false);
+ return;
+ }
+ settle(true);
+ });
loadInfo();
// Retire both reads when this instance goes away. The generations are this
// mount's; the setting store they write is the application's.