Skip to content

Commit 718fb12

Browse files
committed
modified according to code rabbit suggestions
1 parent 97d7315 commit 718fb12

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

app/client/packages/mcp/src/gates.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
apiBaseUrlFromEnv,
44
elicitationTimeoutFromEnv,
55
gateEnabled,
6+
gateEnabledUnlessFalse,
67
parsePositiveInt,
78
publicOriginFromEnv,
89
sessionLimitsFromEnv,
@@ -66,6 +67,26 @@ describe("gateEnabled — opt-in gate parsing (data/JS layers)", () => {
6667
});
6768
});
6869

70+
describe("gateEnabledUnlessFalse — default-on until false", () => {
71+
it.each(["false", "FALSE", "False", " false "])(
72+
"disables for %j",
73+
(value) => {
74+
expect(gateEnabledUnlessFalse(value)).toBe(false);
75+
},
76+
);
77+
78+
it.each(["0", "off", "no", "disabled", "true", "1", "", " "])(
79+
"stays on for %j",
80+
(value) => {
81+
expect(gateEnabledUnlessFalse(value)).toBe(true);
82+
},
83+
);
84+
85+
it("stays on when the variable is unset", () => {
86+
expect(gateEnabledUnlessFalse(undefined)).toBe(true);
87+
});
88+
});
89+
6990
describe("parsePositiveInt — session cap/TTL env overrides", () => {
7091
it.each([
7192
["25", 25],

app/client/packages/mcp/src/gates.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ export function gateEnabled(value: string | undefined): boolean {
88
return value !== undefined && /^(1|true|yes|on)$/i.test(value.trim());
99
}
1010

11+
// Default-ON counterpart for capabilities whose server-side opt-in flags were removed. Enabled unless the env
12+
// value is "false" (trim + case-insensitive); "0", "off", blank, and unset all stay enabled.
13+
export function gateEnabledUnlessFalse(value: string | undefined): boolean {
14+
return value === undefined || value.trim().toLowerCase() !== "false";
15+
}
16+
1117
// Positive-integer env override (session caps, TTLs). Unset, non-numeric, fractional, zero, or negative values fall
1218
// back to the built-in default rather than failing startup or silently disabling a limit.
1319
export function parsePositiveInt(

app/client/packages/mcp/src/server.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
apiBaseUrlFromEnv,
1010
elicitationTimeoutFromEnv,
1111
gateEnabled,
12+
gateEnabledUnlessFalse,
1213
publicOriginFromEnv,
1314
sessionLimitsFromEnv,
1415
} from "./gates.js";
@@ -23,10 +24,12 @@ const apiBaseUrl = apiBaseUrlFromEnv(
2324
process.env.APPSMITH_API_BASE_URL ?? "http://127.0.0.1:8080",
2425
);
2526

26-
// Temporarily keep these capabilities enabled while their server-side configuration flags are unavailable.
27-
// Governed/destructive tools still require Mongo+Redis and register only when that infrastructure is present.
28-
const dataEnabled = true;
29-
const jsEnabled = true;
27+
// Data and JS stay on unless an operator explicitly sets the env var to "false". Governed/destructive tools
28+
// still require Mongo+Redis and register only when that infrastructure is present.
29+
const dataEnabled = gateEnabledUnlessFalse(
30+
process.env.APPSMITH_MCP_DATA_ENABLED,
31+
);
32+
const jsEnabled = gateEnabledUnlessFalse(process.env.APPSMITH_MCP_JS_ENABLED);
3033

3134
// Optional Host-header allowlist (comma-separated hostnames) enforced on /mcp. Unset by default: this service is
3235
// fronted by Caddy which preserves the original Host, so a default loopback list would reject the proxied public

0 commit comments

Comments
 (0)