feat(mcp): add global query timeout override
This commit is contained in:
1 parent
7ba30ae761
commit
e6f8b2187a
24 files changed
+615
-35
No files matched your search
@@ -2053,6 +2053,31 @@ const mcpInstallError = ref(false);
|
||||
const mcpExecutionMode = computed(() => mcpExecutionModeFromPolicy(settingsStore.mcpGlobalPolicy));
|
||||
const mcpExecutionModeOptions: McpExecutionMode[] = ["read_only", "safe_write", "high_risk_write"];
|
||||
const mcpAllowedConnectionIds = computed(() => settingsStore.mcpGlobalPolicy.allowedConnectionIds);
|
||||
const mcpQueryTimeoutInput = ref<string>(settingsStore.mcpGlobalPolicy.queryTimeoutSecs === null ? "" : String(settingsStore.mcpGlobalPolicy.queryTimeoutSecs));
|
||||
|
||||
watch(
|
||||
() => settingsStore.mcpGlobalPolicy.queryTimeoutSecs,
|
||||
(value) => {
|
||||
mcpQueryTimeoutInput.value = value === null ? "" : String(value);
|
||||
},
|
||||
);
|
||||
|
||||
function onMcpQueryTimeoutInput() {
|
||||
const raw = mcpQueryTimeoutInput.value.trim();
|
||||
if (raw === "") {
|
||||
void saveMcpPolicy({ queryTimeoutSecs: null });
|
||||
return;
|
||||
}
|
||||
const parsed = Number(raw);
|
||||
// Backend stores the value as u64; keep out-of-range integers on the
|
||||
// invalid-value path instead of failing serde later with a generic error.
|
||||
if (!Number.isFinite(parsed) || parsed < 0 || !Number.isInteger(parsed) || parsed > Number("18446744073709551615")) {
|
||||
toast(t("settings.mcpQueryTimeoutInvalid"), 5000);
|
||||
mcpQueryTimeoutInput.value = settingsStore.mcpGlobalPolicy.queryTimeoutSecs === null ? "" : String(settingsStore.mcpGlobalPolicy.queryTimeoutSecs);
|
||||
return;
|
||||
}
|
||||
void saveMcpPolicy({ queryTimeoutSecs: parsed });
|
||||
}
|
||||
const mcpSelectableConnections = computed(() => connectionStore.connections);
|
||||
const mcpPolicyControlsDisabled = computed(() =>
|
||||
isMcpPolicyMutationBlocked({
|
||||
@@ -2062,7 +2087,7 @@ const mcpPolicyControlsDisabled = computed(() =>
|
||||
}),
|
||||
);
|
||||
|
||||
async function saveMcpPolicy(partial: { readOnly?: boolean; allowDangerousSql?: boolean; allowedConnectionIds?: string[] | null }) {
|
||||
async function saveMcpPolicy(partial: { readOnly?: boolean; allowDangerousSql?: boolean; allowedConnectionIds?: string[] | null; queryTimeoutSecs?: number | null }) {
|
||||
if (mcpPolicyControlsDisabled.value) return;
|
||||
mcpPolicySaving.value = true;
|
||||
try {
|
||||
@@ -7189,6 +7214,15 @@ onUnmounted(() => {
|
||||
<span>{{ t("settings.mcpExecutionModeHighRiskWriteDescription") }}</span>
|
||||
</p>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<div class="space-y-0.5">
|
||||
<Label id="mcp-query-timeout-label">{{ t("settings.mcpQueryTimeout") }}</Label>
|
||||
<p class="text-[11px] text-muted-foreground">
|
||||
{{ t("settings.mcpQueryTimeoutDescription") }}
|
||||
</p>
|
||||
</div>
|
||||
<Input id="mcp-query-timeout" v-model="mcpQueryTimeoutInput" type="number" min="0" step="1" inputmode="numeric" placeholder="0" :disabled="mcpPolicyControlsDisabled" @change="onMcpQueryTimeoutInput" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<div class="space-y-0.5">
|
||||
<p class="text-xs font-medium">
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
const dialogSource = readFileSync(new URL("../EditorSettingsDialog.vue", import.meta.url), "utf8");
|
||||
|
||||
// Regression for the MCP query-timeout input: decimal values like 1.5 were
|
||||
// silently Math.round-ed to 2 and saved, contradicting the "non-negative whole
|
||||
// number" label. The UI must reject non-integers with the existing invalid
|
||||
// toast instead of silently rewriting them.
|
||||
describe("EditorSettingsDialog MCP query timeout validation", () => {
|
||||
function handlerBlock(): string {
|
||||
const start = dialogSource.indexOf("function onMcpQueryTimeoutInput()");
|
||||
const end = dialogSource.indexOf("const mcpSelectableConnections", start);
|
||||
if (start < 0 || end < 0) throw new Error("Missing onMcpQueryTimeoutInput handler block");
|
||||
return dialogSource.slice(start, end);
|
||||
}
|
||||
|
||||
it("rejects non-integers instead of rounding them", () => {
|
||||
const block = handlerBlock();
|
||||
// The invalid path must test for integer-ness, not just finite + non-negative.
|
||||
expect(block).toMatch(/Number\.isInteger\(parsed\)/);
|
||||
// The valid save path must NOT wrap the value in Math.round anymore.
|
||||
expect(block).not.toContain("Math.round(parsed)");
|
||||
// A decimal input falls through to the invalid toast + revert branch.
|
||||
expect(block).toContain('toast(t("settings.mcpQueryTimeoutInvalid"), 5000)');
|
||||
expect(block).toMatch(/mcpQueryTimeoutInput\.value\s*=\s*settingsStore\.mcpGlobalPolicy\.queryTimeoutSecs === null \? "" : String\(settingsStore\.mcpGlobalPolicy\.queryTimeoutSecs\)/);
|
||||
});
|
||||
|
||||
it("keeps null (inherit) and zero (no limit) working", () => {
|
||||
const block = handlerBlock();
|
||||
// Empty input still persists null (inherit the connection).
|
||||
expect(block).toContain("void saveMcpPolicy({ queryTimeoutSecs: null })");
|
||||
// A valid integer still reaches saveMcpPolicy with the exact value.
|
||||
expect(block).toContain("void saveMcpPolicy({ queryTimeoutSecs: parsed })");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user