Skip to content

Strip endpointPrefix from request paths in transparent proxy #3372

@amirejaz

Description

@amirejaz

Problem

The transparent proxy currently rewrites SSE endpoint URLs in responses to include the configured endpointPrefix, but it doesn't strip the prefix from incoming request paths before forwarding to the backend MCP server.

This causes issues in two scenarios:

  1. Direct client access: When a client makes a request directly to the proxy with the prefix (e.g., /playwright/sse), the proxy forwards it as-is to the backend, which expects /sse without the prefix.

  2. Ingress without prefix stripping: When an ingress controller doesn't strip the prefix before forwarding, the backend receives requests with the prefix that it doesn't expect.

Current Behavior

  • SSE response URLs are rewritten with prefix: /sse/playwright/sse
  • Request paths are forwarded as-is: /playwright/sse → backend receives /playwright/sse

Expected Behavior

  • If ingress already stripped the prefix (detected via X-Forwarded-Prefix header), proxy should not strip again
  • If ingress didn't strip OR client makes direct request, proxy should strip the prefix before forwarding
  • Backend should always receive paths without the prefix: /playwright/sse/sse

Solution

Implement prefix stripping in the proxy's Director function that:

  • Strips endpointPrefix from request paths when present at the start
  • Detects if ingress already stripped via X-Forwarded-Prefix header (when trustProxyHeaders is enabled)
  • Handles edge cases like prefix appearing later in path (e.g., /abc/abc/sse with prefix /abc/abc/sse)

Related

  • Affects: SSE transport with endpointPrefix configuration
  • Related to: Ingress path-based routing scenarios
  • Implementation: pkg/transport/proxy/transparent/transparent_proxy.go

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggoPull requests that update go codeproxy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions