@requestly/mcp 1.0.4 → 1.0.5
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/.coderabbit.yaml +9 -0
- package/README.md +27 -0
- package/build/index.js +118 -61
- package/package.json +8 -4
- package/src/__tests__/codeApproval.test.ts +863 -0
- package/src/__tests__/deleteApproval.test.ts +270 -0
- package/src/__tests__/openReview.test.ts +71 -0
- package/src/__tests__/security.test.ts +152 -0
- package/src/__tests__/serverInstructions.test.ts +27 -0
- package/src/__tests__/setup/isolateHome.ts +33 -0
- package/src/__tests__/testIsolation.test.ts +14 -0
- package/src/__tests__/tools.test.ts +22 -63
- package/src/__tests__/untrustedOutput.test.ts +328 -0
- package/src/apiClient.ts +113 -0
- package/src/codeApproval.ts +409 -0
- package/src/humanApproval.ts +70 -0
- package/src/index.ts +2 -16
- package/src/server.ts +23 -0
- package/src/tools/createGroup.ts +10 -10
- package/src/tools/createRule.ts +37 -27
- package/src/tools/deleteGroup.ts +30 -40
- package/src/tools/deleteRule.ts +30 -37
- package/src/tools/getGroups.ts +11 -11
- package/src/tools/getRules.ts +12 -22
- package/src/tools/updateGroup.ts +11 -11
- package/src/tools/updateRule.ts +124 -56
- package/src/types/updateRuleSchemas.ts +7 -8
- package/src/untrustedData.ts +75 -0
- package/vitest.config.mjs +8 -0
package/src/tools/createRule.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { ruleSchema, schema, ValidatedRuleArgs } from "../types/createRuleSchemas.js";
|
|
3
|
+
import { REQUESTLY_API_BASE, apiErrorResult, readApiJson } from "../apiClient.js";
|
|
4
|
+
import { untrustedDataResult } from "../untrustedData.js";
|
|
5
|
+
import { EDITED_NOTE, applyAccepted, askHumanToAcceptCode, codeItems, codeNotApprovedText } from "../codeApproval.js";
|
|
3
6
|
|
|
4
7
|
export function registerCreateRuleTool(server: McpServer) {
|
|
5
8
|
server.registerTool(
|
|
@@ -8,7 +11,10 @@ export function registerCreateRuleTool(server: McpServer) {
|
|
|
8
11
|
title: 'Create Rule',
|
|
9
12
|
description:
|
|
10
13
|
'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
|
|
14
|
+
'New rules default to Inactive. A Script, Request or Response rule carries code that runs in the browser ' +
|
|
15
|
+
'(inline scripts, script URLs, request/response bodies): before such a rule is saved, the user is shown ' +
|
|
16
|
+
'the code (in the MCP host prompt, or in a local file it names, which the user may edit before accepting) and must accept it (an approval prompt the model cannot answer). If the user ' +
|
|
17
|
+
'does not accept, or the host cannot show the prompt, nothing is saved.',
|
|
12
18
|
inputSchema: schema,
|
|
13
19
|
annotations: {
|
|
14
20
|
title: 'Create Rule',
|
|
@@ -18,7 +24,7 @@ export function registerCreateRuleTool(server: McpServer) {
|
|
|
18
24
|
openWorldHint: true,
|
|
19
25
|
},
|
|
20
26
|
},
|
|
21
|
-
async (args: Record<string, unknown
|
|
27
|
+
async (args: Record<string, unknown>, extra?: { requestId?: string | number; signal?: AbortSignal }): Promise<{ content: Array<{ type: 'text'; text: string }> }> => {
|
|
22
28
|
try {
|
|
23
29
|
// Validate the full request using our discriminated union schema
|
|
24
30
|
const validatedArgs: ValidatedRuleArgs = ruleSchema.parse(args);
|
|
@@ -34,28 +40,41 @@ export function registerCreateRuleTool(server: McpServer) {
|
|
|
34
40
|
],
|
|
35
41
|
};
|
|
36
42
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
const effectiveStatus = status ?? 'Inactive';
|
|
44
|
+
|
|
45
|
+
// RQ-3011 / RQ-3021: code the model wrote is saved only after the user has
|
|
46
|
+
// seen it and accepted it in the host. A model-supplied argument (the old
|
|
47
|
+
// confirmActivation) can never stand in for that.
|
|
48
|
+
const code = codeItems(ruleType, pairs);
|
|
49
|
+
let pairsToSave: unknown = pairs;
|
|
50
|
+
let edited = false;
|
|
51
|
+
if (code.length > 0) {
|
|
52
|
+
const approval = await askHumanToAcceptCode(
|
|
53
|
+
server,
|
|
54
|
+
{ action: 'create', ruleType, name, status: effectiveStatus, added: code },
|
|
55
|
+
{ relatedRequestId: extra?.requestId, signal: extra?.signal }
|
|
56
|
+
);
|
|
57
|
+
if (!approval.approved) {
|
|
58
|
+
return { content: [{ type: 'text', text: codeNotApprovedText(`the new ${ruleType} rule`, approval.reason) }] };
|
|
59
|
+
}
|
|
60
|
+
// What the user accepted, including any edits they made in the review file.
|
|
61
|
+
pairsToSave = applyAccepted(ruleType, pairs, code, approval.accepted);
|
|
62
|
+
edited = approval.edited;
|
|
63
|
+
}
|
|
45
64
|
|
|
46
65
|
const body: Record<string, unknown> = {
|
|
47
66
|
name,
|
|
48
67
|
objectType: 'rule',
|
|
49
68
|
status: effectiveStatus,
|
|
50
69
|
ruleType,
|
|
51
|
-
pairs,
|
|
70
|
+
pairs: pairsToSave,
|
|
52
71
|
description: description || undefined,
|
|
53
72
|
};
|
|
54
73
|
if (groupId) {
|
|
55
74
|
body.groupId = groupId;
|
|
56
75
|
}
|
|
57
76
|
|
|
58
|
-
const response = await fetch(
|
|
77
|
+
const response = await fetch(`${REQUESTLY_API_BASE}/rules`, {
|
|
59
78
|
method: 'POST',
|
|
60
79
|
headers: {
|
|
61
80
|
'Content-Type': 'application/json',
|
|
@@ -64,25 +83,16 @@ export function registerCreateRuleTool(server: McpServer) {
|
|
|
64
83
|
body: JSON.stringify(body),
|
|
65
84
|
});
|
|
66
85
|
if (!response.ok) {
|
|
67
|
-
|
|
68
|
-
return
|
|
69
|
-
content: [
|
|
70
|
-
{
|
|
71
|
-
type: 'text',
|
|
72
|
-
text: `Failed to create rule: ${response.status} ${errorText}`,
|
|
73
|
-
},
|
|
74
|
-
],
|
|
75
|
-
};
|
|
86
|
+
// RQ-3025: status only — never reflect the upstream body into LLM context.
|
|
87
|
+
return await apiErrorResult('create rule', response);
|
|
76
88
|
}
|
|
77
|
-
const
|
|
89
|
+
const parsed = await readApiJson('create rule', response);
|
|
90
|
+
if (!parsed.ok) return parsed.result;
|
|
78
91
|
const note =
|
|
79
92
|
effectiveStatus === 'Inactive'
|
|
80
|
-
? '\n\nNOTE: This rule was created INACTIVE.
|
|
81
|
-
'(especially any injected script/code) and explicitly activate it before it takes effect.'
|
|
93
|
+
? '\n\nNOTE: This rule was created INACTIVE. It takes effect once it is turned on.'
|
|
82
94
|
: '';
|
|
83
|
-
return
|
|
84
|
-
content: [{ type: 'text', text: JSON.stringify(data, null, 2) + note }],
|
|
85
|
-
};
|
|
95
|
+
return untrustedDataResult('create_rule', parsed.data, note + (edited ? EDITED_NOTE : ''));
|
|
86
96
|
}
|
|
87
97
|
catch (error) {
|
|
88
98
|
console.error('Error in create_rule tool:', error);
|
package/src/tools/deleteGroup.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import {
|
|
2
|
+
import { buildResourceUrl, apiErrorResult, resourceIdSchema, readApiJson } from "../apiClient.js";
|
|
3
|
+
import { untrustedDataResult } from "../untrustedData.js";
|
|
4
|
+
import { askHumanToApprove, notApprovedText } from "../humanApproval.js";
|
|
3
5
|
|
|
4
6
|
export function registerDeleteGroupTool(server: McpServer) {
|
|
5
7
|
server.registerTool(
|
|
@@ -7,19 +9,13 @@ export function registerDeleteGroupTool(server: McpServer) {
|
|
|
7
9
|
{
|
|
8
10
|
title: "Delete Group",
|
|
9
11
|
description:
|
|
10
|
-
"Delete a specific group in Requestly using its id. IRREVERSIBLE
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
12
|
+
"Delete a specific group in Requestly using its id. IRREVERSIBLE. The rules inside the " +
|
|
13
|
+
"group are not deleted; they stay in the workspace without a group. " +
|
|
14
|
+
"Before anything is deleted, the user is asked to approve it directly in the MCP host " +
|
|
15
|
+
"(an approval prompt the model cannot answer). If the user does not approve, or the host " +
|
|
16
|
+
"cannot show the prompt, nothing is deleted.",
|
|
14
17
|
inputSchema: {
|
|
15
|
-
id:
|
|
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
|
-
),
|
|
18
|
+
id: resourceIdSchema.describe("Unique identifier of the group to delete."),
|
|
23
19
|
},
|
|
24
20
|
annotations: {
|
|
25
21
|
title: "Delete Group",
|
|
@@ -29,22 +25,7 @@ export function registerDeleteGroupTool(server: McpServer) {
|
|
|
29
25
|
openWorldHint: true,
|
|
30
26
|
},
|
|
31
27
|
},
|
|
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
|
-
}
|
|
28
|
+
async (args, extra) => {
|
|
48
29
|
const apiKey = process.env.REQUESTLY_API_KEY;
|
|
49
30
|
if (!apiKey) {
|
|
50
31
|
return {
|
|
@@ -56,9 +37,20 @@ export function registerDeleteGroupTool(server: McpServer) {
|
|
|
56
37
|
],
|
|
57
38
|
};
|
|
58
39
|
}
|
|
40
|
+
// RQ-3008: the human approves each delete through the host (MCP elicitation).
|
|
41
|
+
// A model-supplied argument can never authorise it.
|
|
42
|
+
const what = `group "${args.id}"`;
|
|
43
|
+
const approval = await askHumanToApprove(
|
|
44
|
+
server,
|
|
45
|
+
`Permanently delete Requestly group "${args.id}"? This cannot be undone. ` +
|
|
46
|
+
`The rules inside it are kept, without a group.`,
|
|
47
|
+
{ relatedRequestId: extra?.requestId, signal: extra?.signal }
|
|
48
|
+
);
|
|
49
|
+
if (!approval.approved) {
|
|
50
|
+
return { content: [{ type: "text", text: notApprovedText(what, approval.reason) }] };
|
|
51
|
+
}
|
|
59
52
|
try {
|
|
60
|
-
const
|
|
61
|
-
const response = await fetch(`https://api2.requestly.io/v1/groups/${id}`,
|
|
53
|
+
const response = await fetch(buildResourceUrl("groups", args.id),
|
|
62
54
|
{
|
|
63
55
|
method: "DELETE",
|
|
64
56
|
headers: {
|
|
@@ -67,15 +59,13 @@ export function registerDeleteGroupTool(server: McpServer) {
|
|
|
67
59
|
},
|
|
68
60
|
}
|
|
69
61
|
);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
],
|
|
78
|
-
};
|
|
62
|
+
if (!response.ok) {
|
|
63
|
+
// RQ-3025: status only — never reflect the upstream body.
|
|
64
|
+
return await apiErrorResult("delete group", response);
|
|
65
|
+
}
|
|
66
|
+
const parsed = await readApiJson("delete group", response);
|
|
67
|
+
if (!parsed.ok) return parsed.result;
|
|
68
|
+
return untrustedDataResult("delete_group", parsed.data);
|
|
79
69
|
} catch (error) {
|
|
80
70
|
return {
|
|
81
71
|
content: [
|
package/src/tools/deleteRule.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import {
|
|
2
|
+
import { buildResourceUrl, apiErrorResult, resourceIdSchema, readApiJson } from "../apiClient.js";
|
|
3
|
+
import { untrustedDataResult } from "../untrustedData.js";
|
|
4
|
+
import { askHumanToApprove, notApprovedText } from "../humanApproval.js";
|
|
3
5
|
|
|
4
6
|
export function registerDeleteRuleTool(server: McpServer) {
|
|
5
7
|
server.registerTool(
|
|
@@ -8,17 +10,11 @@ export function registerDeleteRuleTool(server: McpServer) {
|
|
|
8
10
|
title: "Delete Rule",
|
|
9
11
|
description:
|
|
10
12
|
"Delete a specific rule in Requestly using its ruleId. IRREVERSIBLE. " +
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
+
"Before anything is deleted, the user is asked to approve it directly in the MCP host " +
|
|
14
|
+
"(an approval prompt the model cannot answer). If the user does not approve, or the host " +
|
|
15
|
+
"cannot show the prompt, nothing is deleted.",
|
|
13
16
|
inputSchema: {
|
|
14
|
-
ruleId:
|
|
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
|
-
),
|
|
17
|
+
ruleId: resourceIdSchema.describe("Unique identifier for the rule to delete."),
|
|
22
18
|
},
|
|
23
19
|
annotations: {
|
|
24
20
|
title: "Delete Rule",
|
|
@@ -28,22 +24,7 @@ export function registerDeleteRuleTool(server: McpServer) {
|
|
|
28
24
|
openWorldHint: true,
|
|
29
25
|
},
|
|
30
26
|
},
|
|
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
|
-
}
|
|
27
|
+
async (args, extra) => {
|
|
47
28
|
const apiKey = process.env.REQUESTLY_API_KEY;
|
|
48
29
|
if (!apiKey) {
|
|
49
30
|
return {
|
|
@@ -55,8 +36,20 @@ export function registerDeleteRuleTool(server: McpServer) {
|
|
|
55
36
|
],
|
|
56
37
|
};
|
|
57
38
|
}
|
|
39
|
+
// RQ-3008: the human approves each delete through the host (MCP elicitation).
|
|
40
|
+
// A model-supplied argument can never authorise it.
|
|
41
|
+
const what = `rule "${args.ruleId}"`;
|
|
42
|
+
const approval = await askHumanToApprove(
|
|
43
|
+
server,
|
|
44
|
+
`Permanently delete Requestly rule "${args.ruleId}"? This cannot be undone. ` +
|
|
45
|
+
`Check the rule in the Requestly app first if you're not sure what it is.`,
|
|
46
|
+
{ relatedRequestId: extra?.requestId, signal: extra?.signal }
|
|
47
|
+
);
|
|
48
|
+
if (!approval.approved) {
|
|
49
|
+
return { content: [{ type: "text", text: notApprovedText(what, approval.reason) }] };
|
|
50
|
+
}
|
|
58
51
|
try {
|
|
59
|
-
const response = await fetch(
|
|
52
|
+
const response = await fetch(buildResourceUrl("rules", args.ruleId),
|
|
60
53
|
{
|
|
61
54
|
method: "DELETE",
|
|
62
55
|
headers: {
|
|
@@ -65,15 +58,15 @@ export function registerDeleteRuleTool(server: McpServer) {
|
|
|
65
58
|
},
|
|
66
59
|
}
|
|
67
60
|
);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
61
|
+
if (!response.ok) {
|
|
62
|
+
// RQ-3025: the success path stringified the upstream body verbatim,
|
|
63
|
+
// which reflected API error payloads into LLM context just as the
|
|
64
|
+
// explicit error branches did.
|
|
65
|
+
return await apiErrorResult("delete rule", response);
|
|
66
|
+
}
|
|
67
|
+
const parsed = await readApiJson("delete rule", response);
|
|
68
|
+
if (!parsed.ok) return parsed.result;
|
|
69
|
+
return untrustedDataResult("delete_rule", parsed.data);
|
|
77
70
|
} catch (error) {
|
|
78
71
|
return {
|
|
79
72
|
content: [
|
package/src/tools/getGroups.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { REQUESTLY_API_BASE, apiErrorResult, readApiJson } from "../apiClient.js";
|
|
4
|
+
import { UNTRUSTED_OUTPUT_DESCRIPTION, untrustedDataResult } from "../untrustedData.js";
|
|
3
5
|
|
|
4
6
|
export function registerGetGroupsTool(server: McpServer) {
|
|
5
7
|
server.registerTool(
|
|
6
8
|
"get_groups",
|
|
7
9
|
{
|
|
8
10
|
title: "Get Groups",
|
|
9
|
-
description: "Get all groups in Requestly.",
|
|
11
|
+
description: "Get all groups in Requestly." + UNTRUSTED_OUTPUT_DESCRIPTION,
|
|
10
12
|
inputSchema: {
|
|
11
13
|
offset: z.number().optional().default(0),
|
|
12
14
|
pageSize: z.number().optional().default(30),
|
|
@@ -28,7 +30,7 @@ export function registerGetGroupsTool(server: McpServer) {
|
|
|
28
30
|
const params = new URLSearchParams();
|
|
29
31
|
if (typeof args.offset === "number") params.append("offset", String(args.offset));
|
|
30
32
|
if (typeof args.pageSize === "number") params.append("pageSize", String(args.pageSize));
|
|
31
|
-
const response = await fetch(
|
|
33
|
+
const response = await fetch(`${REQUESTLY_API_BASE}/groups?${params.toString()}`,
|
|
32
34
|
{
|
|
33
35
|
method: "GET",
|
|
34
36
|
headers: {
|
|
@@ -37,15 +39,13 @@ export function registerGetGroupsTool(server: McpServer) {
|
|
|
37
39
|
},
|
|
38
40
|
}
|
|
39
41
|
);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
],
|
|
48
|
-
};
|
|
42
|
+
if (!response.ok) {
|
|
43
|
+
// RQ-3025: status only — never reflect the upstream body.
|
|
44
|
+
return await apiErrorResult("get groups", response);
|
|
45
|
+
}
|
|
46
|
+
const parsed = await readApiJson("get groups", response);
|
|
47
|
+
if (!parsed.ok) return parsed.result;
|
|
48
|
+
return untrustedDataResult("get_groups", parsed.data);
|
|
49
49
|
} catch (error) {
|
|
50
50
|
return {
|
|
51
51
|
content: [
|
package/src/tools/getRules.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { REQUESTLY_API_BASE, buildResourceUrl, apiErrorResult, resourceIdSchema, readApiJson } from "../apiClient.js";
|
|
4
|
+
import { UNTRUSTED_OUTPUT_DESCRIPTION, untrustedDataResult } from "../untrustedData.js";
|
|
3
5
|
|
|
4
6
|
export const getRulesInputSchema = {
|
|
5
|
-
ruleId:
|
|
7
|
+
ruleId: resourceIdSchema.optional().describe("Unique ID of the rule to retrieve. If omitted, retrieves all rules."),
|
|
6
8
|
offset: z.number().int().min(0).optional().describe("Index to start results from (for pagination)."),
|
|
7
9
|
pageSize: z.number().int().min(1).max(75).optional().describe("Number of results to return (max 75)."),
|
|
8
10
|
};
|
|
@@ -13,7 +15,8 @@ export function registerGetRulesTool(server: McpServer) {
|
|
|
13
15
|
{
|
|
14
16
|
title: "Get Rules",
|
|
15
17
|
description:
|
|
16
|
-
"Retrieve all rules or a specific rule from Requestly using its API. Supports pagination and lookup by ruleId."
|
|
18
|
+
"Retrieve all rules or a specific rule from Requestly using its API. Supports pagination and lookup by ruleId." +
|
|
19
|
+
UNTRUSTED_OUTPUT_DESCRIPTION,
|
|
17
20
|
inputSchema: getRulesInputSchema,
|
|
18
21
|
},
|
|
19
22
|
async (args) => {
|
|
@@ -29,9 +32,9 @@ export function registerGetRulesTool(server: McpServer) {
|
|
|
29
32
|
};
|
|
30
33
|
}
|
|
31
34
|
const { ruleId, offset, pageSize } = args;
|
|
32
|
-
let url =
|
|
35
|
+
let url = `${REQUESTLY_API_BASE}/rules`;
|
|
33
36
|
if (ruleId) {
|
|
34
|
-
url
|
|
37
|
+
url = buildResourceUrl("rules", ruleId);
|
|
35
38
|
} else {
|
|
36
39
|
const params = [];
|
|
37
40
|
if (offset !== undefined) params.push(`offset=${offset}`);
|
|
@@ -49,25 +52,12 @@ export function registerGetRulesTool(server: McpServer) {
|
|
|
49
52
|
},
|
|
50
53
|
});
|
|
51
54
|
if (!response.ok) {
|
|
52
|
-
|
|
53
|
-
return
|
|
54
|
-
content: [
|
|
55
|
-
{
|
|
56
|
-
type: "text",
|
|
57
|
-
text: `Failed to get rules: ${response.status} ${errorText}`,
|
|
58
|
-
},
|
|
59
|
-
],
|
|
60
|
-
};
|
|
55
|
+
// RQ-3025: status only — never reflect the upstream body into LLM context.
|
|
56
|
+
return await apiErrorResult("get rules", response);
|
|
61
57
|
}
|
|
62
|
-
const
|
|
63
|
-
return
|
|
64
|
-
|
|
65
|
-
{
|
|
66
|
-
type: "text",
|
|
67
|
-
text: JSON.stringify(data, null, 2),
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
};
|
|
58
|
+
const parsed = await readApiJson("get rules", response);
|
|
59
|
+
if (!parsed.ok) return parsed.result;
|
|
60
|
+
return untrustedDataResult("get_rules", parsed.data);
|
|
71
61
|
} catch (error) {
|
|
72
62
|
return {
|
|
73
63
|
content: [
|
package/src/tools/updateGroup.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { buildResourceUrl, apiErrorResult, resourceIdSchema, readApiJson } from "../apiClient.js";
|
|
4
|
+
import { untrustedDataResult } from "../untrustedData.js";
|
|
3
5
|
|
|
4
6
|
export function registerUpdateGroupTool(server: McpServer) {
|
|
5
7
|
server.registerTool(
|
|
@@ -8,7 +10,7 @@ export function registerUpdateGroupTool(server: McpServer) {
|
|
|
8
10
|
title: "Update Group",
|
|
9
11
|
description: "Update a specific group in Requestly.",
|
|
10
12
|
inputSchema: {
|
|
11
|
-
id:
|
|
13
|
+
id: resourceIdSchema.describe("Unique identifier of the group to update."),
|
|
12
14
|
name: z.string().describe("New name of the group."),
|
|
13
15
|
status: z.enum(["Active", "Inactive"]).optional().default("Active"),
|
|
14
16
|
isFavourite: z.boolean().optional().default(false),
|
|
@@ -28,7 +30,7 @@ export function registerUpdateGroupTool(server: McpServer) {
|
|
|
28
30
|
}
|
|
29
31
|
try {
|
|
30
32
|
const { id, ...rest } = args;
|
|
31
|
-
const response = await fetch(
|
|
33
|
+
const response = await fetch(buildResourceUrl("groups", id),
|
|
32
34
|
{
|
|
33
35
|
method: "PUT",
|
|
34
36
|
headers: {
|
|
@@ -39,15 +41,13 @@ export function registerUpdateGroupTool(server: McpServer) {
|
|
|
39
41
|
body: JSON.stringify(rest),
|
|
40
42
|
}
|
|
41
43
|
);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
],
|
|
50
|
-
};
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
// RQ-3025: status only — never reflect the upstream body.
|
|
46
|
+
return await apiErrorResult("update group", response);
|
|
47
|
+
}
|
|
48
|
+
const parsed = await readApiJson("update group", response);
|
|
49
|
+
if (!parsed.ok) return parsed.result;
|
|
50
|
+
return untrustedDataResult("update_group", parsed.data);
|
|
51
51
|
} catch (error) {
|
|
52
52
|
return {
|
|
53
53
|
content: [
|