MCP PHP SDK

Client

Main MCP Client facade.

Provides a synchronous API for communicating with MCP servers. All blocking operations are delegated to the transport.

Tags
author

Kyrian Obikwelu koshnawaza@gmail.com

Table of Contents

Properties

$config  : Configuration
$logger  : LoggerInterface
$protocol  : Protocol
$transport  : TransportInterface|null

Methods

__construct()  : mixed
builder()  : Builder
Create a new client builder for fluent configuration.
callTool()  : CallToolResult
Call a tool on the server.
complete()  : CompletionCompleteResult
Request completion suggestions for a prompt or resource argument.
connect()  : void
Connect to an MCP server using the provided transport.
disconnect()  : void
Disconnect from the server.
getInstructions()  : string|null
Get server instructions.
getPrompt()  : GetPromptResult
Get a prompt from the server.
getServerInfo()  : Implementation|null
Get server information from initialization.
isConnected()  : bool
Check if connected and initialized.
listPrompts()  : ListPromptsResult
List available prompts from the server.
listResources()  : ListResourcesResult
List available resources from the server.
listResourceTemplates()  : ListResourceTemplatesResult
List available resource templates from the server.
listTools()  : ListToolsResult
List available tools from the server.
ping()  : void
Send a ping request to the server.
readResource()  : ReadResourceResult
Read a resource by URI.
setLoggingLevel()  : void
Set the minimum logging level for server log messages.
sendRequest()  : Response<string|int, mixed>
Send a request to the server and wait for response.

Properties

$logger read-only

private LoggerInterface $logger = new NullLogger()

Methods

builder()

Create a new client builder for fluent configuration.

public static builder() : Builder
Return values
Builder

callTool()

Call a tool on the server.

public callTool(string $name[, array<string, mixed> $arguments = [] ][, callable(float $progress, Array $total, Array $message): void|null $onProgress = null ]) : CallToolResult
Parameters
$name : string

Tool name

$arguments : array<string, mixed> = []

Tool arguments

$onProgress : callable(float $progress, Array $total, Array $message): void|null = null

Optional callback for progress updates

Return values
CallToolResult

disconnect()

Disconnect from the server.

public disconnect() : void

getInstructions()

Get server instructions.

public getInstructions() : string|null
Return values
string|null

getPrompt()

Get a prompt from the server.

public getPrompt(string $name[, array<string, string> $arguments = [] ][, callable(float $progress, Array $total, Array $message): void|null $onProgress = null ]) : GetPromptResult
Parameters
$name : string

Prompt name

$arguments : array<string, string> = []

Prompt arguments

$onProgress : callable(float $progress, Array $total, Array $message): void|null = null

Optional callback for progress updates

Return values
GetPromptResult

isConnected()

Check if connected and initialized.

public isConnected() : bool
Return values
bool

listTools()

List available tools from the server.

public listTools([string|null $cursor = null ]) : ListToolsResult
Parameters
$cursor : string|null = null
Return values
ListToolsResult

ping()

Send a ping request to the server.

public ping() : void

readResource()

Read a resource by URI.

public readResource(string $uri[, callable(float $progress, Array $total, Array $message): void|null $onProgress = null ]) : ReadResourceResult
Parameters
$uri : string

The resource URI

$onProgress : callable(float $progress, Array $total, Array $message): void|null = null

Optional callback for progress updates

Return values
ReadResourceResult

setLoggingLevel()

Set the minimum logging level for server log messages.

public setLoggingLevel(LoggingLevel $level) : void
Parameters
$level : LoggingLevel

sendRequest()

Send a request to the server and wait for response.

private sendRequest(Request $request[, callable(float $progress, Array $total, Array $message): void|null $onProgress = null ]) : Response<string|int, mixed>
Parameters
$request : Request
$onProgress : callable(float $progress, Array $total, Array $message): void|null = null
Tags
throws
RequestException|ConnectionException
Return values
Response<string|int, mixed>

        
On this page

Search results