Skip to content

Conversation

@mfaferek93
Copy link

@mfaferek93 mfaferek93 commented Feb 1, 2026

Pull Request

Summary

The previous implementation incorrectly used ASGI handlers (scope, receive, send) with Starlette Route(), which doesn't work. Route() expects endpoint functions that take a Request object.

Changes per MCP SDK documentation (mcp/server/sse.py):

  • handle_sse now takes Request and uses request._send
  • Returns Response() to avoid NoneType error on disconnect
  • Messages endpoint uses Mount() with ASGI handler directly
  • Removed unused handle_messages function

Issue

Link the related issue (required):

  • closes #

Type

  • Bug fix
  • New feature
  • Breaking change
  • Documentation only

Testing

How was this tested / how should reviewers verify it?


Checklist

  • Breaking changes are clearly described (and announced in docs / changelog if needed)
  • Linting passes (poetry run ruff check src/ tests/)
  • Formatting passes (poetry run ruff format --check src/ tests/)
  • Type checking passes (poetry run mypy src/)
  • Tests pass (poetry run python run_tests.py)
  • Docs were updated if behavior or public API changed

Copilot AI review requested due to automatic review settings February 1, 2026 17:07
@mfaferek93 mfaferek93 self-assigned this Feb 1, 2026
@mfaferek93 mfaferek93 added the bug Something isn't working label Feb 1, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes incorrect ASGI handler usage in the SSE transport layer by aligning the implementation with MCP SDK documentation patterns. The changes address compatibility issues where Route() was incorrectly used with ASGI handlers instead of Request-based endpoints.

Changes:

  • Modified handle_sse to accept a Request object instead of raw ASGI parameters (scope, receive, send)
  • Changed POST message routing from Route() to Mount() with direct ASGI handler
  • Removed unused handle_messages wrapper function

The previous implementation incorrectly used ASGI handlers (scope, receive, send)
with Starlette Route(), which doesn't work. Route() expects endpoint functions
that take a Request object.

Changes per MCP SDK documentation (mcp/server/sse.py):
- handle_sse now takes Request and uses request._send
- Returns Response() to avoid NoneType error on disconnect
- Messages endpoint uses Mount() with ASGI handler directly
- Removed unused handle_messages function
@mfaferek93 mfaferek93 force-pushed the fix/sse-transport-routing branch from 87ba96c to 02191cc Compare February 1, 2026 17:12
@mfaferek93 mfaferek93 requested a review from bburda February 1, 2026 17:14
@mfaferek93 mfaferek93 merged commit 1ea4f88 into main Feb 1, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants