class WebClient extends Client

Properties

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

Methods

__construct(HttpTransport $httpTransport, Implementation|null $clientInfo = null, OAuthConfig|null $oAuthConfig = null)

Create an HTTP client with optional OAuth configuration.

defaultClientInfo()

Get the application's default client information.

from  Client
setName(string|null $name)

Set the client's registered name.

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

Create a local subprocess client.

from  Client
static WebClient
web(string $url)

Create an HTTP client.

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

Cache eligible responses in the given store and scope.

from  Client
withoutCache()

Disable response caching.

from  Client
withTimeout(float $seconds)

Set the transport timeout.

from  Client
onlyTools(array $tools)

Limit calls to the given tool patterns.

from  Client
exceptTools(array $tools)

Exclude the given tool patterns.

from  Client
bool
allowsTool(string $name)

Determine whether the tool is allowed on this client.

from  Client
connect()

Connect and negotiate the server protocol.

from  Client
void
disconnect()

Disconnect the client and release its transport.

from  Client
bool
connected()

Determine whether the client is connected.

from  Client
initializeResult()

Get the legacy initialization result.

from  Client
discoverResult()

Get the discovery result.

from  Client
array
capabilities()

Get the server's negotiated capabilities.

from  Client
serverInfo()

Get the server's implementation information.

from  Client
string|null
instructions()

Get the server's instructions.

from  Client
withProtocolVersion(ProtocolVersion|null $version)

Pin the client to a supported protocol version.

from  Client
ProtocolVersion
protocolVersion()

Get the negotiated protocol version.

from  Client
void
ping()

Ping the server.

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

List the available tools allowed on this client.

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

Call a tool with the given arguments.

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

List the server's prompts.

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

Get a prompt with the given arguments.

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

List the server's resources.

from  Client
readResource(string $uri)

Read the resource at the given URI.

from  Client
array
__serialize()

Serialize the client's name or connection recipe.

from  Client
void
__unserialize(array $data)

Restore the HTTP transport and registered OAuth configuration.

void
restoreNamedClient(Client $client)

Restore OAuth settings from the same factory instance as the transport.

__destruct()

Disconnect a remaining live connection.

from  Client
withToken(string|Closure $token)

Set the bearer token or its resolver.

withHeaders(array $headers)

Add custom HTTP headers.

withOAuth(string|null $clientId = null, string|null $clientSecret = null, string|null $scope = null, string|null $redirectUri = null)

Configure OAuth authorization for this client.

oAuthClient(string|null $resourceMetadataUrl = null, string|null $challengeScope = null)

Create the OAuth client for this resource and challenge.

string|null
canonicalRouteUrl(string $name)

Get the canonical URL for a registered OAuth route.

Details

at line 22
__construct(HttpTransport $httpTransport, Implementation|null $clientInfo = null, OAuthConfig|null $oAuthConfig = null)

Create an HTTP client with optional OAuth configuration.

Parameters

HttpTransport $httpTransport
Implementation|null $clientInfo
OAuthConfig|null $oAuthConfig

in Client at line 68
protected Implementation defaultClientInfo()

Get the application's default client information.

Return Value

Implementation

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

Set the client's registered name.

Parameters

string|null $name

Return Value

Client

in 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

in Client at line 100
static WebClient web(string $url)

Create an HTTP client.

Parameters

string $url

Return Value

WebClient

in Client 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

in Client at line 118
Client withoutCache()

Disable response caching.

Return Value

Client

in Client at line 128
Client withTimeout(float $seconds)

Set the transport timeout.

Parameters

float $seconds

Return Value

Client

in Client at line 140
Client onlyTools(array $tools)

Limit calls to the given tool patterns.

Parameters

array $tools

Return Value

Client

in Client at line 152
Client exceptTools(array $tools)

Exclude the given tool patterns.

Parameters

array $tools

Return Value

Client

in Client at line 162
bool allowsTool(string $name)

Determine whether the tool is allowed on this client.

Parameters

string $name

Return Value

bool

in Client at line 171
Client connect()

Connect and negotiate the server protocol.

Return Value

Client

in Client at line 181
void disconnect()

Disconnect the client and release its transport.

Return Value

void

in Client at line 189
bool connected()

Determine whether the client is connected.

Return Value

bool

in Client at line 197
InitializeResult|null initializeResult()

Get the legacy initialization result.

Return Value

InitializeResult|null

in Client at line 205
DiscoverResult|null discoverResult()

Get the discovery result.

Return Value

DiscoverResult|null

in Client at line 215
array capabilities()

Get the server's negotiated capabilities.

Return Value

array

in Client at line 225
Implementation|null serverInfo()

Get the server's implementation information.

Return Value

Implementation|null

in Client at line 235
string|null instructions()

Get the server's instructions.

Return Value

string|null

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

Pin the client to a supported protocol version.

Parameters

ProtocolVersion|null $version

Return Value

Client

in Client at line 263
ProtocolVersion protocolVersion()

Get the negotiated protocol version.

Return Value

ProtocolVersion

in Client at line 273
void ping()

Ping the server.

Return Value

void

in Client 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

in Client 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

in Client 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

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

Get a prompt with the given arguments.

Parameters

string $name
array $arguments

Return Value

PromptResult

in Client 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

in Client at line 382
ResourceReadResult readResource(string $uri)

Read the resource at the given URI.

Parameters

string $uri

Return Value

ResourceReadResult

in Client at line 392
array __serialize()

Serialize the client's name or connection recipe.

Return Value

array

at line 120
void __unserialize(array $data)

Restore the HTTP transport and registered OAuth configuration.

Parameters

array $data

Return Value

void

at line 134
protected void restoreNamedClient(Client $client)

Restore OAuth settings from the same factory instance as the transport.

Parameters

Client $client

Return Value

void

in Client at line 453
__destruct()

Disconnect a remaining live connection.

at line 35
WebClient withToken(string|Closure $token)

Set the bearer token or its resolver.

Parameters

string|Closure $token

Return Value

WebClient

at line 47
WebClient withHeaders(array $headers)

Add custom HTTP headers.

Parameters

array $headers

Return Value

WebClient

at line 57
WebClient withOAuth(string|null $clientId = null, string|null $clientSecret = null, string|null $scope = null, string|null $redirectUri = null)

Configure OAuth authorization for this client.

Parameters

string|null $clientId
string|null $clientSecret
string|null $scope
string|null $redirectUri

Return Value

WebClient

at line 77
OAuthClient oAuthClient(string|null $resourceMetadataUrl = null, string|null $challengeScope = null)

Create the OAuth client for this resource and challenge.

Parameters

string|null $resourceMetadataUrl
string|null $challengeScope

Return Value

OAuthClient

at line 106
protected string|null canonicalRouteUrl(string $name)

Get the canonical URL for a registered OAuth route.

Parameters

string $name

Return Value

string|null