Skip to content

Latest commit

 

History

History
41 lines (35 loc) · 1.48 KB

File metadata and controls

41 lines (35 loc) · 1.48 KB

Clients

The client side is for applications that use MCP servers: you connect to a server, discover what it offers, and call it. The API is synchronous — every method returns a result or throws.

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();
  • Connecting to a server — the builder, the connection lifecycle, and what the server told you about itself during initialization.
  • Transports — launching a local server process (STDIO) or talking to a remote one (HTTP).
  • Tools, resources & prompts — listing and calling everything a server exposes, including progress callbacks and completions.
  • Server-initiated requests — the other direction: log messages, sampling requests, and elicitations the server sends you.
  • Error handling — which exception means what, plus a complete end-to-end example.
  • Clients on this revision — the one builder line that speaks protocol revision 2026-07-28, and what it changes underneath.