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 (Verwaltung der MCP-Server-Konfiguration)
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 ist 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'));
// MCP-Server aktivieren/deaktivieren (globale Einstellung)
Copilot::client()->rpc()->mcp()->enable(new McpConfigEnableRequest(names: ['my-server']));
Copilot::client()->rpc()->mcp()->disable(new McpConfigDisableRequest(names: ['my-server']));
// In-Memory-Cache leeren (beim nächsten Laden erneut von der Festplatte lesen)
Copilot::client()->rpc()->mcp()->reload();
// MCP-Registry-Suche (experimental/internal)
// $authInfo sind vom Host bereitgestellte JSON-Authentifizierungsdaten. Das SDK interpretiert deren Inhalt nicht.
$registry = Copilot::client()->rpc()->mcp()->registry();
$requestId = $registry->allocateRequestId()->requestId;
$servers = $registry->search(new McpRegistrySearchRequest(
requestId: $requestId,
authInfo: $authInfo, // Vom Host übergebene Authentifizierungsdaten. Das SDK interpretiert deren Inhalt nicht.
query: 'database',
limit: 20,
));
// $servers->servers enthält die Serverdaten der Registry (unverändert, ohne Interpretation der Struktur)
// Nicht verwendete reservierte IDs können freigegeben werden. Laufende Suchen brechen Sie ab, indem Sie cancel() aus einem anderen Ablauf aufrufen.
$unusedRequestId = $registry->allocateRequestId()->requestId;
$cancelResult = $registry->cancel(new McpRegistryCancelRequest(requestId: $unusedRequestId));
// Beim Freigeben einer unbenutzten ID ist canceled false. Nur beim Stoppen einer laufenden Suche ist es true.
// Installation / Deinstallation über den MCP-Katalog (experimental)
// Das Ergebnis ist ein assoziatives Array einer diskriminierten Union mit kind. Prüfen Sie kind, bevor Sie auf die einzelnen Felder zugreifen.
$mcp = Copilot::client()->rpc()->mcp();
$contract = new CatalogClientContract(
protocolVersion: 1,
requiredCapabilities: ['mcp-server-card', 'mcp-install-planning'],
);
// $candidateHandle, $searchId und $cardReference stammen aus dem Ergebnis der Katalogsuche.
// $sessionId ist die ID einer Session, die bereits mit diesem Client verbunden ist.
$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),
));
// Während applyInstall wird der beim Erstellen des Clients konfigurierte installation_confirmation_handler aufgerufen.
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,
));
}
}
// Eigene Installationen auflisten und nicht abgeschlossene Operationen wiederherstellen
$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));
// Für die Deinstallation planen Sie mit einer installationId, die Ihnen gehört, und wenden das zurückgegebene planHandle an.
$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,
));
}
// Prüfen, ob GitHub-MCP-Tools ausgeschlossen werden können (experimental/internal)
$exclude = Copilot::client()->rpc()->mcp()->shouldExcludeGitHubTools(
new McpShouldExcludeGitHubToolsRequest(
availableTools: ['builtin:bash'],
excludedTools: [],
toolFilterPrecedence: OptionsUpdateToolFilterPrecedence::Available,
),
)->excludeGhReplaceableTools;
// mcp discover (automatische Erkennung von MCP-Servern)
Copilot::client()->rpc()->mcp()->discover(new McpDiscoverRequest(
workingDirectory: '/path/to/project',
));
// Auch ohne Argumente ausführbar
$result = Copilot::client()->rpc()->mcp()->discover();
// $result->servers ist ein Array von DiscoveredMcpServer