BaseTransport implements TransportInterface uses ManagesTransportCallbacks
Provides a skeletal implementation of the TransportInterface to minimize the effort required to implement this interface.
Tags
Table of Contents
Interfaces
Constants
- YIELD_FAILED_MESSAGE : mixed = 'Failed to send the message to the client.'
Properties
- $fiberYieldHandler : callable(Array, Array, McpFiber): void
- $logger : LoggerInterface
- $messageListener : callable(TransportInterface<string|int, mixed>, string, Array, Array, Array): void
-
$outgoingMessagesProvider
: callable(Uuid): array<int, array{message: string, context: array
}> - $pendingRequestsProvider : callable(Uuid, McpFiber): array<string, array<string, mixed>>
- $responseFinder : callable(Uuid, Uuid): Array|null
- $sessionEndListener : callable(Uuid, Array): bool
- $sessionFiber : McpFiber|null
- $sessionId : Uuid|null
Methods
- __construct() : mixed
- attachFiberToSession() : void
- close() : void
- Closes the transport and cleans up any resources.
- initialize() : void
- Initializes the transport.
- onMessage() : void
- onSessionEnd() : void
- setFiberYieldHandler() : void
- setOutgoingMessagesProvider() : void
- setPendingRequestsProvider() : void
- setResponseFinder() : void
- setSessionId() : void
- Set the session ID for the current transport context.
- checkForResponse() : Response|Error|null
- endSessionOnShutdown() : void
- Ends the session of a transport shutting down, which has no client to report a store failure to.
-
getOutgoingMessages()
: array<int, array{message: string, context: array
}> - getPendingRequests() : array<string, array<string, mixed>>
- handleFiberYield() : void
- Hands what the session's fiber yielded to the yield handler.
- handleMessage() : void
- handleSessionEnd() : bool
- resumeHandlerFiber() : Error|null
- Resumes the session's fiber and handles what it yields next.
Constants
YIELD_FAILED_MESSAGE
private
mixed
YIELD_FAILED_MESSAGE
= 'Failed to send the message to the client.'
Properties
$fiberYieldHandler
protected
callable(Array, Array, McpFiber): void
$fiberYieldHandler
$logger
protected
LoggerInterface
$logger
$messageListener
protected
callable(TransportInterface<string|int, mixed>, string, Array, Array, Array): void
$messageListener
$outgoingMessagesProvider
protected
callable(Uuid): array<int, array{message: string, context: array}>
$outgoingMessagesProvider
$pendingRequestsProvider
protected
callable(Uuid, McpFiber): array<string, array<string, mixed>>
$pendingRequestsProvider
$responseFinder
protected
callable(Uuid, Uuid): Array|null
$responseFinder
$sessionEndListener
protected
callable(Uuid, Array): bool
$sessionEndListener
$sessionFiber
protected
McpFiber|null
$sessionFiber
= null
$sessionId
protected
Uuid|null
$sessionId
= null
Methods
__construct()
public
__construct([LoggerInterface|null $logger = null ]) : mixed
Parameters
- $logger : LoggerInterface|null = null
attachFiberToSession()
public
attachFiberToSession(McpFiber $fiber, Uuid $sessionId) : void
Parameters
- $fiber : McpFiber
- $sessionId : Uuid
close()
Closes the transport and cleans up any resources.
public
close() : void
initialize()
Initializes the transport.
public
initialize() : void
onMessage()
public
onMessage(callable $listener) : void
Parameters
- $listener : callable
onSessionEnd()
public
onSessionEnd(callable $listener) : void
Parameters
- $listener : callable
setFiberYieldHandler()
public
setFiberYieldHandler(callable(Array, Array, McpFiber): void $handler) : void
Parameters
- $handler : callable(Array, Array, McpFiber): void
setOutgoingMessagesProvider()
public
setOutgoingMessagesProvider(callable $provider) : void
Parameters
- $provider : callable
setPendingRequestsProvider()
public
setPendingRequestsProvider(callable $provider) : void
Parameters
- $provider : callable
setResponseFinder()
public
setResponseFinder(callable(Uuid, Uuid): Array $finder) : void
Parameters
- $finder : callable(Uuid, Uuid): Array
setSessionId()
Set the session ID for the current transport context.
public
setSessionId(Uuid|null $sessionId) : void
Parameters
- $sessionId : Uuid|null
-
The session ID, or null to clear
checkForResponse()
protected
checkForResponse(Uuid $requestId, Uuid|null $sessionId) : Response|Error|null
Parameters
- $requestId : Uuid
- $sessionId : Uuid|null
Tags
Return values
Response|Error|nullendSessionOnShutdown()
Ends the session of a transport shutting down, which has no client to report a store failure to.
protected
endSessionOnShutdown(Uuid|null $sessionId) : void
Parameters
- $sessionId : Uuid|null
getOutgoingMessages()
protected
getOutgoingMessages(Uuid|null $sessionId) : array<int, array{message: string, context: array}>
Parameters
- $sessionId : Uuid|null
Return values
array<int, array{message: string, context: arraygetPendingRequests()
protected
getPendingRequests(Uuid|null $sessionId, McpFiber $fiber) : array<string, array<string, mixed>>
Parameters
- $sessionId : Uuid|null
- $fiber : McpFiber
Return values
array<string, array<string, mixed>>handleFiberYield()
Hands what the session's fiber yielded to the yield handler.
protected
handleFiberYield(FiberSuspend|null $yielded, Uuid|null $sessionId, McpFiber $fiber) : void
When the handler fails, the message the fiber suspended on never reaches the client, so the fiber is resumed with an error instead of being left waiting on nothing; whatever it yields next is handled the same way.
Parameters
- $yielded : FiberSuspend|null
- $sessionId : Uuid|null
- $fiber : McpFiber
-
the fiber that yielded
handleMessage()
protected
handleMessage(string $payload, Uuid|null $sessionId[, AccessToken|null $accessToken = null ][, string|null $principal = null ]) : void
Parameters
- $payload : string
- $sessionId : Uuid|null
- $accessToken : AccessToken|null = null
- $principal : string|null = null
handleSessionEnd()
protected
handleSessionEnd(Uuid|null $sessionId[, string|null $principal = null ]) : bool
Parameters
- $sessionId : Uuid|null
- $principal : string|null = null
Tags
Return values
bool —false when the listener reported that the session does not exist
resumeHandlerFiber()
Resumes the session's fiber and handles what it yields next.
protected
resumeHandlerFiber(McpFiber $fiber, Uuid|null $sessionId[, FiberResume $value = null ]) : Error|null
Returns the error answering its request when it cannot be driven further, an event loop still holding it for instance: the fiber is left to its runtime, and the transport drops it.
Parameters
- $fiber : McpFiber
- $sessionId : Uuid|null
- $value : FiberResume = null