@requestly/mcp 1.0.2 → 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/build/index.js +13 -11
- package/package.json +1 -1
- package/src/__tests__/ruleSchemas.test.ts +61 -3
- package/src/__tests__/tools.test.ts +24 -2
- package/src/tools/createRule.ts +25 -3
- package/src/tools/deleteGroup.ts +34 -1
- package/src/tools/deleteRule.ts +33 -1
- package/src/tools/updateRule.ts +42 -3
- package/src/types/createRuleSchemas.ts +10 -4
- package/src/types/ruleSchemas.ts +6 -0
package/package.json
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
DelayPairSchema,
|
|
13
13
|
ScriptPairSchema,
|
|
14
14
|
ScriptModificationSchema,
|
|
15
|
+
ScriptAttributeSchema,
|
|
15
16
|
RuleTypeEnum,
|
|
16
17
|
} from '../types/ruleSchemas.js';
|
|
17
18
|
import {
|
|
@@ -403,6 +404,42 @@ describe('ScriptModificationSchema', () => {
|
|
|
403
404
|
const { codeType, ...rest } = validMod;
|
|
404
405
|
expect(() => ScriptModificationSchema.parse(rest)).toThrow();
|
|
405
406
|
});
|
|
407
|
+
|
|
408
|
+
it('accepts optional attributes array', () => {
|
|
409
|
+
const result = ScriptModificationSchema.parse({
|
|
410
|
+
...validMod,
|
|
411
|
+
attributes: [
|
|
412
|
+
{ name: 'data-tracker-id', value: '1234-5678' },
|
|
413
|
+
{ name: 'type', value: 'text/javascript' },
|
|
414
|
+
],
|
|
415
|
+
});
|
|
416
|
+
expect(result.attributes).toHaveLength(2);
|
|
417
|
+
expect(result.attributes![0].name).toBe('data-tracker-id');
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it('accepts script without attributes (optional)', () => {
|
|
421
|
+
const result = ScriptModificationSchema.parse(validMod);
|
|
422
|
+
expect(result.attributes).toBeUndefined();
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it('accepts empty attributes array', () => {
|
|
426
|
+
const result = ScriptModificationSchema.parse({ ...validMod, attributes: [] });
|
|
427
|
+
expect(result.attributes).toHaveLength(0);
|
|
428
|
+
});
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
describe('ScriptAttributeSchema', () => {
|
|
432
|
+
it('accepts valid attribute', () => {
|
|
433
|
+
expect(() => ScriptAttributeSchema.parse({ name: 'data-id', value: '123' })).not.toThrow();
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it('rejects missing name', () => {
|
|
437
|
+
expect(() => ScriptAttributeSchema.parse({ value: '123' })).toThrow();
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it('rejects missing value', () => {
|
|
441
|
+
expect(() => ScriptAttributeSchema.parse({ name: 'data-id' })).toThrow();
|
|
442
|
+
});
|
|
406
443
|
});
|
|
407
444
|
|
|
408
445
|
describe('ScriptPairSchema', () => {
|
|
@@ -424,7 +461,7 @@ describe('ScriptPairSchema', () => {
|
|
|
424
461
|
scripts: [
|
|
425
462
|
{ codeType: 'js', value: 'alert("hi")', loadTime: 'beforePageLoad', type: 'code' },
|
|
426
463
|
{ codeType: 'css', value: 'body { color: red; }', loadTime: 'afterPageLoad', type: 'code' },
|
|
427
|
-
{ codeType: 'js', value: 'https://cdn.example.com/lib.js', loadTime: 'beforePageLoad', type: 'url' },
|
|
464
|
+
{ codeType: 'js', value: 'https://cdn.example.com/lib.js', loadTime: 'beforePageLoad', type: 'url', attributes: [{ name: 'defer', value: '' }] },
|
|
428
465
|
],
|
|
429
466
|
})
|
|
430
467
|
).not.toThrow();
|
|
@@ -584,6 +621,27 @@ describe('createRuleSchema (discriminated union)', () => {
|
|
|
584
621
|
).not.toThrow();
|
|
585
622
|
});
|
|
586
623
|
|
|
624
|
+
it('validates Script rule with custom attributes', () => {
|
|
625
|
+
const result = createRuleSchema.parse({
|
|
626
|
+
...baseRule,
|
|
627
|
+
ruleType: 'Script',
|
|
628
|
+
pairs: [{
|
|
629
|
+
source: validSource,
|
|
630
|
+
scripts: [{
|
|
631
|
+
codeType: 'js',
|
|
632
|
+
value: 'https://tracker.example.com/script.js',
|
|
633
|
+
loadTime: 'afterPageLoad',
|
|
634
|
+
type: 'url',
|
|
635
|
+
attributes: [
|
|
636
|
+
{ name: 'data-luigisbox-tracker-id', value: '1234-5678' },
|
|
637
|
+
{ name: 'type', value: 'text/javascript' },
|
|
638
|
+
],
|
|
639
|
+
}],
|
|
640
|
+
}],
|
|
641
|
+
});
|
|
642
|
+
expect(result.pairs[0].scripts[0].attributes).toHaveLength(2);
|
|
643
|
+
});
|
|
644
|
+
|
|
587
645
|
it('rejects Script rule with invalid pair (missing scripts)', () => {
|
|
588
646
|
expect(() =>
|
|
589
647
|
createRuleSchema.parse({
|
|
@@ -644,13 +702,13 @@ describe('createRuleSchema (discriminated union)', () => {
|
|
|
644
702
|
expect(result.description).toBe('Test description');
|
|
645
703
|
});
|
|
646
704
|
|
|
647
|
-
it('defaults status to
|
|
705
|
+
it('defaults status to Inactive', () => {
|
|
648
706
|
const result = createRuleSchema.parse({
|
|
649
707
|
name: 'Test',
|
|
650
708
|
ruleType: 'Cancel',
|
|
651
709
|
pairs: [{ source: validSource }],
|
|
652
710
|
});
|
|
653
|
-
expect(result.status).toBe('
|
|
711
|
+
expect(result.status).toBe('Inactive');
|
|
654
712
|
});
|
|
655
713
|
});
|
|
656
714
|
|
|
@@ -125,6 +125,16 @@ describe('Create Rule Tool - Schema Validation per Rule Type', () => {
|
|
|
125
125
|
source: validSource,
|
|
126
126
|
scripts: [
|
|
127
127
|
{ codeType: 'js', value: 'console.log("injected")', loadTime: 'afterPageLoad', type: 'code' },
|
|
128
|
+
{
|
|
129
|
+
codeType: 'js',
|
|
130
|
+
value: 'https://tracker.example.com/script.js',
|
|
131
|
+
loadTime: 'afterPageLoad',
|
|
132
|
+
type: 'url',
|
|
133
|
+
attributes: [
|
|
134
|
+
{ name: 'data-tracker-id', value: '12345' },
|
|
135
|
+
{ name: 'type', value: 'text/javascript' },
|
|
136
|
+
],
|
|
137
|
+
},
|
|
128
138
|
],
|
|
129
139
|
}],
|
|
130
140
|
},
|
|
@@ -382,10 +392,22 @@ describe('Delete Rule Tool', () => {
|
|
|
382
392
|
return toolHandler(args);
|
|
383
393
|
}
|
|
384
394
|
|
|
385
|
-
it('deletes a rule by ID', async () => {
|
|
386
|
-
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 });
|
|
387
397
|
expect(result.content[0].text).toContain('success');
|
|
388
398
|
expect((globalThis.fetch as any).mock.calls[0][0]).toBe('https://api2.requestly.io/v1/rules/Cancel_abc12');
|
|
389
399
|
expect((globalThis.fetch as any).mock.calls[0][1].method).toBe('DELETE');
|
|
390
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
|
+
});
|
|
391
413
|
});
|
package/src/tools/createRule.ts
CHANGED
|
@@ -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:
|
|
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) {
|
package/src/tools/deleteGroup.ts
CHANGED
|
@@ -6,12 +6,45 @@ export function registerDeleteGroupTool(server: McpServer) {
|
|
|
6
6
|
"delete_group",
|
|
7
7
|
{
|
|
8
8
|
title: "Delete Group",
|
|
9
|
-
description:
|
|
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 {
|
package/src/tools/deleteRule.ts
CHANGED
|
@@ -6,12 +6,44 @@ export function registerDeleteRuleTool(server: McpServer) {
|
|
|
6
6
|
"delete_rule",
|
|
7
7
|
{
|
|
8
8
|
title: "Delete Rule",
|
|
9
|
-
description:
|
|
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 {
|
package/src/tools/updateRule.ts
CHANGED
|
@@ -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
|
-
|
|
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('
|
|
16
|
-
.describe(
|
|
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('
|
|
53
|
-
.describe(
|
|
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()
|
package/src/types/ruleSchemas.ts
CHANGED
|
@@ -89,11 +89,17 @@ export const DelayPairSchema = z.object({
|
|
|
89
89
|
}).describe('Delay value in milliseconds (stringified number).'),
|
|
90
90
|
}).describe('Delay rule pair: source and delay.');
|
|
91
91
|
|
|
92
|
+
export const ScriptAttributeSchema = z.object({
|
|
93
|
+
name: z.string().describe('Attribute name (e.g. "data-tracker-id", "type", "defer").'),
|
|
94
|
+
value: z.string().describe('Attribute value.'),
|
|
95
|
+
}).describe('Custom HTML attribute to add to the injected script tag.');
|
|
96
|
+
|
|
92
97
|
export const ScriptModificationSchema = z.object({
|
|
93
98
|
codeType: z.enum(['js', 'css']).describe('Script language: js or css.'),
|
|
94
99
|
value: z.string().describe('Script content or URL depending on type.'),
|
|
95
100
|
loadTime: z.enum(['beforePageLoad', 'afterPageLoad']).describe('When to load the script: beforePageLoad or afterPageLoad.'),
|
|
96
101
|
type: z.enum(['url', 'code']).describe('Script value type: url (external script URL) or code (inline script).'),
|
|
102
|
+
attributes: z.array(ScriptAttributeSchema).optional().describe('Optional array of custom HTML attributes to add to the injected script tag.'),
|
|
97
103
|
}).describe('Script modification details.');
|
|
98
104
|
|
|
99
105
|
export const ScriptPairSchema = z.object({
|