Transports
The Model Context Protocol supports different transport mechanisms for communication between client and server. use-mcp supports both:
- SSE (Server-Sent Events): A persistent connection where the server pushes events to the client. Standard for MCP.
- Streamable HTTP: Uses standard HTTP POST requests with chunked transfer encoding for streaming responses.
Configuration
You can configure the transport preference in the useMcp options:
useMcp({
url: '...',
transportType: 'auto' // 'auto' | 'http' | 'sse'
})
Transport Types
auto (Default)
This is the recommended setting. The client will:
- Attempt to connect via HTTP first.
- If HTTP fails (e.g., 404 Not Found, 405 Method Not Allowed), it will automatically fall back to SSE.
http
Forces the use of StreamableHTTPClientTransport. This is useful for stateless serverless environments (like standard Cloudflare Workers or AWS Lambda) where maintaining a persistent SSE connection might be difficult or unnecessary.
sse
Forces the use of SSEClientTransport. This establishes a persistent connection suitable for long-running sessions and bidirectional event updates.