1. Go to this page and download the library: Download php-mcp/client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use PhpMcp\Client\Model\Capabilities as ClientCapabilities;
// Client supports sampling requests from the server
$clientCapabilities = ClientCapabilities::forClient(supportsSampling: true);
// Client does NOT support sampling
$clientCapabilities = ClientCapabilities::forClient(supportsSampling: false);
// TODO: Add support for declaring 'roots' capability if needed
use PhpMcp\Client\Enum\TransportType;
use PhpMcp\Client\ServerConfig;
// Example: Stdio Server
$stdioConfig = new ServerConfig(
name: 'local_file_server', // Required: Unique ID for this config
transport: TransportType::Stdio, // Required: Transport type
timeout: 15.0, // Optional: Request timeout (seconds)
command: 'npx', // Required for Stdio: Executable
args: [ // Optional for Stdio: Arguments array
'-y',
'@modelcontextprotocol/server-filesystem',
'/path/to/project'
],
workingDir: '/path/to/project', // Optional for Stdio: Working directory
env: ['DEBUG' => 'mcp*'] // Optional for Stdio: Environment variables
);
// Example: HTTP Server
$httpConfig = new ServerConfig(
name: 'remote_web_agent', // Required: Unique ID
transport: TransportType::Http, // Required: Transport type
timeout: 45.0, // Optional: Request timeout
url: 'http://localhost:8080/sse',// Required for Http: SSE URL
headers: [ // Optional for Http: Auth/Custom headers
'Authorization' => 'Bearer xyz789'
],
);