Class TransportDetector

java.lang.Object
com.tnsai.mcp.client.TransportDetector

public class TransportDetector extends Object
Auto-detects the best MCP transport for a given endpoint.

Detection order:

  1. Streamable HTTP - POST a JSON-RPC request, check for valid response
  2. SSE - GET with Accept: text/event-stream
  3. HTTP fallback - basic HttpTransport

Usage

 McpTransport transport = TransportDetector.detect("https://api.example.com/mcp");
 McpClient client = new McpClient(transport);
 
See Also:
  • Method Details

    • detect

      public static McpTransport detect(String endpoint) throws IOException
      Detects the best transport for a given endpoint.
      Parameters:
      endpoint - the MCP server endpoint URL
      Returns:
      the detected transport
      Throws:
      IOException - if detection fails for all transport types
    • detect

      public static McpTransport detect(String endpoint, Map<String,String> headers) throws IOException
      Detects the best transport for a given endpoint with custom headers.
      Parameters:
      endpoint - the MCP server endpoint URL
      headers - custom headers for authentication
      Returns:
      the detected transport
      Throws:
      IOException - if detection fails for all transport types