class HttpTransport implements Transport, UsesProtocol, IsolatesExchanges

Properties

protected null|Closure(): ?string|string $token
protected ProtocolVersion|null $protocolVersion
protected string|null $sessionId
protected bool $initialized
protected float $timeoutSeconds
protected array<string, string> $customHeaders
protected array<int, string> $queue

Keep the protected queue while replies belong to their calling coroutine.

Methods

__construct(string $url)

Create an HTTP transport for the endpoint.

void
connect()

Reset shared negotiation state for a new connection.

void
disconnect()

Terminate the session and invalidate exchanges for their owners to close.

void
setTimeoutSeconds(float $seconds)

Set the HTTP request timeout.

void
withToken(string|Closure $token)

Set the bearer token or its resolver.

void
withHeaders(array $headers)

Add custom HTTP headers.

array
customHeaders()

Get the client's custom HTTP headers.

string
url()

Get the server endpoint URL.

array
recipe()

Get the configuration needed to recreate this transport.

void
send(string $message, array $headers = [])

Send a message in an exchange owned by the calling coroutine.

void
useProtocol(ProtocolVersion $protocolVersion)

Set the protocol version used by subsequent requests.

string
receive()

Receive the next message without waiting for the response body to end.

void
endExchange()

Close the calling coroutine's response without affecting sibling exchanges.

__destruct()

Disconnect any remaining session and responses.

bool
hasJsonRpcError(string $content)

Determine whether an HTTP error contains a protocol error response.

array
headers(array $mirrored = [])

Build headers from the current connection and credentials.

request(array $headers = [])

Prepare a request with custom headers restricted to the configured origin.

bool
reserved(string $name)

Determine whether the header belongs to the MCP protocol.

array
eraHeaders()

Get the headers required by this protocol era.

void
captureSessionId(Response $response)

Capture the legacy initialization session identifier.

void
readSseStream(Response $response)

Read one complete SSE message into the current exchange.

string
readLine(StreamInterface $stream)

Read one line without waiting for a larger body buffer to fill.

void
queueSseEvent(string $data)

Queue an SSE payload while rejecting unsupported server requests.

void
terminateSession()

Terminate an active legacy session.

void
reset()

Reset shared negotiation without closing already-sent sibling responses.

never
failWith(string $message)

Forget this exchange's failed session and report its error.

Details

at line 77
__construct(string $url)

Create an HTTP transport for the endpoint.

Parameters

string $url

at line 84
void connect()

Reset shared negotiation state for a new connection.

Return Value

void

at line 92
void disconnect()

Terminate the session and invalidate exchanges for their owners to close.

Return Value

void

at line 117
void setTimeoutSeconds(float $seconds)

Set the HTTP request timeout.

Parameters

float $seconds

Return Value

void

at line 127
void withToken(string|Closure $token)

Set the bearer token or its resolver.

Parameters

string|Closure $token

Return Value

void

at line 137
void withHeaders(array $headers)

Add custom HTTP headers.

Parameters

array $headers

Return Value

void

at line 147
array customHeaders()

Get the client's custom HTTP headers.

Return Value

array

at line 155
string url()

Get the server endpoint URL.

Return Value

string

at line 165
array recipe()

Get the configuration needed to recreate this transport.

Return Value

array

at line 181
void send(string $message, array $headers = [])

Send a message in an exchange owned by the calling coroutine.

Parameters

string $message
array $headers

Return Value

void

at line 279
void useProtocol(ProtocolVersion $protocolVersion)

Set the protocol version used by subsequent requests.

Parameters

ProtocolVersion $protocolVersion

Return Value

void

at line 293
string receive()

Receive the next message without waiting for the response body to end.

Return Value

string

at line 314
void endExchange()

Close the calling coroutine's response without affecting sibling exchanges.

Return Value

void

at line 325
__destruct()

Disconnect any remaining session and responses.

at line 333
protected bool hasJsonRpcError(string $content)

Determine whether an HTTP error contains a protocol error response.

Parameters

string $content

Return Value

bool

at line 346
protected array headers(array $mirrored = [])

Build headers from the current connection and credentials.

Parameters

array $mirrored

Return Value

array

at line 383
protected PendingRequest request(array $headers = [])

Prepare a request with custom headers restricted to the configured origin.

Parameters

array $headers

Return Value

PendingRequest

at line 403
protected bool reserved(string $name)

Determine whether the header belongs to the MCP protocol.

Parameters

string $name

Return Value

bool

at line 413
protected array eraHeaders()

Get the headers required by this protocol era.

Return Value

array

at line 437
protected void captureSessionId(Response $response)

Capture the legacy initialization session identifier.

Parameters

Response $response

Return Value

void

at line 453
protected void readSseStream(Response $response)

Read one complete SSE message into the current exchange.

Parameters

Response $response

Return Value

void

at line 495
protected string readLine(StreamInterface $stream)

Read one line without waiting for a larger body buffer to fill.

Parameters

StreamInterface $stream

Return Value

string

at line 505
protected void queueSseEvent(string $data)

Queue an SSE payload while rejecting unsupported server requests.

Parameters

string $data

Return Value

void

at line 523
protected void terminateSession()

Terminate an active legacy session.

Return Value

void

at line 543
protected void reset()

Reset shared negotiation without closing already-sent sibling responses.

Return Value

void

at line 554
protected never failWith(string $message)

Forget this exchange's failed session and report its error.

Parameters

string $message

Return Value

never