PHP code example of logiscape / mcp-sdk-php

1. Go to this page and download the library: Download logiscape/mcp-sdk-php 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/ */

    

logiscape / mcp-sdk-php example snippets




// An example server with a basic addition tool

ample-mcp-server');

$server
    // Define a tool
    ->tool('add-numbers', 'Adds two numbers together', function (float $a, float $b): string {
        return 'Sum: ' . ($a + $b);
    })

    // Start the server
    ->run();



// A basic example client that connects to example_server.php and calls a tool

ver stdio
    $session = $client->connect('php', ['example_server.php']);

    // Call the add-numbers tool with two arguments
    $result = $session->callTool('add-numbers', ['a' => 5, 'b' => 25]);

    // Output the result
    echo $result->content[0]->text . "\n";

} catch (\Exception $e) {
    echo "Error: " . $e->getMessage() . "\n";
    exit(1);
} finally {
    $client->close();
}
bash
composer 
bash
php example_client.php