1. Go to this page and download the library: Download bramato/laravel-mcp-server 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/ */
bramato / laravel-mcp-server example snippets
namespace App\Mcp\Resources;
use Bramato\LaravelMcpServer\Mcp\Interfaces\ResourceInterface;
use Illuminate\Support\Facades\Auth;
class UserProfileResource implements ResourceInterface
{
public function getUri(): string { return 'user://profile'; } // Unique URI for this resource
public function getName(): string { return 'User Profile'; }
public function getDescription(): string { return 'Provides information about the authenticated user.'; }
public function getMimeType(): string { return 'application/json'; }
public function getContents(): mixed
{
$user = Auth::user(); // Example: Get authenticated user
if (!$user) {
return null; // Or throw an exception mapped to an error
}
return [
'id' => $user->id,
'name' => $user->name,
'email' => $user->email,
];
}
}
namespace App\Mcp\Tools;
use Bramato\LaravelMcpServer\Mcp\Interfaces\ToolInterface;
// use App\Jobs\ProcessNotificationJob; // Example Job
use Illuminate\Support\Facades\Log;
class SendNotificationTool implements ToolInterface
{
public function getName(): string { return 'sendNotification'; }
public function getDescription(): string { return 'Sends a notification to a user.'; }
public function getInputSchema(): array
{
// Define expected parameters using JSON Schema format
return [
'type' => 'object',
'properties' => [
'user_id' => ['type' => 'integer', 'description' => 'ID of the target user'],
'message' => ['type' => 'string', 'description' => 'The notification message content'],
],
'