Skip to content
docsv0.2.0

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

Parameters of __construct()
NameTypeDescription
$baseUrlstringBase URL of the MCP server
$headersarray<string, string>Additional HTTP headers
$timeoutintRequest 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(): void

Verify the server is reachable by running the MCP `initialize` handshake over HTTP.

HttpSseTransport::disconnect()

public function disconnect(): void

HttpSseTransport::isConnected()

public function isConnected(): bool

HttpSseTransport::request()

public function request(string $method, array $params = []): array

POST a JSON-RPC request and parse the reply, whether it comes back as SSE or plain JSON.

Parameters

Parameters of request()
NameTypeDescription
$methodstring
$paramsarray<string, mixed>

HttpSseTransport::notify()

public function notify(string $method, array $params = []): void

POST 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

Parameters of notify()
NameTypeDescription
$methodstring
$paramsarray<string, mixed>