Skip to content

Commit 4e22f00

Browse files
Final modificatins before starting on the PE deployment for Foundry
1 parent c7f9aa7 commit 4e22f00

File tree

2 files changed

+38
-27
lines changed

2 files changed

+38
-27
lines changed

labs/ai-foundry-private-mcp/foundry-private-mcp.ipynb

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"## Microsoft Foundry Private connectivity lab\n",
1010
"![flow](./architecture.png)\n",
1111
"\n",
12-
"Playground to show how to create a private network for consuming REST API managed as MCPs using `Foundry Agents V1`. This lab demonstrates how to create a private network for consuming MCPs from `Foundry Agents V1` using `Private Link Services`, `Azure API Management (APIM)`, and `Azure Front Door`.\n",
12+
"Playground to show how to create a private network for consuming REST API managed as MCPs using `Foundry Agents Classic`. This lab demonstrates how to create a private network for consuming MCPs from `Foundry Agents Classic` using `Private Link Services`, `Azure API Management (APIM)`, and `Azure Front Door`.\n",
1313
"\n",
1414
"Notes:\n",
1515
"- `Foundry Agents` are only accessible through `Private Endpoints`. Public network access is disabled.\n",
@@ -19,6 +19,7 @@
1919
"- **`Azure Front Door` is the only publicly-accessible service.**\n",
2020
"\n",
2121
"### Prerequisites\n",
22+
"- **important** Admin access to be able to deploy and configure Enterprise Applications in Entra ID\n",
2223
"- [Python 3.12 or later version](https://www.python.org/) installed\n",
2324
"- [Pandas Library](https://pandas.pydata.org/) and matplotlib installed\n",
2425
"- [VS Code](https://code.visualstudio.com/) installed with the [Jupyter notebook extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter) enabled\n",
@@ -161,7 +162,6 @@
161162
" apim_resource_id = utils.get_deployment_output(output, 'apimResourceId', 'apimResourceId')\n",
162163
"\n",
163164
" outputPls = utils.run(f\"az network private-endpoint-connection list --id {apim_resource_id} --query \\\"[?properties.privateLinkServiceConnectionState.status=='Pending'].id\\\" --output tsv\")\n",
164-
" print(outputPls.text)\n",
165165
"\n",
166166
" if outputPls.success:\n",
167167
" pls_connection_id = outputPls.text.strip()\n",
@@ -220,7 +220,9 @@
220220
" apim_resource_gateway_url = utils.get_deployment_output(output, 'apimResourceGatewayURL', 'APIM API Gateway URL')\n",
221221
" apim_subscription_key = utils.get_deployment_output(output, 'apimSubscriptionKey', 'APIM Subscription Key (masked)', True)\n",
222222
" ai_foundry_project_endpoint = utils.get_deployment_output(output, 'ai_project_endpoint', 'AI Foundry Project Endpoint')\n",
223-
" ai_deployment_name = utils.get_deployment_output(output, 'ai_model_deployment_name', 'AI Model Deployment Name')"
223+
" ai_deployment_name = utils.get_deployment_output(output, 'ai_model_deployment_name', 'AI Model Deployment Name')\n",
224+
" vm_resource_id = utils.get_deployment_output(output, 'vmResourceId', 'VM Resource ID')\n",
225+
" key_vault_url = utils.get_deployment_output(output, 'keyVaultUrl', 'Key Vault URL')"
224226
]
225227
},
226228
{
@@ -230,7 +232,9 @@
230232
"<a id='6'></a>\n",
231233
"### 6️⃣ 🧪 Test the API using a direct HTTP call through Frontdoor\n",
232234
"\n",
233-
"Requests is an elegant and simple HTTP library for Python that will be used here to make raw API requests and inspect the responses. "
235+
"Requests is an elegant and simple HTTP library for Python that will be used here to make raw API requests and inspect the responses.\n",
236+
"\n",
237+
"**After a successful deployment it may take up to 45 mins for this cell to run correctly**"
234238
]
235239
},
236240
{
@@ -271,7 +275,7 @@
271275
" error_text = response.text\n",
272276
" except Exception:\n",
273277
" error_text = \"[Unable to read response body]\"\n",
274-
" utils.print_error(f\"Unexpected status code: {response.status_code}. Response text: {error_text}\")\n",
278+
" utils.print_error(f\"Unexpected status code: {response.status_code}.\")\n",
275279
"\n",
276280
"call_mcp_api(f\"https://{frontdoor_endpoint}\")"
277281
]
@@ -310,14 +314,28 @@
310314
"\n"
311315
]
312316
},
317+
{
318+
"cell_type": "code",
319+
"execution_count": null,
320+
"metadata": {},
321+
"outputs": [],
322+
"source": [
323+
"utils.print_info(f\"\"\"Run the following command to connect to the VM via Bastion: \n",
324+
"az network bastion ssh \\\n",
325+
"--name bastion-host \\\n",
326+
"--resource-group {resource_group_name} \\\n",
327+
"--target-resource-id {vm_resource_id} \\\n",
328+
"--auth-type password \\\n",
329+
"--username azureuser\n",
330+
"\"\"\")"
331+
]
332+
},
313333
{
314334
"cell_type": "markdown",
315335
"metadata": {},
316336
"source": [
317337
"##### 1. Connect to Jumpbox\n",
318-
"Use Azure Bastion to connect to the VM:\n",
319-
"\n",
320-
"## MISSING NSG & SSH Allow rule\n",
338+
"Use Azure Bastion to connect to the VM (full command is the output from previos cell):\n",
321339
"\n",
322340
"```bash\n",
323341
"az network bastion ssh \\\n",
@@ -328,12 +346,9 @@
328346
" --username azureuser\n",
329347
"```\n",
330348
"\n",
331-
"or\n",
332-
"\n",
349+
"***Password:***\n",
333350
"```bash\n",
334-
"az ssh vm --resource-group lab-ai-foundry-private-mcp \\\n",
335-
"--vm-name vm-jumpbox \\\n",
336-
"--subscription <subscription-id>\n",
351+
"@Aa123456789\n",
337352
"```\n",
338353
"\n",
339354
"Or connect via the Azure Portal: Navigate to the VM → Connect → Bastion\n",
@@ -342,23 +357,14 @@
342357
"\n",
343358
"##### 2. Download needed files\n",
344359
"```bash \n",
345-
"wget https://raw.githubusercontent.com/pablocast/AI-Gateway/refs/heads/main/requirements.txt\n",
346360
"wget https://raw.githubusercontent.com/pablocast/AI-Gateway/refs/heads/main/labs/ai-foundry-private-mcp/agent/load_env_from_kv.py\n",
347361
"wget https://raw.githubusercontent.com/pablocast/AI-Gateway/refs/heads/main/labs/ai-foundry-private-mcp/agent/sample_agents_mcp.py\n",
348362
"```\n",
349363
"\n",
350-
"## MISSING REQUIREMENTS.TXT FILE\n",
351-
"##### 4. Run the agent\n",
364+
"##### 3. Run the agent\n",
352365
"```bash\n",
353-
"python3 -m venv ~/venv\n",
354-
"\n",
355-
"# Activate virtual environment\n",
356-
"source ~/venv/bin/activate\n",
357-
"\n",
358-
"pip install -r requirements.txt\n",
359-
"\n",
360366
"# Get Key Vault URL from deployment outputs\n",
361-
"KEY_VAULT_URL=\"https://kv-xqdtyddlyrpoe.vault.azure.net/\"\n",
367+
"KEY_VAULT_URL=\"<KEY-VAULT-URL>\"\n",
362368
"\n",
363369
"# Run the MCP agent\n",
364370
"python3 ~/sample_agents_mcp.py $KEY_VAULT_URL\n",

labs/ai-foundry-private-mcp/main.bicep

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,15 +736,19 @@ resource vmExtension 'Microsoft.Compute/virtualMachines/extensions@2023-09-01' =
736736
apt-get update
737737
738738
# Install Python and venv
739-
apt-get install -y python3 python3-pip python3-venv python3-full
739+
apt-get install -y python3 python3-pip python3-venv python3-full vim wget
740740
741741
# Create a virtual environment for the azureuser
742742
mkdir -p /home/azureuser/scripts
743743
python3 -m venv /home/azureuser/venv
744+
745+
wget -O /home/azureuser/requirements.txt https://raw.githubusercontent.com/Azure-Samples/AI-Gateway/refs/heads/main/requirements.txt
744746
745747
# Install packages in the virtual environment
746748
/home/azureuser/venv/bin/pip install --upgrade pip
747-
/home/azureuser/venv/bin/pip install requests azure-identity azure-ai-projects azure-ai-agents==1.2.0b6 requests jsonref python-dotenv azure-keyvault-secrets
749+
/home/azureuser/venv/bin/pip install -r /home/azureuser/requirements.txt
750+
751+
echo "source /home/azureuser/venv/bin/activate" >> /home/azureuser/.bashrc
748752
749753
# Set ownership
750754
chown -R azureuser:azureuser /home/azureuser/venv
@@ -872,7 +876,7 @@ module keyVaultModule './modules/keyvault.bicep' = {
872876
privateEndpointSubnetId: subnetPe.id
873877
virtualNetworkId: virtualNetwork.id
874878
secrets: {
875-
'MCP-SERVER-URL': 'https://${frontDoorEndpoint.properties.hostName}/order-mcp/mcp'
879+
'MCP-SERVER-URL': '${frontDoorEndpoint.properties.hostName}/order-mcp/mcp'
876880
'MCP-SERVER-LABEL': 'order_mcp'
877881
'AZURE-AI-PROJECT-ENDPOINT': foundryAccountModule.outputs.aiFoundryProjectEndpoint
878882
'AZURE-AI-MODEL-DEPLOYMENT-NAME': modelsConfig[0].name
@@ -896,3 +900,4 @@ output frontDoorEndpointHostName string = frontDoorEndpoint.properties.hostName
896900
output ai_project_endpoint string = foundryAccountModule.outputs.aiFoundryProjectEndpoint
897901
output ai_model_deployment_name string = modelsConfig[0].name
898902
output keyVaultUrl string = keyVaultModule.outputs.keyVaultUrl
903+
output vmResourceId string = vm.id

0 commit comments

Comments
 (0)