|
56 | 56 | "import utils\n", |
57 | 57 | "\n", |
58 | 58 | "deployment_name = os.path.basename(os.path.dirname(globals()['__vsc_ipynb_file__']))\n", |
59 | | - "resource_group_name = f\"lab-{deployment_name}\" # change the name to match your naming style\n", |
| 59 | + "resource_group_name = f\"lab-{deployment_name}-4\" # change the name to match your naming style\n", |
60 | 60 | "resource_group_location = \"ukwest\"\n", |
| 61 | + "resource_suffix = ''.join(random.choices(string.ascii_letters + string.digits, k=8)).lower()\n", |
61 | 62 | "\n", |
62 | 63 | "aiservices_config = []\n", |
63 | 64 | "\n", |
|
71 | 72 | "inference_api_version = \"2025-03-01-preview\"\n", |
72 | 73 | "foundry_project_name = deployment_name\n", |
73 | 74 | "\n", |
74 | | - "# Generate a unique name for the app registration\n", |
75 | | - "app_registration_name = f\"lab-{deployment_name}-{''.join(random.choices(string.ascii_letters + string.digits, k=8)).lower()}-app\"\n", |
| 75 | + "app_registration_name = f\"lab-{deployment_name}-{resource_suffix}-app\"\n", |
76 | 76 | "\n", |
77 | 77 | "build = 0\n", |
78 | 78 | "prm_mcp_server_image = \"mcp-prm-server\"\n", |
|
83 | 83 | "encryption_iv = base64.b64encode(os.urandom(16)).decode('utf-8')\n", |
84 | 84 | "encryption_key = base64.b64encode(os.urandom(16)).decode('utf-8')\n", |
85 | 85 | "oauth_scopes = 'openid https://graph.microsoft.com/.default'\n", |
| 86 | + "mcpApiPath = \"profile\" # path to the MCP API in the APIM service\n", |
86 | 87 | "\n", |
87 | | - "utils.print_ok('Notebook initialized')" |
| 88 | + "utils.print_ok('Notebook initialized')\n" |
88 | 89 | ] |
89 | 90 | }, |
90 | 91 | { |
|
142 | 143 | " \"mcpEntraAppName\": { \"value\": app_registration_name },\n", |
143 | 144 | " \"apimSku\": { \"value\": apim_sku },\n", |
144 | 145 | " \"aiServicesConfig\": { \"value\": aiservices_config },\n", |
145 | | - " #\"mcpPrmPath\": { \"value\": mcpPrmPath }, ## Add a path you would like your MCP server to exposed as ##\n", |
146 | 146 | " \"modelsConfig\": { \"value\": models_config },\n", |
147 | 147 | " \"apimSubscriptionsConfig\": { \"value\": apim_subscriptions_config },\n", |
148 | 148 | " \"inferenceAPIPath\": { \"value\": inference_api_path },\n", |
149 | 149 | " \"inferenceAPIType\": { \"value\": inference_api_type },\n", |
150 | 150 | " \"foundryProjectName\": { \"value\": foundry_project_name },\n", |
151 | 151 | " \"oauthScopes\": { \"value\": oauth_scopes },\n", |
| 152 | + " \"mcpApiPath\": { \"value\": mcpApiPath },\n", |
152 | 153 | " \"encryptionIV\": { \"value\": encryption_iv },\n", |
153 | 154 | " \"encryptionKey\": { \"value\": encryption_key },\n", |
154 | 155 | " }\n", |
|
160 | 161 | "\n", |
161 | 162 | "# Run the deployment\n", |
162 | 163 | "output = utils.run(f\"az deployment group create --name {deployment_name} --resource-group {resource_group_name} --template-file main.bicep --parameters params.json\",\n", |
163 | | - " f\"Deployment '{deployment_name}' succeeded\", f\"Deployment '{deployment_name}' failed\")" |
| 164 | + " f\"Deployment '{deployment_name}' succeeded\", f\"Deployment '{deployment_name}' failed\")\n" |
164 | 165 | ] |
165 | 166 | }, |
166 | 167 | { |
|
255 | 256 | "# Unauthenticated call should fail with 401 Unauthorized\n", |
256 | 257 | "import requests\n", |
257 | 258 | "\n", |
258 | | - "mcp_server_url = f\"{apim_resource_gateway_url}/mcp\"\n", |
| 259 | + "mcp_server_url = mcp_api_endpoint # e.g. https://<apim-gateway-host>/<mcpApiPath>/mcp\n", |
259 | 260 | "utils.print_info(\"Calling sse endpoint WITHOUT authorization...\")\n", |
260 | 261 | "utils.print_message(f\"MCP Server Url : {mcp_server_url}\")\n", |
261 | 262 | "response = requests.post(mcp_server_url, headers={\"Content-Type\": \"application/json\"})\n", |
|
299 | 300 | "1. Execute `npx @modelcontextprotocol/inspector` in a terminal\n", |
300 | 301 | "2. Access the provided URL in a browser (it should open automatically).\n", |
301 | 302 | "3. Set the transport type as `Streamable HTTP`\n", |
302 | | - "4. Provide the MCP server URL\n", |
| 303 | + "4. Provide the MCP server URL (the `mcp_api_endpoint` value, e.g. `https://<apim-gateway-host>/<mcpApiPath>/mcp`)\n", |
303 | 304 | "5. Click in the `Open Auth Settings` button\n", |
304 | | - "6. Click on `Quick OAuth Flow`\n", |
305 | | - "7. You’ll see a sign-in screen or an “Application Access Request” screen asking for your consent to use your signed-in account. After reviewing the request, click \"Allow\" to proceed.\n", |
306 | | - "8. After being redirected back to the MCP Inspector, scroll down to the `Authentication Complete` step. Expand the `Access Tokens` section and copy the `access_token` value.\n", |
307 | | - "9. Expand the Authentication section on the left and paste the `access_token` into the Bearer Token parameter.\n", |
308 | | - "10. Click on \"Connect\" and verify that the Weather Tool is functioning properly." |
| 305 | + "6. In the auth settings, set the `Client ID` to your MCP app registration's `client_id` and set the `Scope` to `<mcp_api_endpoint>/user_impersonate` (e.g. `https://<apim-gateway-host>/<mcpApiPath>/mcp/user_impersonate` — the same value advertised in the `scopes_supported` field of the Protected Resource Metadata)\n", |
| 306 | + "7. Click on `Quick OAuth Flow`\n", |
| 307 | + "8. You’ll see a sign-in screen or an “Application Access Request” screen asking for your consent to use your signed-in account. After reviewing the request, click \"Allow\" to proceed.\n", |
| 308 | + "9. After being redirected back to the MCP Inspector, scroll down to the `Authentication Complete` step. Expand the `Access Tokens` section and copy the `access_token` value.\n", |
| 309 | + "10. Expand the Authentication section on the left and paste the `access_token` into the Bearer Token parameter.\n", |
| 310 | + "11. Click on \"Connect\" and verify that the Weather Tool is functioning properly.\n" |
309 | 311 | ] |
310 | 312 | }, |
311 | 313 | { |
|
322 | 324 | ], |
323 | 325 | "metadata": { |
324 | 326 | "kernelspec": { |
325 | | - "display_name": "pip2uv", |
| 327 | + "display_name": "ai-gateway (3.12.13.final.0)", |
326 | 328 | "language": "python", |
327 | 329 | "name": "python3" |
328 | 330 | }, |
|
0 commit comments