> ## Documentation Index
> Fetch the complete documentation index at: https://kawax.biz/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP

> Descrive come configurare e gestire i server MCP tramite la configurazione di sessione e la Server RPC API di Laravel Copilot SDK.

## MCP

Puoi usare i server MCP specificandoli in `mcpServers` di SessionConfig.

Se usi Laravel Boost con Copilot CLI, considera anche [laravel-boost-copilot-cli](https://github.com/invokable/laravel-boost-copilot-cli).
Si è verificato che `'type' => 'stdio'` (oppure `'local'`) e `'tools' => ['*']` sono obbligatori. Senza di questi non viene riconosciuto come server MCP.

```php theme={null}
Artisan::command('copilot:mcp', function () {
    $config = new SessionConfig(
        mcpServers: [
            'laravel-boost' => [
                'type' => 'stdio',
                'command' => 'php',
                'args' => ['artisan', 'boost:mcp'],
                'tools' => ['*'],
            ],
        ],
    );

    Copilot::start(function (CopilotSession $session) {
        info('Starting Copilot with Laravel Boost MCP: '.$session->id());

        $prompt = 'Quali MCP sono caricati? Se laravel-boost è disponibile, usa application-info per ottenere le informazioni sull\'app.';

        warning($prompt);

        $response = spin(
            callback: fn () => $session->sendAndWait($prompt),
            message: 'Thinking...',
        );

        note($response->content());
    }, config: $config);
});
```

## Stato dei server MCP

Lo stato dei server MCP in una sessione può assumere i seguenti valori:

| Stato            | Descrizione              |
| ---------------- | ------------------------ |
| `connected`      | Connesso                 |
| `failed`         | Connessione fallita      |
| `needs-auth`     | Richiede autenticazione  |
| `pending`        | In attesa di connessione |
| `disabled`       | Disabilitato             |
| `not_configured` | Non configurato          |

## Gestione della configurazione dei server MCP (Server RPC)

Indipendentemente dalla sessione, puoi gestire la configurazione dei server MCP a livello di server.

```php theme={null}
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Types\Rpc\McpConfigAddRequest;
use Revolution\Copilot\Types\Rpc\McpConfigUpdateRequest;
use Revolution\Copilot\Types\Rpc\McpConfigRemoveRequest;
use Revolution\Copilot\Types\Rpc\McpServerValue;

// Ottieni l'elenco dei server MCP configurati
$result = Copilot::client()->rpc()->mcp()->list();
foreach ($result->servers as $name => $config) {
    dump($name, $config->type, $config->command);
}

// Aggiungi un server MCP
Copilot::client()->rpc()->mcp()->add(new McpConfigAddRequest(
    name: 'laravel-boost',
    config: new McpServerValue(
        type: 'stdio',
        command: 'php',
        args: ['artisan', 'boost:mcp'],
        tools: ['*'],
    ),
));

// Aggiorna la configurazione di un server MCP
Copilot::client()->rpc()->mcp()->update(new McpConfigUpdateRequest(
    name: 'laravel-boost',
    config: new McpServerValue(
        type: 'stdio',
        command: 'php',
        args: ['artisan', 'boost:mcp', '--verbose'],
        tools: ['*'],
    ),
));

// Rimuovi un server MCP
Copilot::client()->rpc()->mcp()->remove(new McpConfigRemoveRequest(name: 'laravel-boost'));
```

<Info>
  Per le informazioni più recenti fai riferimento al [repository GitHub](https://github.com/invokable/laravel-copilot-sdk).
</Info>


## Related topics

- [Laravel MCP](/it/mcp.md)
- [Creare un server MCP con Laravel](/it/advanced/mcp-server.md)
- [Creare un agente personalizzato per Boost](/it/advanced/boost-custom-agent.md)
- [Laravel AI SDK](/it/ai-sdk.md)
- [Laravel Boost Custom Agent for PhpStorm with GitHub Copilot](/it/packages/laravel-boost-phpstorm-copilot.md)
