proxy_inject_headers
Modify HTTP traffic by adding, overwriting, or deleting headers in requests or responses based on hostname or URL patterns.
Instructions
Add or overwrite headers on matching traffic. Creates a passthrough rule with header transforms.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hostname | No | Hostname to match (optional) | |
| url_pattern | No | URL regex pattern to match (optional) | |
| headers | Yes | Headers to inject (key-value pairs, set value to null to delete a header) | |
| direction | No | Where to inject: request, response, or both | request |
| priority | No | Rule priority (default: 50) |
Implementation Reference
- src/tools/modification.ts:22-53 (handler)The handler function for the proxy_inject_headers tool, which processes input parameters, constructs a rule matcher and handler, and adds the rule via the proxyManager.
async ({ hostname, url_pattern, headers, direction, priority }) => { try { const matcher: RuleMatcher = {}; if (hostname) matcher.hostname = hostname; if (url_pattern) matcher.urlPattern = url_pattern; const handler: RuleHandler = { type: "passthrough" }; if (direction === "request" || direction === "both") { handler.transformRequest = { updateHeaders: headers }; } if (direction === "response" || direction === "both") { handler.transformResponse = { updateHeaders: headers }; } const rule = await proxyManager.addRule({ priority, enabled: true, description: `Inject headers: ${Object.keys(headers).join(", ")} (${direction})`, 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) }) }] }; } }, - src/tools/modification.ts:11-21 (registration)Registration and schema definition for the proxy_inject_headers tool, using Zod for parameter validation.
server.tool( "proxy_inject_headers", "Add or overwrite headers on matching traffic. Creates a passthrough rule with header transforms.", { hostname: z.string().optional().describe("Hostname to match (optional)"), url_pattern: z.string().optional().describe("URL regex pattern to match (optional)"), headers: z.record(z.string().nullable()).describe("Headers to inject (key-value pairs, set value to null to delete a header)"), direction: z.enum(["request", "response", "both"]).optional().default("request") .describe("Where to inject: request, response, or both"), priority: z.number().optional().default(50).describe("Rule priority (default: 50)"), },