HttpTransport
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
Create an HTTP transport for the endpoint.
Reset shared negotiation state for a new connection.
Terminate the session and invalidate exchanges for their owners to close.
Set the HTTP request timeout.
Add custom HTTP headers.
Get the client's custom HTTP headers.
Get the server endpoint URL.
Get the configuration needed to recreate this transport.
Send a message in an exchange owned by the calling coroutine.
Set the protocol version used by subsequent requests.
Receive the next message without waiting for the response body to end.
Close the calling coroutine's response without affecting sibling exchanges.
Disconnect any remaining session and responses.
Determine whether an HTTP error contains a protocol error response.
Build headers from the current connection and credentials.
Prepare a request with custom headers restricted to the configured origin.
Determine whether the header belongs to the MCP protocol.
Get the headers required by this protocol era.
Read one line without waiting for a larger body buffer to fill.
Queue an SSE payload while rejecting unsupported server requests.
Terminate an active legacy session.
Reset shared negotiation without closing already-sent sibling responses.
Forget this exchange's failed session and report its error.
Details
at line 77
__construct(string $url)
Create an HTTP transport for the endpoint.
at line 84
void
connect()
Reset shared negotiation state for a new connection.
at line 92
void
disconnect()
Terminate the session and invalidate exchanges for their owners to close.
at line 117
void
setTimeoutSeconds(float $seconds)
Set the HTTP request timeout.
at line 127
void
withToken(string|Closure $token)
Set the bearer token or its resolver.
at line 137
void
withHeaders(array $headers)
Add custom HTTP headers.
at line 147
array
customHeaders()
Get the client's custom HTTP headers.
at line 155
string
url()
Get the server endpoint URL.
at line 165
array
recipe()
Get the configuration needed to recreate this transport.
at line 181
void
send(string $message, array $headers = [])
Send a message in an exchange owned by the calling coroutine.
at line 279
void
useProtocol(ProtocolVersion $protocolVersion)
Set the protocol version used by subsequent requests.
at line 293
string
receive()
Receive the next message without waiting for the response body to end.
at line 314
void
endExchange()
Close the calling coroutine's response without affecting sibling exchanges.
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.
at line 346
protected array
headers(array $mirrored = [])
Build headers from the current connection and credentials.
at line 383
protected PendingRequest
request(array $headers = [])
Prepare a request with custom headers restricted to the configured origin.
at line 403
protected bool
reserved(string $name)
Determine whether the header belongs to the MCP protocol.
at line 413
protected array
eraHeaders()
Get the headers required by this protocol era.
at line 437
protected void
captureSessionId(Response $response)
Capture the legacy initialization session identifier.
at line 453
protected void
readSseStream(Response $response)
Read one complete SSE message into the current exchange.
at line 495
protected string
readLine(StreamInterface $stream)
Read one line without waiting for a larger body buffer to fill.
at line 505
protected void
queueSseEvent(string $data)
Queue an SSE payload while rejecting unsupported server requests.
at line 523
protected void
terminateSession()
Terminate an active legacy session.
at line 543
protected void
reset()
Reset shared negotiation without closing already-sent sibling responses.
at line 554
protected never
failWith(string $message)
Forget this exchange's failed session and report its error.