Skip to content

Update routing for streamable HTTP to avoid 307 redirect #1115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 11, 2025

Conversation

yurikunash
Copy link
Contributor

@yurikunash yurikunash commented Jul 10, 2025

Setup the endpoint for the streamable HTTP (/mcp) in the routing table as a route served by an ASGI app, instead of mounting it as a base path.

Resolves: #732

As mentioned in MCP specification (version 2025-06-18):

The server MUST provide a single HTTP endpoint path (hereafter referred to as the MCP endpoint) that supports both POST and GET methods. For example, this could be a URL like https://example.com/mcp

This also aligns with JSON-RPC specification.

Motivation and Context

The change is required to avoid a 307 Temporary Redirect, from /mcp to /mcp/ endpoint, which currently happens. The redirect causes issues for several popular clients and also impedes hosting MCP servers behind proxy servers.

How Has This Been Tested?

Tested locally and on a remote server with MCP clients.

Breaking Changes

The users who have MCP clients configured to consume the endpoint with a slash, e.g. /mcp/, will start experiencing a 307 Temporary redirect to the endpoint without the slash /mcp.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@yurikunash yurikunash changed the title Remove submounting for streamable http (avoid 307 redirect and trailing slash) Update routing for streamable HTTP to avoid 307 redirect Jul 10, 2025
@yurikunash yurikunash marked this pull request as ready for review July 10, 2025 07:47
ihrpr
ihrpr previously approved these changes Jul 11, 2025
Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

#781 is addressing the same issue, I'll add a similar test to this PR.

ihrpr
ihrpr previously approved these changes Jul 11, 2025
@ihrpr ihrpr merged commit fd11eca into modelcontextprotocol:main Jul 11, 2025
10 checks passed
@yurikunash yurikunash deleted the 307_redirect branch July 11, 2025 12:01
@yurikunash
Copy link
Contributor Author

Thank you for looking into the PR @ihrpr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

307 Temporary Redirect
2 participants