PHP code example of meyer59 / nova-mcp

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

    

meyer59 / nova-mcp example snippets


public function tools(): array
{
    return [
        // Your other Nova tools...
        new \NovaMcp\McpAccess,
    ];
}

// config/nova-mcp.php
'instructions' => 'This application manages digital signage. Players are devices; playlists contain scheduled media.',

use Laravel\Nova\Http\Requests\NovaRequest;

// Add inside your existing App\Nova\Player resource:
public static function mcpDescription(NovaRequest $request): string
{
    return 'A player is a device running the signage app. '
        .'It controls a connected screen. Changing its playlist changes '
        .'the content shown on that screen.';
}

// config/nova-mcp.php
' [App\Nova\User::class],

''excluded_resources' => [App\Nova\Campaign::class],

use NovaMcp\NovaMcp;

NovaMcp::manageTokensUsing(function ($actor, $targetUser) {
    return $actor->can('manageMcpTokensFor', $targetUser);
});

// config/nova-mcp.php
'
    App\Nova\Actions\ImpersonateUser::class,
    App\Nova\Actions\CreateApiToken::class,
],

'action_results' => 'status',
'full_result_actions' => [
    // App\Nova\Actions\ReturnPublicReport::class,
],

use NovaMcp\NovaMcp;

// For an action or field that should be available only in Nova's browser UI:
->canSee(fn ($request) => ! NovaMcp::isMcpRequest($request))

// The current authenticated MCP token, or null outside an MCP request:
$token = NovaMcp::token(); // An explicit Request argument is also supported.

public function authorizedToRun(\Illuminate\Http\Request $request, $model)
{
    return ! \NovaMcp\NovaMcp::isMcpRequest($request)
        && parent::authorizedToRun($request, $model);
}

public function runAction($user, $model, $action): bool
{
    if (\NovaMcp\NovaMcp::isMcpRequest()
        && $action instanceof \App\Nova\Actions\ImpersonateUser) {
        return false;
    }

    return $this->update($user, $model); // Keep your existing policy decision here.
}

// config/nova-mcp.php — exact hosts, without scheme, port or wildcards
'allowed_hosts' => ['tenant.example.com', 'internal-proxy.example.com'],

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;

Gate::define('accessNovaMcp', function ($user, Request $request) {
    return in_array($user->email, ['[email protected]'], true)
        && in_array($request->ip(), ['203.0.113.10'], true);
});

use NovaMcp\NovaMcp;

$count = NovaMcp::revokeTokensFor($user, 'password_reset');

use NovaMcp\Fields\FieldRegistry;
use NovaMcp\Fields\ScalarAdapter;

app(FieldRegistry::class)->register(MyPlainTextField::class, new ScalarAdapter('string'));
bash
php artisan vendor:publish --tag=nova-mcp-config