HandleAuthorizationUrlAsync(Uri authorizationUrl, Uri
listener.Start();
Console.WriteLine($"Listening for OAuth callback on: {listenerPrefix}");
- OpenBrowser(authorizationUrl);
+ OpenBrowser(callbackContext.AuthorizationUri);
var context = await listener.GetContextAsync();
var query = HttpUtility.ParseQueryString(context.Request.Url?.Query ?? string.Empty);
var code = query["code"];
+ var state = query["state"];
+ var issuer = query["iss"];
var error = query["error"];
const string ResponseHtml = "Authentication complete
You can close this window now.
";
@@ -102,14 +107,19 @@ static async Task HandleAuthorizationUrlAsync(Uri authorizationUrl, Uri
return null;
}
- if (string.IsNullOrEmpty(code))
+ if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(state))
{
- Console.WriteLine("No authorization code received");
+ Console.WriteLine("The authorization response did not contain both code and state.");
return null;
}
Console.WriteLine("Authorization code received successfully.");
- return code;
+ return new AuthorizationResult
+ {
+ Code = code,
+ State = state,
+ Iss = issuer,
+ };
}
catch (Exception ex)
{
diff --git a/dotnet/samples/02-agents/ModelContextProtocol/README.md b/dotnet/samples/02-agents/ModelContextProtocol/README.md
index d9a1b1a4d..37fbdc60e 100644
--- a/dotnet/samples/02-agents/ModelContextProtocol/README.md
+++ b/dotnet/samples/02-agents/ModelContextProtocol/README.md
@@ -23,7 +23,7 @@ Before you begin, ensure you have the following prerequisites:
|[Agent with MCP server tools and authorization](./Agent_MCP_Server_Auth/)|This sample demonstrates how to use MCP Server tools from a protected MCP server with a simple agent|
|[Agent with per-run MCP authentication headers](./Agent_MCP_PerRun_AuthHeaders/)|This sample demonstrates how to attach per-run, refreshable authentication headers to MCP requests using a custom HttpClient handler and an AsyncLocal scope. Uses Microsoft Foundry (`FOUNDRY_PROJECT_ENDPOINT` / `FOUNDRY_MODEL`) rather than the Azure OpenAI variables in the prerequisites above.|
|[Responses Agent with Hosted MCP tool](./ResponseAgent_Hosted_MCP/)|This sample demonstrates how to use the Hosted MCP tool with the Responses Service, where the service invokes any MCP tools directly|
-|[Agent with long-running MCP task (transparent polling)](./Agent_MCP_LongRunningTask_Client/)|This sample demonstrates how an agent transparently drives a long-running MCP task (SEP-2663) to completion. The wrapper polls the task internally on both `RunAsync` and `RunStreamingAsync` invocations.|
+|[Agent with MCP Tasks extension (transparent polling)](./Agent_MCP_LongRunningTask_Client/)|This sample demonstrates how an agent transparently drives an MCP 2026-07-28 Tasks extension invocation to completion. The wrapper handles inline fallback and polls task-backed calls internally for both `RunAsync` and `RunStreamingAsync`.|
## Running the samples from the console
diff --git a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/HostedMcpTools.csproj b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/HostedMcpTools.csproj
index 0621a4ac3..a7b1ac076 100644
--- a/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/HostedMcpTools.csproj
+++ b/dotnet/samples/04-hosting/FoundryHostedAgents/responses/Hosted-McpTools/HostedMcpTools.csproj
@@ -35,7 +35,7 @@
-
+