1. Go to this page and download the library: Download prism-php/relay 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 Prism\Prism\Prism;
use Prism\Relay\Facades\Relay;
use Prism\Prism\Enums\Provider;
$response = Prism::text()
->using(Provider::Anthropic, 'claude-3-7-sonnet-latest')
->withPrompt('Find information about Laravel on the web')
->withTools(Relay::tools('puppeteer'))
->asText();
return $response->text;
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Prism\Relay\Facades\Relay;
use Prism\Prism\Enums\Provider;
use Prism\Prism\Prism;
use Prism\Prism\Text\PendingRequest;
use function Laravel\Prompts\note;
use function Laravel\Prompts\textarea;
class MCP extends Command
{
protected $signature = 'prism:mcp';
public function handle()
{
$response = $this->agent(textarea('Prompt'))->asText();
note($response->text);
}
protected function agent(string $prompt): PendingRequest
{
return Prism::text()
->using(Provider::Anthropic, 'claude-3-7-sonnet-latest')
->withSystemPrompt(view('prompts.nova-v2'))
->withPrompt($prompt)
->withTools([
...Relay::tools('puppeteer'),
])
->usingTopP(1)
->withMaxSteps(99)
->withMaxTokens(8192);
}
}
'puppeteer' => [
'command' => [
'npx',
'-y',
'@modelcontextprotocol/server-puppeteer',
'--options',
// Array values are passed as JSON encoded strings
[
'debug' => env('MCP_PUPPETEER_DEBUG', false)
]
],
'timeout' => 30,
'transport' => Transport::Stdio,
'env' => [
'NODE_ENV' => 'production', // Set Node environment
'MCP_SERVER_PORT' => '3001', // Set a custom port for the server
],
],
use Prism\Prism\Prism;
use Prism\Relay\Facades\Relay;
use Prism\Prism\Enums\Provider;
$response = Prism::text()
->using(Provider::Anthropic, 'claude-3-7-sonnet-latest')
->withTools([
...Relay::tools('github'),
...Relay::tools('puppeteer')
])
->withPrompt('Find and take screenshots of Laravel repositories')
->asText();
use Prism\Relay\Exceptions\RelayException;
use Prism\Relay\Exceptions\ServerConfigurationException;
use Prism\Relay\Exceptions\ToolCallException;
use Prism\Relay\Exceptions\ToolDefinitionException;
use Prism\Relay\Exceptions\TransportException;
try {
$tools = Relay::tools('puppeteer');
// Use the tools...
} catch (ServerConfigurationException $e) {
// Handle configuration errors (missing server, invalid settings)
Log::error('MCP Server configuration error: ' . $e->getMessage());
} catch (ToolDefinitionException $e) {
// Handle issues with tool definitions from the MCP server
Log::error('MCP Tool definition error: ' . $e->getMessage());
} catch (TransportException $e) {
// Handle communication errors with the MCP server
Log::error('MCP Transport error: ' . $e->getMessage());
} catch (ToolCallException $e) {
// Handle errors when calling a specific tool
Log::error('MCP Tool call error: ' . $e->getMessage());
} catch (RelayException $e) {
// Handle any other MCP-related errors
Log::error('Relay general error: ' . $e->getMessage());
}