Builds on section 05 by adding authentication. Connects to the authenticated MCP server (section 06) and passes a bearer token when calling tools. Supports optional Entra ID user auth for the chat UI.
-
appsettings.json and .vscode/launch.json (for F5 debugging): Replace the placeholders:
<AZURE_CLIENT_ID>inMcp.Scope- your MCP Server's app registration Client ID.<OPENAI_API_KEY>- your OpenAI API key.- For Entra ID auth (optional):
<AZURE_TENANT_ID>,<FRONTEND_CLIENT_ID>,<ENTRA_CLIENT_SECRET>in Entra settings.
-
get-user-token.ps1: Pass your MCP Client API's Client ID when running the script (see below).
.\scripts\get-user-token.ps1 -ClientId "<mcp-client-api-client-id>"There is nothing wrong with the code. If it doesn't work try stuff like...
- Make sure the authenticated server (06) is running when you start this
- Make sure you do a clean
dotnet build - Put a breakpoint inside this lambda
async (JsonElement arguments, CancellationToken ct) => await InvokeMcpToolAsync(toolName, arguments.GetRawText(), ct),it WILL hit it - Get a fresh token
- Just try different stuff but I promise this code works when connected to the spc-06 server
- It works even without the EntraID settings in appsettings.json