Client
Main MCP Client facade.
Provides a synchronous API for communicating with MCP servers. All blocking operations are delegated to the transport.
Tags
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
$config read-only
private
Configuration
$config
$logger read-only
private
LoggerInterface
$logger
= new NullLogger()
$protocol read-only
private
Protocol
$protocol
$transport
private
TransportInterface|null
$transport
= null
Methods
__construct()
public
__construct(Protocol $protocol, Configuration $config[, LoggerInterface $logger = new NullLogger() ]) : mixed
Parameters
- $protocol : Protocol
- $config : Configuration
- $logger : LoggerInterface = new NullLogger()
builder()
Create a new client builder for fluent configuration.
public
static builder() : Builder
Return values
BuildercallTool()
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
CallToolResultcomplete()
Request completion suggestions for a prompt or resource argument.
public
complete(PromptReference|ResourceReference $ref, array{name: string, value: string} $argument) : CompletionCompleteResult
Parameters
- $ref : PromptReference|ResourceReference
-
The prompt or resource reference
- $argument : array{name: string, value: string}
-
The argument to complete
Return values
CompletionCompleteResultconnect()
Connect to an MCP server using the provided transport.
public
connect(TransportInterface $transport) : void
Parameters
- $transport : TransportInterface
Tags
disconnect()
Disconnect from the server.
public
disconnect() : void
getInstructions()
Get server instructions.
public
getInstructions() : string|null
Return values
string|nullgetPrompt()
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
GetPromptResultgetServerInfo()
Get server information from initialization.
public
getServerInfo() : Implementation|null
Return values
Implementation|nullisConnected()
Check if connected and initialized.
public
isConnected() : bool
Return values
boollistPrompts()
List available prompts from the server.
public
listPrompts([string|null $cursor = null ]) : ListPromptsResult
Parameters
- $cursor : string|null = null
Return values
ListPromptsResultlistResources()
List available resources from the server.
public
listResources([string|null $cursor = null ]) : ListResourcesResult
Parameters
- $cursor : string|null = null
Return values
ListResourcesResultlistResourceTemplates()
List available resource templates from the server.
public
listResourceTemplates([string|null $cursor = null ]) : ListResourceTemplatesResult
Parameters
- $cursor : string|null = null
Return values
ListResourceTemplatesResultlistTools()
List available tools from the server.
public
listTools([string|null $cursor = null ]) : ListToolsResult
Parameters
- $cursor : string|null = null
Return values
ListToolsResultping()
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
ReadResourceResultsetLoggingLevel()
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