Skip to content

Commit 820b1a7

Browse files
bhaarathmsclaude
andcommitted
feat: create Copilot Entra app with PPMI permissions and redirect URI
Create {serverName}-Copilot Entra app during BYO MCP server registration. Same PPMI API permissions as A365Proxy, plus broker redirect URI. Pass CopilotClientAppId to backend for storage in MCC server record. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent f009a04 commit 820b1a7

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

src/Microsoft.Agents.A365.DevTools.Cli/Commands/DevelopMcpCommand.cs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1238,6 +1238,44 @@ private static Command CreateRegisterExternalMcpServerSubcommand(
12381238
};
12391239
}
12401240

1241+
// Create Copilot (VS Code) Entra app — same pattern as A365 Proxy
1242+
string? copilotAppClientId = null;
1243+
string? copilotAppObjectId = null;
1244+
1245+
if (force)
1246+
{
1247+
var existingCopilotObjectId = await graphApiService.GetAppObjectIdByDisplayNameAsync(tenantId, $"{serverName}-Copilot");
1248+
if (!string.IsNullOrWhiteSpace(existingCopilotObjectId))
1249+
{
1250+
logger.LogDebug("Deleting existing Copilot app: {ObjectId}", existingCopilotObjectId);
1251+
await graphApiService.DeleteEntraAppAsync(tenantId, existingCopilotObjectId);
1252+
}
1253+
}
1254+
1255+
logger.LogDebug("Creating Entra application for Copilot (VS Code)...");
1256+
var copilotApp = await graphApiService.CreateEntraAppAsync(tenantId, $"{serverName}-Copilot", serviceTreeId: serviceTreeId);
1257+
if (copilotApp != null)
1258+
{
1259+
copilotAppClientId = copilotApp.Value.ClientId;
1260+
copilotAppObjectId = copilotApp.Value.ObjectId;
1261+
logger.LogDebug("Created Copilot app: {ClientId}", copilotAppClientId);
1262+
1263+
var copilotRedirectUri = $"ms-appx-web://MicrosoftAAD.BrokerPlugin/{copilotAppClientId}";
1264+
try
1265+
{
1266+
await graphApiService.UpdateAppRedirectUrisAsync(tenantId, copilotAppObjectId, new[] { copilotRedirectUri });
1267+
logger.LogDebug("Set Copilot redirect URI: {Uri}", copilotRedirectUri);
1268+
}
1269+
catch (Exception ex)
1270+
{
1271+
logger.LogWarning("Failed to set redirect URI on Copilot app: {Error}", ex.Message);
1272+
}
1273+
}
1274+
else
1275+
{
1276+
logger.LogWarning("Failed to create Copilot Entra app. Continuing without it.");
1277+
}
1278+
12411279
// Track warnings for non-fatal failures during registration
12421280
var warnings = new List<string>();
12431281

@@ -1265,6 +1303,7 @@ private static Command CreateRegisterExternalMcpServerSubcommand(
12651303
RemoteServerScopes = remoteScopes,
12661304
PublisherName = publisherName,
12671305
Description = serverDescription,
1306+
CopilotClientAppId = copilotAppClientId,
12681307
Force = force,
12691308
};
12701309

@@ -1427,6 +1466,23 @@ await graphApiService.AddRequiredResourceAccessAsync(
14271466
logger.LogWarning(msg);
14281467
warnings.Add(msg);
14291468
}
1469+
1470+
// Add same PPMI API permissions on Copilot app
1471+
if (ppmiScopeIds.Count > 0 && copilotAppObjectId != null)
1472+
{
1473+
try
1474+
{
1475+
logger.LogDebug("Adding API permissions on Copilot app for PPMI scopes...");
1476+
await graphApiService.AddRequiredResourceAccessAsync(
1477+
tenantId, copilotAppObjectId, ppmiAppClientId, ppmiScopeIds);
1478+
}
1479+
catch (Exception ex)
1480+
{
1481+
var msg = $"Failed to add API permissions on Copilot app: {ex.Message}";
1482+
logger.LogWarning(msg);
1483+
warnings.Add(msg);
1484+
}
1485+
}
14301486
}
14311487
else
14321488
{

src/Microsoft.Agents.A365.DevTools.Cli/Models/AddMcpServerRequest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ public class AddMcpServerRequest
7575
[JsonPropertyName("description")]
7676
public string? Description { get; set; }
7777

78+
/// <summary>
79+
/// Copilot (VS Code) Entra client application ID
80+
/// </summary>
81+
[JsonPropertyName("copilotClientAppId")]
82+
public string? CopilotClientAppId { get; set; }
83+
7884
/// <summary>
7985
/// When true, force re-creation of connectors and reuse existing MCC record
8086
/// </summary>

0 commit comments

Comments
 (0)