OpenCode MCP client should follow HTTP 307 redirects #3909

Closed
opened 2026-02-16 17:41:54 -05:00 by yindo · 3 comments
Owner

Originally created by @kierr on GitHub (Dec 27, 2025).

Originally assigned to: @thdxr on GitHub.

Feature Request

OpenCode's MCP client should automatically follow HTTP 307 redirects when connecting to remote servers

Current Behavior

When connecting to a remote MCP server that returns a 307 redirect:

  1. Initial request (POST/GET) to /mcp returns HTTP 307 with Location: /mcp/
  2. OpenCode does NOT follow the redirect
  3. Request fails, connection is lost
  4. Falls back to next transport (SSE) which also fails

Evidence

Claude Code successfully connects to https://litellm.wild-hexatonic.ts.net/mcp (no trailing slash) because:

  • It either follows the 307 redirect automatically, OR
  • It sends the correct path with trailing slash

OpenCode fails with same URL because it does not follow the 307 redirect:

POST https://litellm.wild-hexatonic.ts.net/mcp → 307 → /mcp/ → connection lost

Requested Behavior

  1. Automatically follow HTTP 307 redirects during initial connection
  2. Preserve HTTP method, headers, and request body when following redirects
  3. Support redirect: follow option in MCP config for manual control

Workaround

Users must currently configure the full redirect path (e.g., /mcp/context7) in their config to avoid redirects.

References

  • HTTP RFC 7231 (Section 6.4) defines 307 Temporary Redirect behavior
  • Standard fetch APIs (browsers, curl, etc.) automatically follow 307 redirects by default
  • MCP SDK (@modelcontextprotocol/sdk) should handle redirects transparently
Originally created by @kierr on GitHub (Dec 27, 2025). Originally assigned to: @thdxr on GitHub. ## Feature Request OpenCode's MCP client should automatically follow HTTP 307 redirects when connecting to remote servers ### Current Behavior When connecting to a remote MCP server that returns a 307 redirect: 1. Initial request (POST/GET) to /mcp returns HTTP 307 with Location: /mcp/ 2. OpenCode does NOT follow the redirect 3. Request fails, connection is lost 4. Falls back to next transport (SSE) which also fails ### Evidence Claude Code successfully connects to https://litellm.wild-hexatonic.ts.net/mcp (no trailing slash) because: - It either follows the 307 redirect automatically, OR - It sends the correct path with trailing slash OpenCode fails with same URL because it does not follow the 307 redirect: POST https://litellm.wild-hexatonic.ts.net/mcp → 307 → /mcp/ → connection lost ### Requested Behavior 1. Automatically follow HTTP 307 redirects during initial connection 2. Preserve HTTP method, headers, and request body when following redirects 3. Support redirect: follow option in MCP config for manual control ### Workaround Users must currently configure the full redirect path (e.g., /mcp/context7) in their config to avoid redirects. ### References - HTTP RFC 7231 (Section 6.4) defines 307 Temporary Redirect behavior - Standard fetch APIs (browsers, curl, etc.) automatically follow 307 redirects by default - MCP SDK (@modelcontextprotocol/sdk) should handle redirects transparently
yindo closed this issue 2026-02-16 17:41:54 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Dec 27, 2025):

This issue might be a duplicate of existing issues. Please check:

  • #6246: litellm gateway /mcp/ endpoint has broken routing (same root cause - 307 redirect handling)
  • #5371: Support MCP servers that require POST-based or non-standard SSE handshake (related MCP server connection improvements)

The underlying issue appears to be that OpenCode's MCP client doesn't follow HTTP 307 redirects during initial connection, which prevents it from working with servers that redirect based on trailing slashes.

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Dec 27, 2025): This issue might be a duplicate of existing issues. Please check: - #6246: litellm gateway /mcp/ endpoint has broken routing (same root cause - 307 redirect handling) - #5371: Support MCP servers that require POST-based or non-standard SSE handshake (related MCP server connection improvements) The underlying issue appears to be that OpenCode's MCP client doesn't follow HTTP 307 redirects during initial connection, which prevents it from working with servers that redirect based on trailing slashes. Feel free to ignore if none of these address your specific case.
Author
Owner

@kierr commented on GitHub (Dec 27, 2025):

Unproven assumption - no evidence that OpenCode doesn't follow redirects. Claude Code may use different client library, different timeout settings, or connect to /mcp/context7 workaround endpoint. Needs actual investigation before filing.

@kierr commented on GitHub (Dec 27, 2025): Unproven assumption - no evidence that OpenCode doesn't follow redirects. Claude Code may use different client library, different timeout settings, or connect to /mcp/context7 workaround endpoint. Needs actual investigation before filing.
Author
Owner

@kierr commented on GitHub (Dec 27, 2025):

Issue based on assumption without evidence. curl -L shows redirect IS followed for POST requests (makes second POST to /mcp/). The actual problem is litellm gateway's /mcp/ endpoint redirects POST to same path with slash added, which causes the redirect to occur in the first place. Claude Code likely works due to different implementation details or timeout settings, not redirect handling.

@kierr commented on GitHub (Dec 27, 2025): Issue based on assumption without evidence. curl -L shows redirect IS followed for POST requests (makes second POST to /mcp/). The actual problem is litellm gateway's /mcp/ endpoint redirects POST to same path with slash added, which causes the redirect to occur in the first place. Claude Code likely works due to different implementation details or timeout settings, not redirect handling.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3909