MCP PHP SDK

Builder

FinalYes

Fluent builder for creating Client instances.

Tags
author

Kyrian Obikwelu koshnawaza@gmail.com

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

$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'

$requestTimeout

private int $requestTimeout = 120

$title

private string|null $title = null

$version

private string $version = '1.0.0'

Methods

enableExtension()

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
throws
InvalidArgumentException

if the identifier is not a valid _meta prefix

LogicException

if the same extension is enabled more than once

Return values
self

setClientInfo()

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
self

setInitTimeout()

Set initialization timeout in seconds.

public setInitTimeout(int $seconds) : self
Parameters
$seconds : int
Return values
self

setLogger()

Set the logger.

public setLogger(LoggerInterface $logger) : self
Parameters
$logger : LoggerInterface
Return values
self

setMaxRetries()

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
self

setProtocolVersion()

Set the protocol version to use.

public setProtocolVersion(ProtocolVersion $protocolVersion) : self
Parameters
$protocolVersion : ProtocolVersion
Return values
self

setRequestTimeout()

Set request timeout in seconds.

public setRequestTimeout(int $seconds) : self
Parameters
$seconds : int
Return values
self
On this page

Search results