Overview of the MCP Client SDK
mainThe MCP Client SDK provides a synchronous, framework-agnostic API for PHP applications to communicate with MCP servers. It manages connection lifecycles, request/response correlation, server-initiated requests (sampling), and real-time notifications.
Key features include:
- Connection management via Transports.
- Synchronous API for tools, resources, and prompts.
- Support for server-initiated communication (sampling and notifications).
- Progress notification support for long-running operations.
use Mcp\
Client;
use Mcp\Client\Transport\StdioTransport;
// Build and configure the client
$client = Client::builder()
->setClientInfo('My Client', '1.0.0')
->setInitTimeout(30)
->setRequestTimeout(120)
->build();
// Create a transport
$transport = new StdioTransport(
command: 'php',
args: ['/path/to/server.php'],
);
// Connect and use the server
$client->connect($transport);
$tools = $client->listTools();
$client->disconnect();