Connect from C# McpClient
February 25, 2026 ยท View on GitHub
Connect to Azure MCP Server from a C# console app.
The client will:
- Fetch OAuth Protected Resource Metadata from the server
- Authenticate using interactive browser login
- Connect to the MCP server and list available tools
- Optional: Call
storage_account_gettool to list storage accounts in a subscription.
Prerequisites
- Azure MCP Server deployed and running (see main README)
- .NET 10 SDK
Setup
-
Update
appsettings.jsonwith your MCP server URLEdit
appsettings.jsonand set theMcpServer:Urlto your Container App URL:// If MCP server was deployed using repo's infrastructure, // the commented azd commands can be used to obtain the value. { "McpServer": { // `azd env get-value CONTAINER_APP_URL` "Url": "https://<your_mcp_server_endpoint>" }, // `azd env get-value ENTRA_APP_CLIENT_CLIENT_ID` "EntraClientClientId": "<entraapp_mcpclient_clientid>", // `azd env get-value AZURE_SUBSCRIPTION_ID` "SubscriptionId": "<your_subscription_id>" }Tip: You can also create an
appsettings.Development.jsonfile with your local overrides. Set theDOTNET_ENVIRONMENTenvironment variable toDevelopmentto load it on top ofappsettings.json:# PowerShell $env:DOTNET_ENVIRONMENT="Development" -
Build and run
dotnet runTo perform an additional tool call to list storage accounts, run:
dotnet run -- --list-accounts trueNote: All
appsettings.jsonvalues can also be overridden via command-line arguments (e.g.,--McpServer:Url https://localhost:7071).
Troubleshooting
If you encounter authentication or consent errors (e.g., MsalUiRequiredException), see the
Troubleshooting guide.