PHP code example of vinkius / laravel-mcp-connect

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

    

vinkius / laravel-mcp-connect example snippets


use Vinkius\McpConnect\Facades\Mcp;

// Search the marketplace
$results = Mcp::search('github issues');

// Inspect a tool's schema
$schema = Mcp::inspect('github__create_issue');

// Execute a tool
$result = Mcp::execute('github__create_issue', [
    'owner' => 'my-org',
    'repo'  => 'my-repo',
    'title' => 'Bug: Login broken on mobile',
]);

echo $result->text(); // "Issue #42 created successfully"

use Vinkius\McpConnect\Facades\Mcp;

// List all activated servers and their tools (}: " . implode(', ', $server->toolNames());
}

// Search the catalog (

// Browse marketplace categories
$categories = Mcp::categories();

foreach ($categories as $cat) {
    echo "{$cat->label}: {$cat->listingCount} apps";
}

// Fetch paginated listings with filters
$response = Mcp::listings(['category' => 'ai', 'page' => 2, 'sort' => 'popular']);
foreach ($response['data'] as $listing) {
    echo "{$listing->title} — {$listing->priceFormatted()}";
}

// Get full detail for a single listing
$listing = Mcp::listing('github-mcp');
echo "{$listing->title}: " . implode(', ', $listing->toolNames());

// Featured sections for discovery carousels
$featured = Mcp::featured();

// Search marketplace listings
$results = Mcp::searchListings('payment processing');

// Always inspect before executing — know the exact parameters
$schema = Mcp::inspect('github__create_issue');

echo $schema->description;
// "Create a new issue in a GitHub repository"

print_r($schema->inputSchema);
// ["type" => "object", "properties" => [...], "

$result = Mcp::execute('github__create_issue', [
    'owner' => 'my-org',
    'repo'  => 'my-repo',
    'title' => 'Automated issue from Laravel',
    'body'  => 'Created via MCP Connect.',
]);

if ($result->successful()) {
    $data = $result->json(); // Parsed JSON from first content block
} else {
    $error = $result->text(); // Error message
}

// Activate a marketplace listing
$activation = Mcp::activate('listing-uuid');

if ($activation->;
}

// Deactivate a subscription
Mcp::deactivate('subscription-uuid');

$analytics = Mcp::analytics();

foreach ($analytics as $sub) {
    echo "{$sub->title}: {$sub->requestCount} requests ({$sub->status})";
}

if (Mcp::ping()) {
    echo 'Vinkius API is reachable!';
}

use Vinkius\McpConnect\Events\ToolExecuted;

Event::listen(ToolExecuted::class, function (ToolExecuted $event) {
    Log::info("MCP tool executed: {$event->toolName}", [
        'duration_ms' => $event->durationMs,
        'is_error'    => $event->result->isError,
    ]);
});

use Vinkius\McpConnect\Exceptions\McpException;
use Vinkius\McpConnect\Exceptions\AuthenticationException;
use Vinkius\McpConnect\Exceptions\ExecutionException;

try {
    $result = Mcp::execute('tool__name', $args);
} catch (AuthenticationException $e) {
    // Token invalid/expired — non-retryable
} catch (ExecutionException $e) {
    // Tool returned an error
    $errorDetail = $e->getResult()->text();
} catch (McpException $e) {
    // Any MCP-related error
}

// config/mcp-connect.php

return [
    'base_url'        => env('VINKIUS_API_URL', 'https://api.vinkius.com'),
    'token'           => env('VINKIUS_CATALOG_TOKEN'),  // optional for marketplace
    'timeout'         => 30,
    'connect_timeout' => 10,
    'retry'           => ['times' => 2, 'sleep' => 500],
    'cache'           => [
        'enabled' => true,
        'store'   => null,  // null = default cache store
        'prefix'  => 'mcp_connect',
        'ttl'     => [
            // Catalog (authenticated)
            'tools'     => 60,
            'schema'    => 300,
            'search'    => 120,
            'browse'    => 600,
            'analytics' => 60,
            // Marketplace (public)
            'listings'  => 120,
            'featured'  => 600,
        ],
    ],
];
bash
php artisan vendor:publish --tag=mcp-connect-config