PHP code example of innoge / laravel-mcp

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

    

innoge / laravel-mcp example snippets




namespace App\Console\Commands;

use Illuminate\Console\Command;
use InnoGE\LaravelMcp\Commands\ServesMcpServer;

class McpServerCommand extends Command
{
    use ServesMcpServer;

    protected $signature = 'mcp:serve';
    protected $description = 'Start an MCP server';

    public function handle(): int
    {
        return $this->serveMcp('your-app-name', '1.0.0');
    }

    private function getTools(): array
    {
        return [
            // List your tool classes here
        ];
    }

    private function getResources(): array
    {
        return [
            // List your resource providers here
        ];
    }
}

use InnoGE\LaravelMcp\Resources\EloquentResourceProvider;
use App\Models\User;

// In your getResources() method:
return [
    new EloquentResourceProvider(User::query(), 'users', 'A User of the Application')
];

use InnoGE\LaravelMcp\Resources\InMemoryResourceProvider;
use InnoGE\LaravelMcp\Types\Resources\ResourceContent;
use InnoGE\LaravelMcp\Types\Resources\ResourceItem;

// Create a resource provider
$resourceProvider = new InMemoryResourceProvider();

// Add example documents as resources
$resourceProvider->addResource(
    new ResourceItem('doc://example/document1', 'Example Document 1', 'This is an example document', 'text/plain', 1024),
    new ResourceContent('doc://example/document1', 'text/plain', 'This is the content of the document')
);

$resourceProvider->addResource(
    new ResourceItem('doc://example/document2', 'Example Document 2', 'This is an example document 2', 'text/plain', 1024),
    new ResourceContent('doc://example/document2', 'text/plain', 'This is the content of the document 2')
);

// In your getResources() method:
return [
    $resourceProvider
];

use InnoGE\LaravelMcp\Tools\Examples\HelloTool;
use InnoGE\LaravelMcp\Tools\Examples\ClockTool;
use App\MCP\Tools\YourCustomTool;

// In your getTools() method:
return [
    HelloTool::class,
    ClockTool::class,
    YourCustomTool::class,
];



namespace App\MCP\Tools;

use Illuminate\Support\Facades\Artisan;
use InnoGE\LaravelMcp\Tools\Tool;
use Symfony\Component\Console\Output\BufferedOutput;

class CallArtisanCommandTool implements Tool
{
    /**
     * Get the tool name
     */
    public function getName(): string
    {
        return 'call-artisan-command';
    }

    /**
     * Get the tool description
     */
    public function getDescription(): string
    {
        return 'Call a Laravel Artisan command';
    }

    /**
     * Get the input schema for the tool
     */
    public function getInputSchema(): array
    {
        return [
            'type' => 'object',
            'properties' => [
                'command' => [
                    'type' => 'string',
                    'description' => 'The Artisan command to call (e.g. "migrate")',
                ],
            ],
            '