Skip to content

bug: auto-detected MCP URL ignores X-Forwarded-Proto — advertises http://host:8080/mcp behind an HTTPS proxy #2907

Closed

Description

@vybe

Summary

The auto-detected MCP URL that Trinity advertises to external clients (Settings → MCP URL, the connector snippets, GET /api/settings/mcp-url) is always http://<hostname>:8080/mcp, even when the request arrived over HTTPS through a reverse proxy or tunnel. On a Cloudflare Tunnel, Caddy (DigitalOcean 1-Click), or any nginx + Let's Encrypt install the correct, already-working endpoint is https://<hostname>/mcp — src/frontend/nginx.conf has proxied /mcp to the MCP container since #2281 — but the default URL still points users at plain HTTP on a port that a hardened install does not even publish.

Context

_get_default_mcp_url in src/backend/routers/settings/mcp_url.py builds the URL from the Host header alone: it hardcodes the http:// scheme and the :8080 port and ignores X-Forwarded-Proto. The frontend nginx already sets X-Forwarded-Proto $scheme on the /api/ route, so the information is on the request and simply unused.

Consequences today:

  • A tunnel/Caddy install shows an MCP URL that is either unreachable (port 8080 not published) or downgrades the client to plaintext when 8080 is open. The operator has to know to set the mcp_external_url override by hand.
  • docs/memory/requirements/mcp.md §7.6 requires the MCP port to be exposed over TLS only when MCP_INLINE_AUTH_ENABLED is on (the keyless session id is a bearer credential on the wire), yet the platform's own default URL steers keyless connector users to http://.
  • The agent-side .mcp.json validator (docker/base-image/agent_server/mcp_validator.py) rejects any owner-supplied HTTP MCP server that is not https://, so Trinity holds third parties to a rule its own advertised URL does not meet.

Out of scope here: the agent-container hop (TRINITY_MCP_URL defaulting to http://mcp-server:8080/mcp on the internal Docker bridge) and TLS termination inside the MCP container. Those are separate, larger changes; this issue is only the advertised external URL.

Acceptance Criteria

  • When the request carries X-Forwarded-Proto: https, the auto-detected default is https://<hostname>/mcp (no :8080), since the proxy serves /mcp on the same origin.
  • When the request carries X-Forwarded-Proto: http or no forwarded header, behaviour is unchanged: http://<hostname>:8080/mcp (http://localhost:8080/mcp for localhost / 127.0.0.1), so bare-VM and local dev installs are not affected.
  • A forwarded X-Forwarded-Host (when present) takes precedence over Host for the hostname, matching how the other proxied routes are resolved; if the codebase has no precedent for trusting X-Forwarded-Host, document the decision to stick with Host in the PR.
  • The stored mcp_external_url override continues to win over auto-detection; the GET /api/settings/mcp-url response still returns both url and default_url.
  • Connector snippets (src/backend/services/connector_service.py) and the enterprise connector route (src/backend/routers/connector.py) pick up the corrected default through resolve_mcp_url with no change on their side.
  • Unit tests cover the three cases: forwarded https, forwarded http, no header; plus the override-wins case.
  • The Settings → MCP URL panel shows honest status: the auto-detected value is labelled as detected from the proxy, and the override hint still explains when to set one.

Technical Notes

  • Change site: _get_default_mcp_url(request) in src/backend/routers/settings/mcp_url.py. Read request.headers.get("x-forwarded-proto"), take the first value if comma-separated (multi-hop proxies), and compare case-insensitively.
  • Only trust the forwarded scheme to upgrade the URL shape; never downgrade an explicit https override.
  • docs/DEPLOYMENT.md "TLS on a bare VM" already documents the three edge options (tunnel, private network, own reverse proxy); a one-line note that the MCP URL is now detected from the proxy scheme belongs there.
  • Related: feat: DigitalOcean Marketplace 1-Click Droplet listing for Trinity (vendor application + Packer snapshot, AI Agents category) #2281 (nginx /mcp proxy for hosted installs).

Activity

  1. added
    priority-p2
    type-bug
    theme-security
    complexity-low
    status-ready
    on Sep 19, 2026
  2. removed
    status-ready
    on Oct 19, 2026
  3. obasilakis commented on Oct 19, 2026

    @obasilakis
    Contributor

    /claim

  4. added
    status-in-progress
    on Oct 19, 2026
  5. github-actions commented on Oct 19, 2026

    @github-actions

    Claimed by @obasilakis. Label status-in-progress added.

    Next steps:

    1. Create branch: feature/2907-<short-slug>
    2. Implement the feature
    3. Open a PR with Fixes #2907
  6. added
    status-in-dev
    and removed
    status-in-progress
    on Oct 19, 2026
  7. removed
    status-in-dev
    on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-lowpriority-p2theme-securitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions