@@ -12,7 +12,9 @@ param location string
1212@description ('Id of the user or app to assign application roles' )
1313param principalId string = ''
1414
15- param acaExists bool = false
15+ param serverExists bool = false
16+
17+ param agentExists bool = false
1618
1719@description ('Location for the OpenAI resource group' )
1820@allowed ([
@@ -653,23 +655,41 @@ module cosmosDbPrivateEndpoint 'br/public:avm/res/network/private-endpoint:0.11.
653655 }
654656}
655657
656- // Container app frontend
657- module aca 'aca .bicep' = {
658- name : 'aca '
658+ // Container app for MCP server
659+ module server 'server .bicep' = {
660+ name : 'server '
659661 scope : resourceGroup
660662 params : {
661- name : replace ('${take (prefix ,19 )}-ca ' , '--' , '-' )
663+ name : replace ('${take (prefix ,15 )}-server ' , '--' , '-' )
662664 location : location
663665 tags : tags
664- identityName : '${prefix }-id-aca '
666+ identityName : '${prefix }-id-server '
665667 containerAppsEnvironmentName : containerApps .outputs .environmentName
666668 containerRegistryName : containerApps .outputs .registryName
667669 openAiDeploymentName : openAiDeploymentName
668670 openAiEndpoint : openAi .outputs .endpoint
669671 cosmosDbAccount : cosmosDb .outputs .name
670672 cosmosDbDatabase : cosmosDbDatabaseName
671673 cosmosDbContainer : cosmosDbContainerName
672- exists : acaExists
674+ exists : serverExists
675+ }
676+ }
677+
678+ // Container app for agent
679+ module agent 'agent.bicep' = {
680+ name : 'agent'
681+ scope : resourceGroup
682+ params : {
683+ name : replace ('${take (prefix ,15 )}-agent' , '--' , '-' )
684+ location : location
685+ tags : tags
686+ identityName : '${prefix }-id-agent'
687+ containerAppsEnvironmentName : containerApps .outputs .environmentName
688+ containerRegistryName : containerApps .outputs .registryName
689+ openAiDeploymentName : openAiDeploymentName
690+ openAiEndpoint : openAi .outputs .endpoint
691+ mcpServerUrl : '${server .outputs .uri }/mcp/'
692+ exists : agentExists
673693 }
674694}
675695
@@ -683,11 +703,21 @@ module openAiRoleUser 'core/security/role.bicep' = {
683703 }
684704}
685705
686- module openAiRoleBackend 'core/security/role.bicep' = {
706+ module openAiRoleServer 'core/security/role.bicep' = {
707+ scope : resourceGroup
708+ name : 'openai-role-server'
709+ params : {
710+ principalId : server .outputs .identityPrincipalId
711+ roleDefinitionId : '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd' // Cognitive Services OpenAI User
712+ principalType : 'ServicePrincipal'
713+ }
714+ }
715+
716+ module openAiRoleAgent 'core/security/role.bicep' = {
687717 scope : resourceGroup
688- name : 'openai-role-backend '
718+ name : 'openai-role-agent '
689719 params : {
690- principalId : aca .outputs .identityPrincipalId
720+ principalId : agent .outputs .identityPrincipalId
691721 roleDefinitionId : '5e0bd9bd-7b93-4f28-af87-19fc36ad61bd' // Cognitive Services OpenAI User
692722 principalType : 'ServicePrincipal'
693723 }
@@ -704,13 +734,13 @@ module cosmosDbRoleUser 'core/security/documentdb-sql-role.bicep' = {
704734 }
705735}
706736
707- // Cosmos DB Data Contributor role for backend
708- module cosmosDbRoleBackend 'core/security/documentdb-sql-role.bicep' = {
737+ // Cosmos DB Data Contributor role for server
738+ module cosmosDbRoleServer 'core/security/documentdb-sql-role.bicep' = {
709739 scope : resourceGroup
710- name : 'cosmosdb-role-backend '
740+ name : 'cosmosdb-role-server '
711741 params : {
712742 databaseAccountName : cosmosDb .outputs .name
713- principalId : aca .outputs .identityPrincipalId
743+ principalId : server .outputs .identityPrincipalId
714744 roleDefinitionId : '/${subscription ().id }/resourceGroups/${resourceGroup .name }/providers/Microsoft.DocumentDB/databaseAccounts/${cosmosDb .outputs .name }/sqlRoleDefinitions/00000000-0000-0000-0000-000000000002'
715745 }
716746}
@@ -725,10 +755,15 @@ output AZURE_OPENAI_ENDPOINT string = openAi.outputs.endpoint
725755output AZURE_OPENAI_RESOURCE string = openAi .outputs .name
726756output AZURE_OPENAI_RESOURCE_LOCATION string = openAi .outputs .location
727757
728- output SERVICE_ACA_IDENTITY_PRINCIPAL_ID string = aca .outputs .identityPrincipalId
729- output SERVICE_ACA_NAME string = aca .outputs .name
730- output SERVICE_ACA_URI string = aca .outputs .uri
731- output SERVICE_ACA_IMAGE_NAME string = aca .outputs .imageName
758+ output SERVICE_SERVER_IDENTITY_PRINCIPAL_ID string = server .outputs .identityPrincipalId
759+ output SERVICE_SERVER_NAME string = server .outputs .name
760+ output SERVICE_SERVER_URI string = server .outputs .uri
761+ output SERVICE_SERVER_IMAGE_NAME string = server .outputs .imageName
762+
763+ output SERVICE_AGENT_IDENTITY_PRINCIPAL_ID string = agent .outputs .identityPrincipalId
764+ output SERVICE_AGENT_NAME string = agent .outputs .name
765+ output SERVICE_AGENT_URI string = agent .outputs .uri
766+ output SERVICE_AGENT_IMAGE_NAME string = agent .outputs .imageName
732767
733768output AZURE_CONTAINER_ENVIRONMENT_NAME string = containerApps .outputs .environmentName
734769output AZURE_CONTAINER_REGISTRY_ENDPOINT string = containerApps .outputs .registryLoginServer
0 commit comments