Skip to content

Conversation

@pietrozullo
Copy link
Member

Description

Implements streamable HTTP transport support in the TypeScript mcp-use library with automatic SSE fallback. The HttpConnector now intelligently tries streamable HTTP first and falls back to SSE for compatibility with older MCP servers.

Type of change

  • New feature (non-breaking change which adds functionality)

Key Changes

1. HttpConnector Enhancement

  • Now supports both streamable HTTP and SSE transports in a single connector
  • Automatically tries streamable HTTP first, falls back to SSE on failure
  • Properly detects 404/405 errors that indicate a server doesn't support streamable HTTP
  • Tracks which transport type is actively being used

2. New Connection Manager

  • Added StreamableHttpConnectionManager for managing streamable HTTP connections
  • Follows the same pattern as existing SSE/WebSocket managers for consistency
  • Provides access to session IDs when available

3. Transport Detection

  • HttpConnector now exposes getTransportType() to check which transport is in use
  • Improved error logging to clearly show fallback behavior
  • Better error messages distinguish between transport-specific failures

4. Configuration Support

  • Server configurations can use preferSse: true to force SSE transport
  • Maintains backward compatibility with existing configurations
  • No breaking changes to the API

5. Example Updates

  • Updated http_example.ts to demonstrate the new transport capabilities
  • Shows how to check which transport was selected
  • Demonstrates both automatic and forced transport selection

Implementation Details

The implementation follows the Python mcp-use pattern:

  1. Try streamable HTTP first - Better performance for modern servers
  2. Fall back to SSE on any error - Maximum compatibility
  3. Special handling for 404/405 - Clear indication that server doesn't support streamable HTTP
  4. Transparent to users - Existing code continues to work without changes

Testing

The implementation has been tested with:

  • Servers supporting only SSE (falls back correctly)
  • Servers supporting streamable HTTP (uses it successfully)
  • Servers supporting neither (appropriate error messages)
  • Various error conditions (proper fallback behavior)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • The title of my pull request follows the conventional commits standard
  • Changes have been documented in the README/documentation (if applicable)

Breaking Changes

None. This is a backward-compatible enhancement that improves performance for servers supporting streamable HTTP while maintaining full compatibility with SSE-only servers.

@pietrozullo pietrozullo merged commit cebaab7 into main Jul 5, 2025
1 check passed
@pietrozullo pietrozullo deleted the feat/streamable-http branch July 5, 2025 22:11
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.

2 participants