MCP PHP SDK

BaseTransport implements TransportInterface

AbstractYes

Base implementation for client transports.

Provides callback management and common utilities.

Tags
author

Kyrian Obikwelu koshnawaza@gmail.com

Table of Contents

Interfaces

TransportInterface
Interface for client transports that communicate with MCP servers.

Properties

$closeCallback  : callable(string): void|null
$errorCallback  : callable(Throwable): void|null
$initializeCallback  : callable(): mixed|null
$logger  : LoggerInterface
$messageCallback  : callable(string): void|null
$state  : ClientStateInterface|null

Methods

__construct()  : mixed
onClose()  : void
Register callback for when connection closes.
onError()  : void
Register callback for transport errors.
onInitialize()  : void
Register callback for initialization handshake.
onMessage()  : void
Register callback for incoming messages from server.
setState()  : void
Set the client state for runtime state management.
handleClose()  : void
Handle connection close.
handleError()  : void
Handle a transport error.
handleInitialize()  : mixed
Perform initialization via the registered callback.
handleMessage()  : void
Handle an incoming message from the server.

Properties

$closeCallback

protected callable(string): void|null $closeCallback

$errorCallback

protected callable(Throwable): void|null $errorCallback

$initializeCallback

protected callable(): mixed|null $initializeCallback

$messageCallback

protected callable(string): void|null $messageCallback

Methods

__construct()

public __construct([LoggerInterface|null $logger = null ]) : mixed
Parameters
$logger : LoggerInterface|null = null

onClose()

Register callback for when connection closes.

public onClose(callable $listener) : void
Parameters
$listener : callable

onError()

Register callback for transport errors.

public onError(callable $listener) : void
Parameters
$listener : callable

onInitialize()

Register callback for initialization handshake.

public onInitialize(callable $listener) : void

The callback should return a Fiber that performs the initialization.

Parameters
$listener : callable

onMessage()

Register callback for incoming messages from server.

public onMessage(callable $listener) : void
Parameters
$listener : callable

handleClose()

Handle connection close.

protected handleClose(string $reason) : void
Parameters
$reason : string

handleError()

Handle a transport error.

protected handleError(Throwable $error) : void
Parameters
$error : Throwable

handleInitialize()

Perform initialization via the registered callback.

protected handleInitialize() : mixed
Tags
throws
RuntimeException

If no initialize listener is registered

Return values
mixed

The result from the initialization callback

handleMessage()

Handle an incoming message from the server.

protected handleMessage(string $message) : void
Parameters
$message : string

        
On this page

Search results