Skip to content

Conversation

JAORMX
Copy link
Collaborator

@JAORMX JAORMX commented Aug 29, 2025

Summary

This PR fixes issue #1187 where the parsing middleware was failing on SSE streams when the path didn't contain `/messages`, `/message`, or `/mcp`.

Problem

The MCP spec allows for various endpoints to be used:

  • Streamable HTTP transport: single endpoint
  • SSE transport: two distinct endpoints (one for SSE stream, one for messages)

However, our parsing middleware was only processing requests to specific paths, causing failures with MCP servers like gofetch that use different endpoint paths (e.g., `/sse` for both SSE stream and messages).

Solution

  • Removed the path restriction in `shouldParseMCPRequest` function
  • Now parse all POST requests with JSON content type (except SSE establishment endpoints)
  • The middleware is now path-agnostic and works with any valid MCP endpoint configuration

Changes

  1. pkg/mcp/parser.go: Updated `shouldParseMCPRequest` to remove path filtering
  2. pkg/mcp/parser_test.go: Updated existing tests to reflect the new behavior
  3. pkg/mcp/parser_integration_test.go: Added comprehensive integration tests using the mcp-go library

Testing

  • ✅ All existing tests pass
  • ✅ Added integration tests with actual MCP server implementations
  • ✅ Tested with various endpoint paths including:
    • Standard paths (`/messages`, `/mcp`)
    • Custom paths (`/rpc`, `/api`)
    • Tenant-specific paths (`/tenant/123/messages`)
    • Single endpoint configurations (like gofetch's `/sse`)

Related Issues

Fixes #1187

Checklist

  • Tests added/updated
  • All tests passing
  • Code follows project conventions
  • Integration tests added using mcp-go library

@JAORMX JAORMX force-pushed the fix-issue-1187-sse-parsing branch from 8d71e3d to f87d542 Compare August 29, 2025 08:31
@JAORMX JAORMX marked this pull request as draft August 29, 2025 08:37
@JAORMX JAORMX force-pushed the fix-issue-1187-sse-parsing branch from f87d542 to 7c5a881 Compare August 29, 2025 08:42
@JAORMX JAORMX requested a review from blkt August 29, 2025 08:43
@JAORMX JAORMX marked this pull request as ready for review August 29, 2025 08:43
blkt
blkt previously approved these changes Aug 29, 2025
Copy link
Contributor

@blkt blkt left a comment

Choose a reason for hiding this comment

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

Very minor detail, let's merge this.

JAORMX added 2 commits August 29, 2025 13:39
This fixes issue #1187 where the parsing middleware was failing on SSE
streams when the path didn't contain /messages, /message, or /mcp.

The problem was that the MCP spec allows for other endpoints to be used:
- Streamable HTTP transport: single endpoint
- SSE transport: two distinct endpoints (one for SSE stream, one for messages)

Changes:
- Remove path restriction in shouldParseMCPRequest function
- Parse all POST requests with JSON content type (except SSE establishment)
- Add comprehensive integration tests using real MCP clients and servers
- Test with various endpoint paths including custom and tenant-specific paths
- Update existing tests to reflect the new behavior
- Refactor integration tests to use actual client-server interactions

The integration tests now:
- Use real MCP clients (SSE and Streamable HTTP) from mcp-go library
- Test actual client-server communication through the middleware
- Verify that requests are properly parsed regardless of endpoint path
- Cover standard paths, custom paths, and tenant-specific paths

This ensures the parser works correctly with MCP servers like gofetch
that use different endpoint paths (e.g., /sse for both SSE stream and messages).

Fixes #1187
Address code review feedback by replacing string-based test logic with
explicit struct fields. Instead of using tc.name to determine the endpoint
for streamable HTTP tests, add an 'endpoint' field to the test case struct.

This makes the test logic more explicit and less fragile, following
better testing practices by avoiding logic based on test names.

Changes:
- Add 'endpoint' field to test case struct for streamable-http transport
- Remove tc.name == 'Streamable HTTP with custom path' logic
- Use tc.endpoint directly for streamable HTTP server setup
- Maintain same test coverage with cleaner, more maintainable code
@JAORMX JAORMX force-pushed the fix-issue-1187-sse-parsing branch from bd7f5d0 to 4ea7589 Compare August 29, 2025 10:39
@JAORMX JAORMX merged commit 0f9b418 into main Aug 29, 2025
17 checks passed
@JAORMX JAORMX deleted the fix-issue-1187-sse-parsing branch August 29, 2025 10:50
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.

Parsing middleware fails on SSE streams
2 participants