PHP code example of scriptoshi / laravel-mcp-client

1. Go to this page and download the library: Download scriptoshi/laravel-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/ */

    

scriptoshi / laravel-mcp-client example snippets


use Scriptoshi\McpClient\Facades\McpClient;

// Start a new chat
McpClient::processRequest("What's the weather like?", $chatUuid);

use Scriptoshi\McpClient\Contracts\McpServerInterface;

class WeatherServer implements McpServerInterface
{
    public function initialize(): array
    {
        return [
            'serverInfo' => [
                'name' => 'WeatherServer',
                'version' => '1.0.0'
            ],
            'capabilities' => [
                'tools' => true
            ]
        ];
    }

    public function listTools(): array
    {
        return [
            'tools' => [
                [
                    'name' => 'get_weather',
                    'description' => 'Get current weather for a location',
                    'inputSchema' => [
                        'type' => 'object',
                        'properties' => [
                            'location' => [
                                'type' => 'string',
                                'description' => 'City name or coordinates'
                            ]
                        ],
                        '

use Scriptoshi\McpClient\Facades\McpClient;

public function boot()
{
    McpClient::registerServer('weather', new WeatherServer());
}

public function toolShouldQueue(string $toolname): bool
{
    return match($toolname) {
        'long_running_process' => true,
        default => false
    };
}

use Scriptoshi\McpClient\Models\Chat;

// Find a chat by UUID
$chat = Chat::findByUuid($uuid);

// Get chat messages
$messages = $chat->messages;

// Get message responses
$responses = $message->responses;

// Get tool executions
$runners = $response->runners;

$runner->error('Something went wrong', [
    'context' => 'Additional error details'
]);

// Different log levels
$runner->info('Processing started');
$runner->warning('Resource usage high');
$runner->success('Operation completed');
bash
php artisan vendor:publish --provider="Scriptoshi\McpClient\McpClientServiceProvider"
bash
php artisan migrate