class Client

Properties

protected Protocol $protocol
protected string|null $name
protected null|array<int, string> $onlyTools
protected array<int, string> $exceptTools

Methods

__construct(Transport $transport, Implementation|null $clientInfo = null)

Create a client for the supplied transport.

defaultClientInfo()

Get the application's default client information.

setName(string|null $name)

Set the client's registered name.

static Client
local(string $command, array $args = [], array $env = [])

Create a local subprocess client.

static WebClient
web(string $url)

Create an HTTP client.

withCache(string|null $store = null, string|null $for = null)

Cache eligible responses in the given store and scope.

withoutCache()

Disable response caching.

withTimeout(float $seconds)

Set the transport timeout.

onlyTools(array $tools)

Limit calls to the given tool patterns.

exceptTools(array $tools)

Exclude the given tool patterns.

bool
allowsTool(string $name)

Determine whether the tool is allowed on this client.

connect()

Connect and negotiate the server protocol.

void
disconnect()

Disconnect the client and release its transport.

bool
connected()

Determine whether the client is connected.

initializeResult()

Get the legacy initialization result.

discoverResult()

Get the discovery result.

array
capabilities()

Get the server's negotiated capabilities.

serverInfo()

Get the server's implementation information.

string|null
instructions()

Get the server's instructions.

withProtocolVersion(ProtocolVersion|null $version)

Pin the client to a supported protocol version.

ProtocolVersion
protocolVersion()

Get the negotiated protocol version.

void
ping()

Ping the server.

tools(int|null $limit = null, iterable|null $default = null)

List the available tools allowed on this client.

callTool(Tool|string $tool, array $arguments = [])

Call a tool with the given arguments.

prompts(int|null $limit = null, iterable|null $default = null)

List the server's prompts.

getPrompt(string $name, array $arguments = [])

Get a prompt with the given arguments.

resources(int|null $limit = null, iterable|null $default = null)

List the server's resources.

readResource(string $uri)

Read the resource at the given URI.

array
__serialize()

Serialize the client's name or connection recipe.

void
__unserialize(array $data)

Restore the client without restoring a live connection.

void
restoreNamedClient(Client $client)

Restore configuration from the registered factory without reusing its connection.

__destruct()

Disconnect a remaining live connection.

Details

at line 56
__construct(Transport $transport, Implementation|null $clientInfo = null)

Create a client for the supplied transport.

Parameters

Transport $transport
Implementation|null $clientInfo

at line 68
protected Implementation defaultClientInfo()

Get the application's default client information.

Return Value

Implementation

at line 79
Client setName(string|null $name)

Set the client's registered name.

Parameters

string|null $name

Return Value

Client

at line 92
static Client local(string $command, array $args = [], array $env = [])

Create a local subprocess client.

Parameters

string $command
array $args
array $env

Return Value

Client

at line 100
static WebClient web(string $url)

Create an HTTP client.

Parameters

string $url

Return Value

WebClient

at line 108
Client withCache(string|null $store = null, string|null $for = null)

Cache eligible responses in the given store and scope.

Parameters

string|null $store
string|null $for

Return Value

Client

at line 118
Client withoutCache()

Disable response caching.

Return Value

Client

at line 128
Client withTimeout(float $seconds)

Set the transport timeout.

Parameters

float $seconds

Return Value

Client

at line 140
Client onlyTools(array $tools)

Limit calls to the given tool patterns.

Parameters

array $tools

Return Value

Client

at line 152
Client exceptTools(array $tools)

Exclude the given tool patterns.

Parameters

array $tools

Return Value

Client

at line 162
bool allowsTool(string $name)

Determine whether the tool is allowed on this client.

Parameters

string $name

Return Value

bool

at line 171
Client connect()

Connect and negotiate the server protocol.

Return Value

Client

at line 181
void disconnect()

Disconnect the client and release its transport.

Return Value

void

at line 189
bool connected()

Determine whether the client is connected.

Return Value

bool

at line 197
InitializeResult|null initializeResult()

Get the legacy initialization result.

Return Value

InitializeResult|null

at line 205
DiscoverResult|null discoverResult()

Get the discovery result.

Return Value

DiscoverResult|null

at line 215
array capabilities()

Get the server's negotiated capabilities.

Return Value

array

at line 225
Implementation|null serverInfo()

Get the server's implementation information.

Return Value

Implementation|null

at line 235
string|null instructions()

Get the server's instructions.

Return Value

string|null

at line 245
Client withProtocolVersion(ProtocolVersion|null $version)

Pin the client to a supported protocol version.

Parameters

ProtocolVersion|null $version

Return Value

Client

at line 263
ProtocolVersion protocolVersion()

Get the negotiated protocol version.

Return Value

ProtocolVersion

at line 273
void ping()

Ping the server.

Return Value

void

at line 284
Collection tools(int|null $limit = null, iterable|null $default = null)

List the available tools allowed on this client.

Parameters

int|null $limit
iterable|null $default

Return Value

Collection

at line 303
ToolResult callTool(Tool|string $tool, array $arguments = [])

Call a tool with the given arguments.

Parameters

Tool|string $tool
array $arguments

Return Value

ToolResult

at line 337
Collection prompts(int|null $limit = null, iterable|null $default = null)

List the server's prompts.

Parameters

int|null $limit
iterable|null $default

Return Value

Collection

at line 355
PromptResult getPrompt(string $name, array $arguments = [])

Get a prompt with the given arguments.

Parameters

string $name
array $arguments

Return Value

PromptResult

at line 366
Collection resources(int|null $limit = null, iterable|null $default = null)

List the server's resources.

Parameters

int|null $limit
iterable|null $default

Return Value

Collection

at line 382
ResourceReadResult readResource(string $uri)

Read the resource at the given URI.

Parameters

string $uri

Return Value

ResourceReadResult

at line 392
array __serialize()

Serialize the client's name or connection recipe.

Return Value

array

at line 414
void __unserialize(array $data)

Restore the client without restoring a live connection.

Parameters

array $data

Return Value

void

at line 442
protected void restoreNamedClient(Client $client)

Restore configuration from the registered factory without reusing its connection.

Parameters

Client $client

Return Value

void

at line 453
__destruct()

Disconnect a remaining live connection.