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