> ## 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 and connectors

> Use ServerRpc in Laravel Copilot SDK to manage MCP configuration and connectors, register secret masks, and run MCP OAuth checks.

## MCP and connectors

Scope: ServerRpc (server-wide operations tied to the Client)

For an overview of RPC and the list of all RPC pages, see [RPC](https://kawax.biz/en/packages/laravel-copilot-sdk/rpc.md).

```php theme={null}
use Revolution\Copilot\Enums\McpInstallationSecretStorage;
use Revolution\Copilot\Enums\OptionsUpdateToolFilterPrecedence;
use Revolution\Copilot\Types\Rpc\CatalogClientContract;
use Revolution\Copilot\Types\Rpc\McpApplyInstallRequest;
use Revolution\Copilot\Types\Rpc\McpApplyUninstallRequest;
use Revolution\Copilot\Types\Rpc\McpInstallationOperationRequest;
use Revolution\Copilot\Types\Rpc\McpInstallationsRequest;
use Revolution\Copilot\Types\Rpc\McpPlanUninstallRequest;
use Revolution\Copilot\Types\Rpc\McpPrepareInstallRequest;
use Revolution\Copilot\Types\Rpc\McpRegistryCancelRequest;
use Revolution\Copilot\Types\Rpc\McpRegistrySearchRequest;
use Revolution\Copilot\Types\Rpc\McpServerCardReference;
use Revolution\Copilot\Types\Rpc\McpShouldExcludeGitHubToolsRequest;

// mcp config (manage MCP server configuration)
Copilot::client()->rpc()->mcp()->list();
Copilot::client()->rpc()->mcp()->add(new McpConfigAddRequest(
    name: 'my-server',
    config: new McpServerValue(type: 'local', command: 'php', args: ['artisan', 'mcp']),
));
// args is optional
Copilot::client()->rpc()->mcp()->update(new McpConfigUpdateRequest(
    name: 'my-server',
    config: new McpServerValue(type: 'http', url: 'https://mcp.example.com'),
));
Copilot::client()->rpc()->mcp()->remove(new McpConfigRemoveRequest(name: 'my-server'));
// Enable/disable MCP servers (global settings)
Copilot::client()->rpc()->mcp()->enable(new McpConfigEnableRequest(names: ['my-server']));
Copilot::client()->rpc()->mcp()->disable(new McpConfigDisableRequest(names: ['my-server']));
// Clear the in-memory cache (reloaded from disk on next read)
Copilot::client()->rpc()->mcp()->reload();

// MCP registry search (experimental/internal)
// $authInfo is JSON authentication info prepared by the host. The SDK doesn't interpret its contents.

$registry = Copilot::client()->rpc()->mcp()->registry();
$requestId = $registry->allocateRequestId()->requestId;
$servers = $registry->search(new McpRegistrySearchRequest(
    requestId: $requestId,
    authInfo: $authInfo, // Auth info passed from the host. The SDK doesn't interpret its contents.
    query: 'database',
    limit: 20,
));
// $servers->servers holds the registry server data (kept as-is without interpreting its shape)
// You can release unused reserved IDs. To cancel an in-progress search, call cancel() from another process.
$unusedRequestId = $registry->allocateRequestId()->requestId;
$cancelResult = $registry->cancel(new McpRegistryCancelRequest(requestId: $unusedRequestId));
// When releasing an unused ID, canceled is false. It's true only when a running search was stopped.

// Install / uninstall via the MCP catalog (experimental)
// Results are associative arrays of a discriminated union with kind. Check kind before reading each field.

$mcp = Copilot::client()->rpc()->mcp();
$contract = new CatalogClientContract(
    protocolVersion: 1,
    requiredCapabilities: ['mcp-server-card', 'mcp-install-planning'],
);

// $candidateHandle, $searchId, and $cardReference come from catalog search results.
// $sessionId is a session ID already connected to this Client.
$planned = $mcp->planInstall([
    'contract' => $contract->toArray(),
    'source' => ['kind' => 'candidate', 'candidateHandle' => $candidateHandle, 'searchId' => $searchId],
]);

if (($planned['kind'] ?? null) === 'planned') {
    $plan = $planned['plan'];
    $prepared = $mcp->prepareInstall(new McpPrepareInstallRequest(
        contract: $contract,
        planHandle: $plan['planHandle'],
        choiceId: $plan['transportChoices'][0]['choiceId'],
        inputs: [],
        policySessionId: $sessionId,
        secrets: [],
        secretStorage: McpInstallationSecretStorage::Keychain,
        source: McpServerCardReference::fromArray($cardReference),
    ));

    // During applyInstall, the installation_confirmation_handler set when creating the client is called.
    if (($prepared['kind'] ?? null) === 'outcome'
        && ($prepared['outcome']['kind'] ?? null) === 'install-prepared') {
        $applied = $mcp->applyInstall(new McpApplyInstallRequest(
            contract: $contract,
            operationId: $prepared['outcome']['operation']['operationId'],
            policySessionId: $sessionId,
        ));
    }
}

// List owned installations and recover incomplete operations
$installations = $mcp->installations();
$installations->list(new McpInstallationsRequest(contract: $contract, policySessionId: $sessionId));
$installations->recover(new McpInstallationsRequest(contract: $contract, policySessionId: $sessionId));
$installations->status(new McpInstallationOperationRequest($contract, $operationId));
$installations->cancel(new McpInstallationOperationRequest($contract, $operationId));

// To uninstall, plan with an installationId you own, then apply the returned planHandle.
$uninstallPlan = $mcp->planUninstall(new McpPlanUninstallRequest(
    contract: $contract,
    installationId: $installationId,
    policySessionId: $sessionId,
));
if (($uninstallPlan['kind'] ?? null) === 'outcome'
    && ($uninstallPlan['outcome']['kind'] ?? null) === 'uninstall-planned') {
    $mcp->applyUninstall(new McpApplyUninstallRequest(
        contract: $contract,
        planHandle: $uninstallPlan['outcome']['plan']['planHandle'],
        policySessionId: $sessionId,
    ));
}

// Determine whether GitHub MCP tools can be excluded (experimental/internal)

$exclude = Copilot::client()->rpc()->mcp()->shouldExcludeGitHubTools(
    new McpShouldExcludeGitHubToolsRequest(
        availableTools: ['builtin:bash'],
        excludedTools: [],
        toolFilterPrecedence: OptionsUpdateToolFilterPrecedence::Available,
    ),
)->excludeGhReplaceableTools;

// mcp discover (auto-discover MCP servers)
Copilot::client()->rpc()->mcp()->discover(new McpDiscoverRequest(
    workingDirectory: '/path/to/project',
));
// Can be run without arguments
$result = Copilot::client()->rpc()->mcp()->discover();
// $result->servers is an array of DiscoveredMcpServer
```

## secrets (experimental: register masks for dynamic secrets)

The experimental `secrets()->addFilterValues()` registers dynamic secrets generated by your host with the CLI's redaction filter. The CLI then masks those values in session logs and exports.

```php theme={null}
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Types\Rpc\SecretsAddFilterValuesRequest;

$result = Copilot::client()->rpc()->secrets()->addFilterValues(
    new SecretsAddFilterValuesRequest(values: [$accessToken]),
);
// $result->ok

// You can also pass an array
Copilot::client()->rpc()->secrets()->addFilterValues([
    'values' => [$accessToken],
]);
```

This RPC doesn't acquire OAuth tokens. The SDK doesn't persist the values or write them to additional logs. Register values that your host has already obtained.

## mcp oauth (MCP OAuth pre-checks)

After a remote MCP server requests OAuth authentication, you can check whether it supports Dynamic Client Registration (DCR). `authorizationServerUrl` is returned when the authorization server can be discovered from metadata. If `supportsDcr` is `false`, dynamic registration is not available. You can also check whether the authorization server is a Microsoft one.

```php theme={null}
use Revolution\Copilot\Facades\Copilot;
use Revolution\Copilot\Types\Rpc\McpOauthCheckDcrSupportRequest;
use Revolution\Copilot\Types\Rpc\McpOauthIsMicrosoftAuthorizationServerRequest;

$oauth = Copilot::client()->rpc()->mcp()->oauth();

$dcr = $oauth->checkDcrSupport(new McpOauthCheckDcrSupportRequest(
    serverUrl: 'https://mcp.example.com',
    resourceMetadataText: $challengeMetadata,
    sessionId: $session->id(),
));

$isMicrosoft = $dcr->authorizationServerUrl === null
    ? false
    : $oauth->isMicrosoftAuthorizationServer(new McpOauthIsMicrosoftAuthorizationServerRequest(
        authorizationServerUrl: $dcr->authorizationServerUrl,
    ))->isMicrosoftAuthorizationServer;
```


## Related topics

- [ServerRpc overview](https://kawax.biz/en/packages/laravel-copilot-sdk/rpc/server-overview.md)
- [RPC (Remote Procedure Call)](https://kawax.biz/en/packages/laravel-copilot-sdk/rpc.md)
- [MCP](https://kawax.biz/en/packages/laravel-copilot-sdk/mcp.md)
- [SessionRpc overview](https://kawax.biz/en/packages/laravel-copilot-sdk/rpc/session-overview.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.