@requestly/mcp 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@requestly/mcp",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "main": "build/index.js",
5
5
  "type": "module",
6
6
  "bin": {
@@ -702,13 +702,13 @@ describe('createRuleSchema (discriminated union)', () => {
702
702
  expect(result.description).toBe('Test description');
703
703
  });
704
704
 
705
- it('defaults status to Active', () => {
705
+ it('defaults status to Inactive', () => {
706
706
  const result = createRuleSchema.parse({
707
707
  name: 'Test',
708
708
  ruleType: 'Cancel',
709
709
  pairs: [{ source: validSource }],
710
710
  });
711
- expect(result.status).toBe('Active');
711
+ expect(result.status).toBe('Inactive');
712
712
  });
713
713
  });
714
714
 
@@ -392,10 +392,22 @@ describe('Delete Rule Tool', () => {
392
392
  return toolHandler(args);
393
393
  }
394
394
 
395
- it('deletes a rule by ID', async () => {
396
- const result = await callDeleteRuleTool({ ruleId: 'Cancel_abc12' });
395
+ it('deletes a rule by ID when confirm is true', async () => {
396
+ const result = await callDeleteRuleTool({ ruleId: 'Cancel_abc12', confirm: true });
397
397
  expect(result.content[0].text).toContain('success');
398
398
  expect((globalThis.fetch as any).mock.calls[0][0]).toBe('https://api2.requestly.io/v1/rules/Cancel_abc12');
399
399
  expect((globalThis.fetch as any).mock.calls[0][1].method).toBe('DELETE');
400
400
  });
401
+
402
+ it('refuses to delete without explicit confirm and issues no request', async () => {
403
+ const result = await callDeleteRuleTool({ ruleId: 'Cancel_abc12' });
404
+ expect(result.content[0].text).toContain('Confirmation required');
405
+ expect(globalThis.fetch as any).not.toHaveBeenCalled();
406
+ });
407
+
408
+ it('refuses to delete when confirm is false and issues no request', async () => {
409
+ const result = await callDeleteRuleTool({ ruleId: 'Cancel_abc12', confirm: false });
410
+ expect(result.content[0].text).toContain('Confirmation required');
411
+ expect(globalThis.fetch as any).not.toHaveBeenCalled();
412
+ });
401
413
  });
@@ -7,8 +7,16 @@ export function registerCreateRuleTool(server: McpServer) {
7
7
  {
8
8
  title: 'Create Rule',
9
9
  description:
10
- 'This endpoint allows you to create various types of rules in Requestly, such as Redirect, Cancel, Replace, Headers, User-Agent, Script (Insert Script), Query Param, Modify Request, Modify Response, and Delay. Each rule has a specific structure and parameters based on the ruleType.',
10
+ 'This endpoint allows you to create various types of rules in Requestly, such as Redirect, Cancel, Replace, Headers, User-Agent, Script (Insert Script), Query Param, Modify Request, Modify Response, and Delay. Each rule has a specific structure and parameters based on the ruleType. ' +
11
+ 'New rules default to Inactive. Script/Request/Response rules (which can execute code in the browser/request pipeline) are ALWAYS created Inactive and must be reviewed by a human and explicitly activated before they take effect.',
11
12
  inputSchema: schema,
13
+ annotations: {
14
+ title: 'Create Rule',
15
+ readOnlyHint: false,
16
+ destructiveHint: false,
17
+ idempotentHint: false,
18
+ openWorldHint: true,
19
+ },
12
20
  },
13
21
  async (args: Record<string, unknown>): Promise<{ content: Array<{ type: 'text'; text: string }> }> => {
14
22
  try {
@@ -26,10 +34,19 @@ export function registerCreateRuleTool(server: McpServer) {
26
34
  ],
27
35
  };
28
36
  }
37
+ // RQ-3011: code-bearing rule types can execute attacker-controlled code in
38
+ // the page / request pipeline. Force them Inactive on creation regardless of
39
+ // what was requested, so an injected prompt can't create a live code rule.
40
+ // Other rule types default to Inactive too (never silently Active).
41
+ const CODE_BEARING_RULE_TYPES = new Set(['Script', 'Request', 'Response']);
42
+ const effectiveStatus = CODE_BEARING_RULE_TYPES.has(ruleType)
43
+ ? 'Inactive'
44
+ : (status ?? 'Inactive');
45
+
29
46
  const body: Record<string, unknown> = {
30
47
  name,
31
48
  objectType: 'rule',
32
- status: status || 'Active',
49
+ status: effectiveStatus,
33
50
  ruleType,
34
51
  pairs,
35
52
  description: description || undefined,
@@ -58,8 +75,13 @@ export function registerCreateRuleTool(server: McpServer) {
58
75
  };
59
76
  }
60
77
  const data = await response.json();
78
+ const note =
79
+ effectiveStatus === 'Inactive'
80
+ ? '\n\nNOTE: This rule was created INACTIVE. A human must review the rule ' +
81
+ '(especially any injected script/code) and explicitly activate it before it takes effect.'
82
+ : '';
61
83
  return {
62
- content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
84
+ content: [{ type: 'text', text: JSON.stringify(data, null, 2) + note }],
63
85
  };
64
86
  }
65
87
  catch (error) {
@@ -6,12 +6,45 @@ export function registerDeleteGroupTool(server: McpServer) {
6
6
  "delete_group",
7
7
  {
8
8
  title: "Delete Group",
9
- description: "Delete a specific group in Requestly using its id.",
9
+ description:
10
+ "Delete a specific group in Requestly using its id. IRREVERSIBLE and CASCADES " +
11
+ "— deleting a group also deletes every rule it contains. Requires confirm: true. " +
12
+ "Never set confirm: true on the user's behalf — first show the user the exact group " +
13
+ "id and get their explicit approval.",
10
14
  inputSchema: {
11
15
  id: z.string().describe("Unique identifier of the group to delete."),
16
+ confirm: z
17
+ .boolean()
18
+ .optional()
19
+ .default(false)
20
+ .describe(
21
+ "Must be explicitly set to true by the human operator to authorize this irreversible, cascading deletion."
22
+ ),
23
+ },
24
+ annotations: {
25
+ title: "Delete Group",
26
+ readOnlyHint: false,
27
+ destructiveHint: true,
28
+ idempotentHint: true,
29
+ openWorldHint: true,
12
30
  },
13
31
  },
14
32
  async (args) => {
33
+ // RQ-3008: consent boundary — group deletion cascades to all child rules,
34
+ // so refuse unless the human operator explicitly confirmed.
35
+ if (args.confirm !== true) {
36
+ return {
37
+ content: [
38
+ {
39
+ type: "text",
40
+ text:
41
+ `Confirmation required. This will PERMANENTLY delete group "${args.id}" ` +
42
+ `AND every rule inside it. This cannot be undone. To proceed, the human ` +
43
+ `operator must re-issue delete_group with the same id and confirm: true.`,
44
+ },
45
+ ],
46
+ };
47
+ }
15
48
  const apiKey = process.env.REQUESTLY_API_KEY;
16
49
  if (!apiKey) {
17
50
  return {
@@ -6,12 +6,44 @@ export function registerDeleteRuleTool(server: McpServer) {
6
6
  "delete_rule",
7
7
  {
8
8
  title: "Delete Rule",
9
- description: "Delete a specific rule in Requestly using its ruleId.",
9
+ description:
10
+ "Delete a specific rule in Requestly using its ruleId. IRREVERSIBLE. " +
11
+ "Requires confirm: true. Never set confirm: true on the user's behalf — " +
12
+ "first show the user the exact ruleId and get their explicit approval.",
10
13
  inputSchema: {
11
14
  ruleId: z.string().describe("Unique identifier for the rule to delete."),
15
+ confirm: z
16
+ .boolean()
17
+ .optional()
18
+ .default(false)
19
+ .describe(
20
+ "Must be explicitly set to true by the human operator to authorize this irreversible deletion."
21
+ ),
22
+ },
23
+ annotations: {
24
+ title: "Delete Rule",
25
+ readOnlyHint: false,
26
+ destructiveHint: true,
27
+ idempotentHint: true,
28
+ openWorldHint: true,
12
29
  },
13
30
  },
14
31
  async (args) => {
32
+ // RQ-3008: consent boundary — refuse irreversible deletion unless the human
33
+ // operator explicitly confirmed. Blocks prompt-injection-driven deletes.
34
+ if (args.confirm !== true) {
35
+ return {
36
+ content: [
37
+ {
38
+ type: "text",
39
+ text:
40
+ `Confirmation required. This will PERMANENTLY delete rule "${args.ruleId}". ` +
41
+ `This cannot be undone. To proceed, the human operator must re-issue ` +
42
+ `delete_rule with the same ruleId and confirm: true.`,
43
+ },
44
+ ],
45
+ };
46
+ }
15
47
  const apiKey = process.env.REQUESTLY_API_KEY;
16
48
  if (!apiKey) {
17
49
  return {
@@ -8,9 +8,27 @@ export function registerUpdateRuleTool(server: McpServer) {
8
8
  {
9
9
  title: "Update Rule",
10
10
  description:
11
- "Update an existing rule in Requestly. Requires ruleId and the updated rule payload.",
12
- inputSchema: schema
13
-
11
+ "Update an existing rule in Requestly. Requires ruleId and the updated rule payload. " +
12
+ "Activating a Script/Request/Response rule (status: 'Active') runs code in the browser/request " +
13
+ "pipeline and requires confirmActivation: true — never set it on the user's behalf; a human must " +
14
+ "review the rule's script/code first.",
15
+ inputSchema: {
16
+ ...schema,
17
+ confirmActivation: z
18
+ .boolean()
19
+ .optional()
20
+ .default(false)
21
+ .describe(
22
+ "Must be set to true by the human operator to activate a code-bearing (Script/Request/Response) rule after they have reviewed the injected code."
23
+ ),
24
+ },
25
+ annotations: {
26
+ title: "Update Rule",
27
+ readOnlyHint: false,
28
+ destructiveHint: false,
29
+ idempotentHint: true,
30
+ openWorldHint: true,
31
+ },
14
32
  },
15
33
  async (args: Record<string, unknown>): Promise<{ content: Array<{ type: "text"; text: string }> }> => {
16
34
  const apiKey = process.env.REQUESTLY_API_KEY;
@@ -37,6 +55,27 @@ export function registerUpdateRuleTool(server: McpServer) {
37
55
  ],
38
56
  };
39
57
  }
58
+ // RQ-3011: gate the dangerous Inactive->Active transition for code-bearing
59
+ // rule types behind explicit human confirmation. confirmActivation is read
60
+ // from the raw args (ruleSchema.parse strips unknown keys).
61
+ const CODE_BEARING_RULE_TYPES = new Set(["Script", "Request", "Response"]);
62
+ const willActivateCodeRule =
63
+ validatedArgs.status === "Active" &&
64
+ CODE_BEARING_RULE_TYPES.has(validatedArgs.ruleType as string);
65
+ if (willActivateCodeRule && args.confirmActivation !== true) {
66
+ return {
67
+ content: [
68
+ {
69
+ type: "text",
70
+ text:
71
+ "Activation requires review. This rule injects code that will run in the " +
72
+ "browser/request pipeline. Re-issue update_rule with confirmActivation: true " +
73
+ "only after a human has reviewed the script/code.",
74
+ },
75
+ ],
76
+ };
77
+ }
78
+
40
79
  const { ruleId, ...rest } = validatedArgs;
41
80
  const body = { ...rest };
42
81
 
@@ -12,8 +12,11 @@ function createRuleSchema<T extends z.infer<typeof RuleTypeEnum>>(
12
12
  status: z
13
13
  .enum(['Active', 'Inactive'])
14
14
  .optional()
15
- .default('Active')
16
- .describe('Status of the rule.'),
15
+ .default('Inactive')
16
+ .describe(
17
+ 'Status of the rule. Defaults to Inactive; rules must be explicitly activated ' +
18
+ 'after a human reviews them. Script/Request/Response rules are always created Inactive.'
19
+ ),
17
20
  pairs: z
18
21
  .array(pairSchema)
19
22
  .describe('List of rule pair objects for the rule type.'),
@@ -49,8 +52,11 @@ const createMCPCompatibleSchema = () => {
49
52
  status: z
50
53
  .enum(['Active', 'Inactive'])
51
54
  .optional()
52
- .default('Active')
53
- .describe('Status of the rule.'),
55
+ .default('Inactive')
56
+ .describe(
57
+ 'Status of the rule. Defaults to Inactive; rules must be explicitly activated ' +
58
+ 'after a human reviews them. Script/Request/Response rules are always created Inactive.'
59
+ ),
54
60
  groupId: z
55
61
  .string()
56
62
  .optional()