Skip to main content
Glama

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
NameRequiredDescriptionDefault
hostnameNoHostname to match (optional)
url_patternNoURL regex pattern to match (optional)
headersYesHeaders to inject (key-value pairs, set value to null to delete a header)
directionNoWhere to inject: request, response, or bothrequest
priorityNoRule priority (default: 50)

Implementation Reference

  • 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) }) }] };
      }
    },
  • 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)"),
      },

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yfe404/proxy-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server