HttpSseTransport
HTTP/SSE Transport for MCP servers. This transport is used for remote MCP servers like Cloudflare's. Communication flow: 1. Client sends JSON-RPC request via HTTP POST 2. Server responds via Server-Sent Events (SSE) or direct JSON response Every exchange is a single buffered POST/response — the "SSE" side is just an alternate `Content-Type` this class parses out of an already-fully-read body (see {@see parseSseResponse()}); there is no long-lived streamed connection. That is what makes the whole request/notify path a clean fit for PSR-18's `ClientInterface`: nothing here needs chunked/incremental reads that `ClientInterface::sendRequest()` couldn't give us.
HttpSseTransport::__construct()
public function __construct(string $baseUrl, array $headers = [], int $timeout = 30, ?string $serverName = null, ?Psr\Http\Client\ClientInterface $httpClient = null, ?Psr\Http\Message\RequestFactoryInterface $requestFactory = null, ?Psr\Http\Message\StreamFactoryInterface $streamFactory = null, ?Psr\Log\LoggerInterface $logger = null):Parameters
| Name | Type | Description |
|---|---|---|
| $baseUrl | string | Base URL of the MCP server |
| $headers | array<string, string> | Additional HTTP headers |
| $timeout | int | Request timeout in seconds; only applied when `$httpClient` is omitted (it configures the default Guzzle client this class builds) |
| $serverName | (string | null) | Server name for error messages |
| $httpClient | (ClientInterface | null) | PSR-18 HTTP client; defaults to a Guzzle client configured with `$timeout` |
| $requestFactory | (RequestFactoryInterface | null) | PSR-17 request factory; defaults to `GuzzleHttp\Psr7\HttpFactory` |
| $streamFactory | (StreamFactoryInterface | null) | PSR-17 stream factory; defaults to `GuzzleHttp\Psr7\HttpFactory` |
| $logger | (LoggerInterface | null) | Optional logger for notify() failures (notifications are fire-and-forget per {@see TransportInterface::notify()}, so failures are logged, not thrown) |
HttpSseTransport::connect()
public function connect(): voidVerify the server is reachable by running the MCP `initialize` handshake over HTTP.
HttpSseTransport::disconnect()
public function disconnect(): voidHttpSseTransport::isConnected()
public function isConnected(): boolHttpSseTransport::request()
public function request(string $method, array $params = []): arrayPOST a JSON-RPC request and parse the reply, whether it comes back as SSE or plain JSON.
Parameters
| Name | Type | Description |
|---|---|---|
| $method | string | |
| $params | array<string, mixed> |
HttpSseTransport::notify()
public function notify(string $method, array $params = []): voidPOST a JSON-RPC notification; the response, if any, is discarded. Per {@see TransportInterface::notify()}, notifications are fire-and-forget — the interface declares no `@throws`, and callers (e.g. {@see connect()}) rely on that. A transport failure here is therefore logged, not thrown, so it isn't silently dropped.
Parameters
| Name | Type | Description |
|---|---|---|
| $method | string | |
| $params | array<string, mixed> |