proxy_update_rule
Update an existing interception rule's matcher and handler settings to modify how traffic is intercepted and processed.
Instructions
Modify an existing interception rule.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rule_id | Yes | Rule ID to update | |
| description | No | New description | |
| priority | No | New priority | |
| matcher | No | New matcher config | |
| handler | No | New handler config |
Implementation Reference
- src/tools/rules.ts:82-111 (registration)Registers the 'proxy_update_rule' tool on the MCP server using server.tool(), providing input schema and handler callback.
server.tool( "proxy_update_rule", "Modify an existing interception rule.", { rule_id: z.string().describe("Rule ID to update"), description: z.string().optional().describe("New description"), priority: z.number().optional().describe("New priority"), matcher: matcherSchema.optional().describe("New matcher config"), handler: handlerSchema.optional().describe("New handler config"), }, async ({ rule_id, description, priority, matcher, handler }) => { try { const updates: Record<string, unknown> = {}; if (description !== undefined) updates.description = description; if (priority !== undefined) updates.priority = priority; if (matcher !== undefined) updates.matcher = matcher; if (handler !== undefined) updates.handler = handler; const rule = await proxyManager.updateRule(rule_id, updates); return { content: [{ type: "text", text: JSON.stringify({ status: "success", rule }), }], }; } catch (e) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: String(e) }) }] }; } }, ); - src/tools/rules.ts:92-110 (handler)The async handler function for 'proxy_update_rule'. It extracts rule_id, description, priority, matcher, and handler from inputs, builds an updates object, calls proxyManager.updateRule(), and returns success/error JSON.
async ({ rule_id, description, priority, matcher, handler }) => { try { const updates: Record<string, unknown> = {}; if (description !== undefined) updates.description = description; if (priority !== undefined) updates.priority = priority; if (matcher !== undefined) updates.matcher = matcher; if (handler !== undefined) updates.handler = handler; const rule = await proxyManager.updateRule(rule_id, updates); return { content: [{ type: "text", text: JSON.stringify({ status: "success", rule }), }], }; } catch (e) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: String(e) }) }] }; } }, - src/state.ts:560-566 (helper)ProxyManager.updateRule() - the core logic that looks up the rule by ID, applies partial updates via Object.assign(), and triggers a mockttp rule rebuild if the proxy is running.
async updateRule(id: string, updates: Partial<Omit<InterceptionRule, "id" | "hitCount" | "createdAt">>): Promise<InterceptionRule> { const rule = this.rules.get(id); if (!rule) throw new Error(`Rule '${id}' not found`); Object.assign(rule, updates); if (this._running) await this.rebuildMockttpRules(); return rule; } - src/tools/rules.ts:85-91 (schema)Input schema for 'proxy_update_rule': accepts rule_id (required string) plus optional description, priority, matcher, and handler fields.
{ rule_id: z.string().describe("Rule ID to update"), description: z.string().optional().describe("New description"), priority: z.number().optional().describe("New priority"), matcher: matcherSchema.optional().describe("New matcher config"), handler: handlerSchema.optional().describe("New handler config"), }, - src/index.ts:64-64 (registration)Entry point where registerRuleTools(server) is called to register all rule tools including proxy_update_rule.
registerRuleTools(server);