@requestly/mcp 1.0.0

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 ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@requestly/mcp",
3
+ "version": "1.0.0",
4
+ "main": "build/index.js",
5
+ "type": "module",
6
+ "bin": {
7
+ "@requestly/mcp": "./build/index.js"
8
+ },
9
+ "scripts": {
10
+ "build": "esbuild src/index.ts --bundle --minify --platform=node --format=esm --outfile=build/index.js && chmod 755 build/index.js",
11
+ "start": "node build/index.js",
12
+ "test": "echo \"Error: no test specified\" && exit 1"
13
+ },
14
+ "keywords": [
15
+ "requestly",
16
+ "mcp",
17
+ "server",
18
+ "rules",
19
+ "groups"
20
+ ],
21
+ "author": "Requestly <contact@requestly.io>",
22
+ "license": "MIT",
23
+ "packageManager": "pnpm@9.15.9",
24
+ "description": "Requestly MCP server for rule and group management via stdio.",
25
+ "devDependencies": {
26
+ "@types/node": "^24.1.0",
27
+ "esbuild": "^0.25.8",
28
+ "typescript": "^5.8.3"
29
+ },
30
+ "dependencies": {
31
+ "@modelcontextprotocol/sdk": "^1.16.0",
32
+ "zod": "^3.25.76"
33
+ }
34
+ }
package/src/index.ts ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { registerTools } from './tools/index.js';
5
+
6
+ const server = new McpServer({
7
+ name: 'requestly-mcp-server',
8
+ version: '1.0.0',
9
+ description:
10
+ 'MCP server for automating and managing Requestly rules, groups, and integrations via the Requestly API.',
11
+ documentation: 'https://docs.requestly.io/api',
12
+ capabilities: {
13
+ resources: {},
14
+ tools: {},
15
+ // Context: This server is designed to expose Requestly API capabilities for rule and group management, CI/CD integration, and data access. Tools will allow creation, update, deletion, and retrieval of rules and groups, as well as custom workflow automation. Authentication is via x-api-key header. No tools are defined yet, but the server is ready for future expansion.
16
+ },
17
+ });
18
+
19
+ async function main() {
20
+ const transport = new StdioServerTransport();
21
+ // Register all tools
22
+ registerTools(server);
23
+ await server.connect(transport);
24
+ console.error('Requestly MCP Server running on stdio');
25
+ }
26
+
27
+ main().catch((error) => {
28
+ console.error('Fatal error in main():', error);
29
+ process.exit(1);
30
+ });
@@ -0,0 +1,59 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+
4
+ export function registerCreateGroupTool(server: McpServer) {
5
+ server.registerTool(
6
+ "create_group",
7
+ {
8
+ title: "Create Group",
9
+ description: "Create a new group in Requestly.",
10
+ inputSchema: {
11
+ name: z.string().describe("Name of the group to be created."),
12
+ status: z.enum(["Active", "Inactive"]).optional().default("Active"),
13
+ isFavourite: z.boolean().optional().default(false),
14
+ },
15
+ },
16
+ async (args) => {
17
+ const apiKey = process.env.REQUESTLY_API_KEY;
18
+ if (!apiKey) {
19
+ return {
20
+ content: [
21
+ {
22
+ type: "text",
23
+ text: "Error: REQUESTLY_API_KEY environment variable is not set.",
24
+ },
25
+ ],
26
+ };
27
+ }
28
+ try {
29
+ const response = await fetch("https://api2.requestly.io/v1/groups", {
30
+ method: "POST",
31
+ headers: {
32
+ "accept": "application/json",
33
+ "content-type": "application/json",
34
+ "x-api-key": apiKey,
35
+ },
36
+ body: JSON.stringify(args),
37
+ });
38
+ const data = await response.json();
39
+ return {
40
+ content: [
41
+ {
42
+ type: "text",
43
+ text: JSON.stringify(data, null, 2),
44
+ },
45
+ ],
46
+ };
47
+ } catch (error) {
48
+ return {
49
+ content: [
50
+ {
51
+ type: "text",
52
+ text: `Error creating group: ${error instanceof Error ? error.message : String(error)}`,
53
+ },
54
+ ],
55
+ };
56
+ }
57
+ }
58
+ );
59
+ }
@@ -0,0 +1,76 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { ruleSchema, schema, ValidatedRuleArgs } from "../types/createRuleSchemas.js";
3
+
4
+ export function registerCreateRuleTool(server: McpServer) {
5
+ server.registerTool(
6
+ 'create_rule',
7
+ {
8
+ title: 'Create Rule',
9
+ description:
10
+ 'This endpoint allows you to create various types of rules in Requestly, such as Redirect, Cancel, Replace, Headers, User-Agent, Query Param, Modify Request, Modify Response, and Delay. Each rule has a specific structure and parameters based on the ruleType.',
11
+ inputSchema: schema,
12
+ },
13
+ async (args: Record<string, unknown>): Promise<{ content: Array<{ type: 'text'; text: string }> }> => {
14
+ try {
15
+ // Validate the full request using our discriminated union schema
16
+ const validatedArgs: ValidatedRuleArgs = ruleSchema.parse(args);
17
+ const { name, description, ruleType, status, pairs, groupId } = validatedArgs;
18
+ const apiKey = process.env.REQUESTLY_API_KEY;
19
+ if (!apiKey) {
20
+ return {
21
+ content: [
22
+ {
23
+ type: 'text',
24
+ text: 'Error: REQUESTLY_API_KEY environment variable is not set.',
25
+ },
26
+ ],
27
+ };
28
+ }
29
+ const body: Record<string, unknown> = {
30
+ name,
31
+ objectType: 'rule',
32
+ status: status || 'Active',
33
+ ruleType,
34
+ pairs,
35
+ description: description || undefined,
36
+ };
37
+ if (groupId) {
38
+ body.groupId = groupId;
39
+ }
40
+
41
+ const response = await fetch('https://api2.requestly.io/v1/rules', {
42
+ method: 'POST',
43
+ headers: {
44
+ 'Content-Type': 'application/json',
45
+ 'x-api-key': apiKey,
46
+ },
47
+ body: JSON.stringify(body),
48
+ });
49
+ if (!response.ok) {
50
+ const errorText = await response.text();
51
+ return {
52
+ content: [
53
+ {
54
+ type: 'text',
55
+ text: `Failed to create rule: ${response.status} ${errorText}`,
56
+ },
57
+ ],
58
+ };
59
+ }
60
+ const data = await response.json();
61
+ return {
62
+ content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
63
+ };
64
+ }
65
+ catch (error) {
66
+ console.error('Error in create_rule tool:', error);
67
+ return {
68
+ content: [
69
+ {
70
+ type: 'text',
71
+ text: `Error creating rule: ${error instanceof Error ? error.message : String(error)}`,
72
+ },
73
+ ],
74
+ };
75
+ }})
76
+ }
@@ -0,0 +1,58 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+
4
+ export function registerDeleteGroupTool(server: McpServer) {
5
+ server.registerTool(
6
+ "delete_group",
7
+ {
8
+ title: "Delete Group",
9
+ description: "Delete a specific group in Requestly using its id.",
10
+ inputSchema: {
11
+ id: z.string().describe("Unique identifier of the group to delete."),
12
+ },
13
+ },
14
+ async (args) => {
15
+ const apiKey = process.env.REQUESTLY_API_KEY;
16
+ if (!apiKey) {
17
+ return {
18
+ content: [
19
+ {
20
+ type: "text",
21
+ text: "Error: REQUESTLY_API_KEY environment variable is not set.",
22
+ },
23
+ ],
24
+ };
25
+ }
26
+ try {
27
+ const { id } = args;
28
+ const response = await fetch(`https://api2.requestly.io/v1/groups/${id}`,
29
+ {
30
+ method: "DELETE",
31
+ headers: {
32
+ "accept": "application/json",
33
+ "x-api-key": apiKey,
34
+ },
35
+ }
36
+ );
37
+ const data = await response.json();
38
+ return {
39
+ content: [
40
+ {
41
+ type: "text",
42
+ text: JSON.stringify(data, null, 2),
43
+ },
44
+ ],
45
+ };
46
+ } catch (error) {
47
+ return {
48
+ content: [
49
+ {
50
+ type: "text",
51
+ text: `Error deleting group: ${error instanceof Error ? error.message : String(error)}`,
52
+ },
53
+ ],
54
+ };
55
+ }
56
+ }
57
+ );
58
+ }
@@ -0,0 +1,57 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+
4
+ export function registerDeleteRuleTool(server: McpServer) {
5
+ server.registerTool(
6
+ "delete_rule",
7
+ {
8
+ title: "Delete Rule",
9
+ description: "Delete a specific rule in Requestly using its ruleId.",
10
+ inputSchema: {
11
+ ruleId: z.string().describe("Unique identifier for the rule to delete."),
12
+ },
13
+ },
14
+ async (args) => {
15
+ const apiKey = process.env.REQUESTLY_API_KEY;
16
+ if (!apiKey) {
17
+ return {
18
+ content: [
19
+ {
20
+ type: "text",
21
+ text: "Error: REQUESTLY_API_KEY environment variable is not set.",
22
+ },
23
+ ],
24
+ };
25
+ }
26
+ try {
27
+ const response = await fetch(`https://api2.requestly.io/v1/rules/${args.ruleId}`,
28
+ {
29
+ method: "DELETE",
30
+ headers: {
31
+ "accept": "application/json",
32
+ "x-api-key": apiKey,
33
+ },
34
+ }
35
+ );
36
+ const data = await response.json();
37
+ return {
38
+ content: [
39
+ {
40
+ type: "text",
41
+ text: JSON.stringify(data, null, 2),
42
+ },
43
+ ],
44
+ };
45
+ } catch (error) {
46
+ return {
47
+ content: [
48
+ {
49
+ type: "text",
50
+ text: `Error deleting rule: ${error instanceof Error ? error.message : String(error)}`,
51
+ },
52
+ ],
53
+ };
54
+ }
55
+ }
56
+ );
57
+ }
@@ -0,0 +1,61 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+
4
+ export function registerGetGroupsTool(server: McpServer) {
5
+ server.registerTool(
6
+ "get_groups",
7
+ {
8
+ title: "Get Groups",
9
+ description: "Get all groups in Requestly.",
10
+ inputSchema: {
11
+ offset: z.number().optional().default(0),
12
+ pageSize: z.number().optional().default(30),
13
+ },
14
+ },
15
+ async (args)=> {
16
+ const apiKey = process.env.REQUESTLY_API_KEY;
17
+ if (!apiKey) {
18
+ return {
19
+ content: [
20
+ {
21
+ type: "text",
22
+ text: "Error: REQUESTLY_API_KEY environment variable is not set.",
23
+ },
24
+ ],
25
+ };
26
+ }
27
+ try {
28
+ const params = new URLSearchParams();
29
+ if (typeof args.offset === "number") params.append("offset", String(args.offset));
30
+ if (typeof args.pageSize === "number") params.append("pageSize", String(args.pageSize));
31
+ const response = await fetch(`https://api2.requestly.io/v1/groups?${params.toString()}`,
32
+ {
33
+ method: "GET",
34
+ headers: {
35
+ "accept": "application/json",
36
+ "x-api-key": apiKey,
37
+ },
38
+ }
39
+ );
40
+ const data = await response.json();
41
+ return {
42
+ content: [
43
+ {
44
+ type: "text",
45
+ text: JSON.stringify(data, null, 2),
46
+ },
47
+ ],
48
+ };
49
+ } catch (error) {
50
+ return {
51
+ content: [
52
+ {
53
+ type: "text",
54
+ text: `Error getting groups: ${error instanceof Error ? error.message : String(error)}`,
55
+ },
56
+ ],
57
+ };
58
+ }
59
+ }
60
+ );
61
+ }
@@ -0,0 +1,83 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+
4
+ export const getRulesInputSchema = {
5
+ ruleId: z.string().optional().describe("Unique ID of the rule to retrieve. If omitted, retrieves all rules."),
6
+ offset: z.number().int().min(0).optional().describe("Index to start results from (for pagination)."),
7
+ pageSize: z.number().int().min(1).max(75).optional().describe("Number of results to return (max 75)."),
8
+ };
9
+
10
+ export function registerGetRulesTool(server: McpServer) {
11
+ server.registerTool(
12
+ "get_rules",
13
+ {
14
+ title: "Get Rules",
15
+ description:
16
+ "Retrieve all rules or a specific rule from Requestly using its API. Supports pagination and lookup by ruleId.",
17
+ inputSchema: getRulesInputSchema,
18
+ },
19
+ async (args) => {
20
+ const apiKey = process.env.REQUESTLY_API_KEY;
21
+ if (!apiKey) {
22
+ return {
23
+ content: [
24
+ {
25
+ type: "text",
26
+ text: "Error: REQUESTLY_API_KEY environment variable is not set.",
27
+ },
28
+ ],
29
+ };
30
+ }
31
+ const { ruleId, offset, pageSize } = args;
32
+ let url = "https://api2.requestly.io/v1/rules";
33
+ if (ruleId) {
34
+ url += `/${encodeURIComponent(ruleId)}`;
35
+ } else {
36
+ const params = [];
37
+ if (offset !== undefined) params.push(`offset=${offset}`);
38
+ if (pageSize !== undefined) params.push(`pageSize=${pageSize}`);
39
+ if (params.length > 0) {
40
+ url += `?${params.join("&")}`;
41
+ }
42
+ }
43
+ try {
44
+ const response = await fetch(url, {
45
+ method: "GET",
46
+ headers: {
47
+ "accept": "application/json",
48
+ "x-api-key": apiKey,
49
+ },
50
+ });
51
+ if (!response.ok) {
52
+ const errorText = await response.text();
53
+ return {
54
+ content: [
55
+ {
56
+ type: "text",
57
+ text: `Failed to get rules: ${response.status} ${errorText}`,
58
+ },
59
+ ],
60
+ };
61
+ }
62
+ const data = await response.json();
63
+ return {
64
+ content: [
65
+ {
66
+ type: "text",
67
+ text: JSON.stringify(data, null, 2),
68
+ },
69
+ ],
70
+ };
71
+ } catch (error) {
72
+ return {
73
+ content: [
74
+ {
75
+ type: "text",
76
+ text: `Error getting rules: ${error instanceof Error ? error.message : String(error)}`,
77
+ },
78
+ ],
79
+ };
80
+ }
81
+ }
82
+ );
83
+ }
@@ -0,0 +1,20 @@
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { registerCreateRuleTool } from "./createRule.js";
3
+ import { registerGetRulesTool } from "./getRules.js";
4
+ import { registerUpdateRuleTool } from "./updateRule.js";
5
+ import { registerDeleteRuleTool } from "./deleteRule.js";
6
+ import { registerCreateGroupTool } from "./createGroup.js";
7
+ import { registerGetGroupsTool } from "./getGroups.js";
8
+ import { registerUpdateGroupTool } from "./updateGroup.js";
9
+ import { registerDeleteGroupTool } from "./deleteGroup.js";
10
+
11
+ export function registerTools(server: McpServer) {
12
+ registerCreateRuleTool(server);
13
+ registerGetRulesTool(server);
14
+ registerUpdateRuleTool(server);
15
+ registerDeleteRuleTool(server);
16
+ registerCreateGroupTool(server);
17
+ registerGetGroupsTool(server);
18
+ registerUpdateGroupTool(server);
19
+ registerDeleteGroupTool(server);
20
+ }
@@ -0,0 +1,63 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { z } from "zod";
3
+
4
+ export function registerUpdateGroupTool(server: McpServer) {
5
+ server.registerTool(
6
+ "update_group",
7
+ {
8
+ title: "Update Group",
9
+ description: "Update a specific group in Requestly.",
10
+ inputSchema: {
11
+ id: z.string().describe("Unique identifier of the group to update."),
12
+ name: z.string().describe("New name of the group."),
13
+ status: z.enum(["Active", "Inactive"]).optional().default("Active"),
14
+ isFavourite: z.boolean().optional().default(false),
15
+ },
16
+ },
17
+ async (args) => {
18
+ const apiKey = process.env.REQUESTLY_API_KEY;
19
+ if (!apiKey) {
20
+ return {
21
+ content: [
22
+ {
23
+ type: "text",
24
+ text: "Error: REQUESTLY_API_KEY environment variable is not set.",
25
+ },
26
+ ],
27
+ };
28
+ }
29
+ try {
30
+ const { id, ...rest } = args;
31
+ const response = await fetch(`https://api2.requestly.io/v1/groups/${id}`,
32
+ {
33
+ method: "PUT",
34
+ headers: {
35
+ "accept": "application/json",
36
+ "content-type": "application/json",
37
+ "x-api-key": apiKey,
38
+ },
39
+ body: JSON.stringify(rest),
40
+ }
41
+ );
42
+ const data = await response.json();
43
+ return {
44
+ content: [
45
+ {
46
+ type: "text",
47
+ text: JSON.stringify(data, null, 2),
48
+ },
49
+ ],
50
+ };
51
+ } catch (error) {
52
+ return {
53
+ content: [
54
+ {
55
+ type: "text",
56
+ text: `Error updating group: ${error instanceof Error ? error.message : String(error)}`,
57
+ },
58
+ ],
59
+ };
60
+ }
61
+ }
62
+ );
63
+ }
@@ -0,0 +1,86 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { ruleSchema, schema, ValidatedRuleArgs } from "../types/updateRuleSchemas.js";
3
+ import { z }from "zod";
4
+
5
+ export function registerUpdateRuleTool(server: McpServer) {
6
+ server.registerTool(
7
+ "update_rule",
8
+ {
9
+ title: "Update Rule",
10
+ description:
11
+ "Update an existing rule in Requestly. Requires ruleId and the updated rule payload.",
12
+ inputSchema: schema
13
+
14
+ },
15
+ async (args: Record<string, unknown>): Promise<{ content: Array<{ type: "text"; text: string }> }> => {
16
+ const apiKey = process.env.REQUESTLY_API_KEY;
17
+ if (!apiKey) {
18
+ return {
19
+ content: [
20
+ {
21
+ type: "text",
22
+ text: "Error: REQUESTLY_API_KEY environment variable is not set.",
23
+ },
24
+ ],
25
+ };
26
+ }
27
+ try {
28
+ // Validate input using the extended ruleSchema
29
+ const validatedArgs: ValidatedRuleArgs = ruleSchema.parse(args);
30
+ if (!validatedArgs.ruleId) {
31
+ return {
32
+ content: [
33
+ {
34
+ type: "text",
35
+ text: "Error: ruleId is required.",
36
+ },
37
+ ],
38
+ };
39
+ }
40
+ const { ruleId, ...rest } = validatedArgs;
41
+ const body = { ...rest };
42
+
43
+ const response = await fetch(`https://api2.requestly.io/v1/rules/${ruleId}`,
44
+ {
45
+ method: "PUT",
46
+ headers: {
47
+ "accept": "application/json",
48
+ "content-type": "application/json",
49
+ "x-api-key": apiKey,
50
+ },
51
+ body: JSON.stringify(body),
52
+ }
53
+ );
54
+ if (!response.ok) {
55
+ const errorText = await response.text();
56
+ return {
57
+ content: [
58
+ {
59
+ type: "text",
60
+ text: `Failed to update rule: ${response.status} ${errorText}`,
61
+ },
62
+ ],
63
+ };
64
+ }
65
+ const data = await response.json();
66
+ return {
67
+ content: [
68
+ {
69
+ type: "text",
70
+ text: JSON.stringify(data, null, 2),
71
+ },
72
+ ],
73
+ };
74
+ } catch (error) {
75
+ return {
76
+ content: [
77
+ {
78
+ type: "text",
79
+ text: `Error updating rule: ${error instanceof Error ? error.message : String(error)}`,
80
+ },
81
+ ],
82
+ };
83
+ }
84
+ }
85
+ );
86
+ }