Builder
Fluent builder for creating Client instances.
Tags
Table of Contents
Properties
- $capabilities : ClientCapabilities|null
- $description : string|null
- $extensions : array<string, array<string, mixed>>
- $initTimeout : int
- $logger : LoggerInterface|null
- $maxRetries : int
- $name : string
- $notificationHandlers : array<string|int, NotificationHandlerInterface>
- $protocolVersion : ProtocolVersion|null
- $requestHandlers : array<string|int, RequestHandlerInterface<string|int, mixed>>
- $requestTimeout : int
- $title : string|null
- $version : string
Methods
- addNotificationHandler() : self
- Add a notification handler for server notifications.
- addRequestHandler() : self
- Add a request handler for server requests (e.g., sampling).
- build() : Client
- Build the client instance.
- enableExtension() : self
- Enable one or more MCP protocol extensions, announced to the server under `capabilities.extensions` in the initialize request.
- setCapabilities() : self
- Set client capabilities.
- setClientInfo() : self
- Set the client name and version.
- setInitTimeout() : self
- Set initialization timeout in seconds.
- setLogger() : self
- Set the logger.
- setMaxRetries() : self
- Set the number of times a failed connection attempt is retried.
- setProtocolVersion() : self
- Set the protocol version to use.
- setRequestTimeout() : self
- Set request timeout in seconds.
Properties
$capabilities
private
ClientCapabilities|null
$capabilities
= null
$description
private
string|null
$description
= null
$extensions
private
array<string, array<string, mixed>>
$extensions
= []
$initTimeout
private
int
$initTimeout
= 30
$logger
private
LoggerInterface|null
$logger
= null
$maxRetries
private
int
$maxRetries
= 3
$name
private
string
$name
= 'mcp-php-client'
$notificationHandlers
private
array<string|int, NotificationHandlerInterface>
$notificationHandlers
= []
$protocolVersion
private
ProtocolVersion|null
$protocolVersion
= null
$requestHandlers
private
array<string|int, RequestHandlerInterface<string|int, mixed>>
$requestHandlers
= []
$requestTimeout
private
int
$requestTimeout
= 120
$title
private
string|null
$title
= null
$version
private
string
$version
= '1.0.0'
Methods
addNotificationHandler()
Add a notification handler for server notifications.
public
addNotificationHandler(NotificationHandlerInterface $handler) : self
Parameters
- $handler : NotificationHandlerInterface
Return values
selfaddRequestHandler()
Add a request handler for server requests (e.g., sampling).
public
addRequestHandler(RequestHandlerInterface<string|int, mixed> $handler) : self
Parameters
- $handler : RequestHandlerInterface<string|int, mixed>
Return values
selfbuild()
Build the client instance.
public
build() : Client
Return values
ClientenableExtension()
Enable one or more MCP protocol extensions, announced to the server under `capabilities.extensions` in the initialize request.
public
enableExtension(ExtensionInterface ...$extensions) : self
Parameters
- $extensions : ExtensionInterface
Tags
Return values
selfsetCapabilities()
Set client capabilities.
public
setCapabilities(ClientCapabilities $capabilities) : self
Parameters
- $capabilities : ClientCapabilities
Return values
selfsetClientInfo()
Set the client name and version.
public
setClientInfo(string $name, string $version[, string|null $description = null ][, string|null $title = null ]) : self
Parameters
- $name : string
- $version : string
- $description : string|null = null
- $title : string|null = null
-
Display name for UI and end-user contexts. Falls back to $name when absent.
Return values
selfsetInitTimeout()
Set initialization timeout in seconds.
public
setInitTimeout(int $seconds) : self
Parameters
- $seconds : int
Return values
selfsetLogger()
Set the logger.
public
setLogger(LoggerInterface $logger) : self
Parameters
- $logger : LoggerInterface
Return values
selfsetMaxRetries()
Set the number of times a failed connection attempt is retried.
public
setMaxRetries(int $retries) : self
Counts retries, not attempts: 3 means one initial attempt plus up to three retries. Pass 0 to fail on the first failure. Only applies to Client::connect(); individual requests are never retried.
Parameters
- $retries : int
Return values
selfsetProtocolVersion()
Set the protocol version to use.
public
setProtocolVersion(ProtocolVersion $protocolVersion) : self
Parameters
- $protocolVersion : ProtocolVersion
Return values
selfsetRequestTimeout()
Set request timeout in seconds.
public
setRequestTimeout(int $seconds) : self
Parameters
- $seconds : int