proxy_rewrite_url
Rewrite URLs in network traffic by matching patterns and replacing them with specified strings, enabling request modification for testing and debugging.
Instructions
Rewrite request URLs matching a pattern. Creates a passthrough rule with body match-replace on the URL.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| match_pattern | Yes | Regex pattern to match in URLs | |
| replace_with | Yes | Replacement string | |
| hostname | No | Limit to this hostname | |
| priority | No | Rule priority (default: 50) |
Implementation Reference
- src/tools/modification.ts:56-96 (handler)The tool 'proxy_rewrite_url' is registered and implemented in src/tools/modification.ts. It configures a passthrough rule that applies a match-replace transformation on the request URL.
server.tool( "proxy_rewrite_url", "Rewrite request URLs matching a pattern. Creates a passthrough rule with body match-replace on the URL.", { match_pattern: z.string().describe("Regex pattern to match in URLs"), replace_with: z.string().describe("Replacement string"), hostname: z.string().optional().describe("Limit to this hostname"), priority: z.number().optional().default(50).describe("Rule priority (default: 50)"), }, async ({ match_pattern, replace_with, hostname, priority }) => { try { const matcher: RuleMatcher = {}; if (hostname) matcher.hostname = hostname; matcher.urlPattern = match_pattern; const handler: RuleHandler = { type: "passthrough", transformRequest: { matchReplaceBody: [[match_pattern, replace_with]], }, }; const rule = await proxyManager.addRule({ priority, enabled: true, description: `URL rewrite: ${match_pattern} → ${replace_with}`, matcher, handler, }); return { content: [{ type: "text", text: JSON.stringify({ status: "success", rule_id: rule.id, description: rule.description }), }], }; } catch (e) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: String(e) }) }] }; } }, );