feat(mcp): add global query timeout override

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-08-30 12:26:54 +08:00
1 parent 7ba30ae761
commit e6f8b2187a
24 files changed
+615 -35

No files matched your search

+11
View File
@@ -433,6 +433,7 @@ describe("normalizeMcpGlobalPolicy", () => {
allowDangerousSql: false,
allowedConnectionIds: null,
configured: false,
queryTimeoutSecs: null,
});
});
@@ -449,12 +450,20 @@ describe("normalizeMcpGlobalPolicy", () => {
allowDangerousSql: true,
allowedConnectionIds: ["connection-1", "connection-2"],
configured: true,
queryTimeoutSecs: null,
});
});
it("preserves an empty allowlist as deny all", () => {
expect(normalizeMcpGlobalPolicy({ allowedConnectionIds: [] }).allowedConnectionIds).toEqual([]);
});
it("round-trips queryTimeoutSecs null, undefined and positive numbers", () => {
expect(normalizeMcpGlobalPolicy({ queryTimeoutSecs: null }).queryTimeoutSecs).toBeNull();
expect(normalizeMcpGlobalPolicy({ queryTimeoutSecs: undefined } as any).queryTimeoutSecs).toBeNull();
expect(normalizeMcpGlobalPolicy({ queryTimeoutSecs: 0 }).queryTimeoutSecs).toBe(0);
expect(normalizeMcpGlobalPolicy({ queryTimeoutSecs: 300 }).queryTimeoutSecs).toBe(300);
});
});
describe("normalizeEditorSettings - continueOnErrorOnBatch", () => {
@@ -667,6 +676,7 @@ describe("settingsStore MCP policy persistence", () => {
allowDangerousSql: false,
allowedConnectionIds: ["connection-1"],
configured: true,
queryTimeoutSecs: null,
};
store.mcpGlobalPolicy = previous;
@@ -679,6 +689,7 @@ describe("settingsStore MCP policy persistence", () => {
allowDangerousSql: false,
allowedConnectionIds: [],
configured: true,
queryTimeoutSecs: null,
});
rejectSave(new Error("save failed"));
+9
View File
@@ -51,6 +51,8 @@ export interface McpGlobalPolicy {
allowDangerousSql: boolean;
allowedConnectionIds: string[] | null;
configured: boolean;
/** MCP query timeout override in seconds. null/undefined = inherit the connection; 0 = no limit. */
queryTimeoutSecs: number | null;
}
export type DesktopIconTheme = "default" | "black";
@@ -90,15 +92,21 @@ export const DEFAULT_MCP_GLOBAL_POLICY: McpGlobalPolicy = {
allowDangerousSql: false,
allowedConnectionIds: null,
configured: false,
queryTimeoutSecs: null,
};
export function normalizeMcpGlobalPolicy(policy: Partial<McpGlobalPolicy> | null | undefined): McpGlobalPolicy {
const allowedConnectionIds = policy?.allowedConnectionIds === null || policy?.allowedConnectionIds === undefined ? null : [...new Set(policy.allowedConnectionIds.filter((id): id is string => typeof id === "string" && id.trim().length > 0).map((id) => id.trim()))];
// null / undefined / non-positive => null (inherit connection). 0 is preserved
// as an explicit "no limit" only here; the UI maps "no limit" <=> 0 and
// "inherit" <=> null.
const queryTimeoutSecs = policy?.queryTimeoutSecs === null || policy?.queryTimeoutSecs === undefined ? null : typeof policy.queryTimeoutSecs === "number" && Number.isFinite(policy.queryTimeoutSecs) && policy.queryTimeoutSecs >= 0 ? Math.round(policy.queryTimeoutSecs) : null;
return {
readOnly: policy?.readOnly === true,
allowDangerousSql: policy?.allowDangerousSql === true,
allowedConnectionIds,
configured: policy?.configured === true,
queryTimeoutSecs,
};
}
@@ -1522,6 +1530,7 @@ export const useSettingsStore = defineStore("settings", () => {
readOnly: next.readOnly,
allowDangerousSql: next.allowDangerousSql,
allowedConnectionIds: next.allowedConnectionIds,
queryTimeoutSecs: next.queryTimeoutSecs,
});
} catch (error) {
mcpGlobalPolicy.value = previous;