Approach 2: MCP/Approvals/Tool Contents stabilization#7299
Open
jozkee wants to merge 17 commits intodotnet:mainfrom
Open
Approach 2: MCP/Approvals/Tool Contents stabilization#7299jozkee wants to merge 17 commits intodotnet:mainfrom
jozkee wants to merge 17 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR stabilizes MCP/tool-calling and approval-related content types across the Microsoft.Extensions.AI stack, updating both runtime code and tests to use the new ToolCallContent / ToolResultContent and ToolApproval* abstractions (and related serialization/telemetry plumbing).
Changes:
- Introduces/standardizes new base content types (
ToolCallContent,ToolResultContent,InputRequestContent,InputResponseContent) and migrates approvals toToolApprovalRequestContent/ToolApprovalResponseContent. - Updates OpenAI Responses conversion + OpenTelemetry serialization to the new content model (e.g.,
OutputsvsOutput, MCP callNamevsToolName, image/code tool call IDs). - Refreshes and expands test coverage for the new content hierarchy, serialization roundtrips, and mixed MCP/function approval flows.
Reviewed changes
Copilot reviewed 70 out of 70 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/Libraries/Microsoft.Extensions.AI.Tests/ChatReduction/SummarizingChatReducerTests.cs | Updates reducer tests to use InputRequestContent/InputResponseContent test types. |
| test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/OpenTelemetryChatClientTests.cs | Updates serialization expectations for tool call/result + approvals; aligns with constructor-based IDs and Outputs. |
| test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/ImageGeneratingChatClientTests.cs | Switches image tool ID assertions from ImageId to CallId. |
| test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs | Updates approval assertions to ToolApprovalRequestContent/ToolApprovalResponseContent and ToolCall. |
| test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientApprovalsTests.cs | Adds mixed MCP/function approval scenarios; updates approval types and introduces input cloning helper for streaming/non-streaming parity. |
| test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientTests.cs | Updates MCP naming/output/approval assertions and adds error + bearer-token extraction tests. |
| test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientIntegrationTests.cs | Updates integration tests to use ToolApprovalRequestContent and CreateResponse; switches MCP tool name/output properties. |
| test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIConversionTests.cs | Updates MCP tool auth/header tests; expands streaming update conversion coverage (including approval correlation behavior). |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Tools/HostedMcpServerToolTests.cs | Adjusts tests for nullable Headers and removal of AuthorizationToken. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/TestJsonSerializerContext.cs | Updates source-gen context registrations for new polymorphic base types and tool call/result arrays. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/UserInputResponseContentTests.cs | Removes tests for deprecated UserInputResponseContent. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/UserInputRequestContentTests.cs | Removes tests for deprecated UserInputRequestContent. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/ToolResultContentTests.cs | Adds roundtrip serialization coverage for ToolResultContent derived types. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/ToolCallContentTests.cs | Adds roundtrip serialization coverage for ToolCallContent derived types. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/ToolApprovalResponseContentTests.cs | Adds constructor validation + serialization roundtrip tests for ToolApprovalResponseContent. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/ToolApprovalRequestContentTests.cs | Adds constructor validation + response factory + serialization roundtrip tests for ToolApprovalRequestContent. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/McpServerToolResultContentTests.cs | Updates MCP result content to Outputs and validates polymorphic roundtrips. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/McpServerToolCallContentTests.cs | Renames MCP call ToolName→Name, Arguments mutability update, and adds serialization roundtrip. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/InputResponseContentTests.cs | Adds base input-response type validation + derived serialization tests. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/InputRequestContentTests.cs | Adds base input-request type validation + derived serialization tests. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/ImageGenerationToolResultContentTests.cs | Moves to ctor-based CallId and removes ImageId usage. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/ImageGenerationToolCallContentTests.cs | Moves to ctor-based CallId and removes ImageId usage. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/FunctionResultContentTests.cs | Adds serialization roundtrip tests for ToolResultContent/AIContent polymorphism. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/FunctionCallContentTests.cs | Adds serialization roundtrip tests for ToolCallContent/AIContent polymorphism. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/FunctionApprovalResponseContentTests.cs | Removes deprecated FunctionApprovalResponseContent tests. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/FunctionApprovalRequestContentTests.cs | Removes deprecated FunctionApprovalRequestContent tests. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/CodeInterpreterToolResultContentTests.cs | Moves to ctor-based CallId and removes settable CallId. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/CodeInterpreterToolCallContentTests.cs | Moves to ctor-based CallId and removes settable CallId. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/Contents/AIContentTests.cs | Updates derived-type list and strengthens per-element polymorphic roundtrip checks. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ChatCompletion/ChatResponseUpdateExtensionsTests.cs | Updates coalescing tests to use CallId and ctor-based tool result creation. |
| test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/AssertExtensions.cs | Extends message comparison helpers to handle tool approvals uniformly across tool call types. |
| src/Libraries/Microsoft.Extensions.AI/ChatReduction/SummarizingChatReducer.cs | Updates “tool-related content” detection to include InputRequestContent/InputResponseContent. |
| src/Libraries/Microsoft.Extensions.AI/ChatCompletion/OpenTelemetryChatClient.cs | Updates OTel payload serialization for renamed properties (Name, Outputs, CallId) and unified approval types. |
| src/Libraries/Microsoft.Extensions.AI/ChatCompletion/ImageGeneratingChatClient.cs | Switches to ctor-based image tool call/result creation with CallId. |
| src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs | Migrates approvals to ToolApproval* with composed request IDs; updates request/response processing logic. |
| src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs | Implements MCP approval request/response correlation in Responses conversion; updates tool call/result modeling and connector auth extraction from headers. |
| src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIJsonContext.cs | Removes IReadOnlyDictionary<string, object?> source-gen contract in favor of IDictionary<string, object?>. |
| src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIAssistantsChatClient.cs | Switches code interpreter tool call/result construction to ctor-based CallId. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.cs | Adds helper for registering derived types into polymorphism options. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.Defaults.cs | Updates default serializer configuration to include new polymorphic bases and registers experimental tool types under ToolCallContent/ToolResultContent. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Tools/HostedMcpServerTool.cs | Stabilizes MCP tool; removes AuthorizationToken and makes Headers nullable/settable; renames Uri ctor arg to serverAddress. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Microsoft.Extensions.AI.Abstractions.json | Updates API baseline/staging to reflect stabilization and new content hierarchy. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/HostedMcpServerToolRequireSpecificApprovalMode.cs | Removes experimental annotations in support of stabilization. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/HostedMcpServerToolNeverRequireApprovalMode.cs | Removes experimental annotations in support of stabilization. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/HostedMcpServerToolApprovalMode.cs | Removes experimental/polymorphic annotations in support of stabilization and updated serialization model. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/HostedMcpServerToolAlwaysRequireApprovalMode.cs | Removes experimental annotations in support of stabilization. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Functions/ApprovalRequiredAIFunction.cs | Removes experimental annotation (stabilizing the API). |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/UserInputResponseContent.cs | Removes deprecated UserInputResponseContent. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/UserInputRequestContent.cs | Removes deprecated UserInputRequestContent. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ToolResultContent.cs | Introduces new ToolResultContent base type for tool results. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ToolCallContent.cs | Introduces new ToolCallContent base type for tool calls. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ToolApprovalResponseContent.cs | Introduces unified approval response content for tool calls. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ToolApprovalRequestContent.cs | Introduces unified approval request content and response factory helper. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/McpServerToolResultContent.cs | Updates MCP tool results to derive from ToolResultContent and renames Output→Outputs. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/McpServerToolCallContent.cs | Updates MCP tool calls to derive from ToolCallContent, renames ToolName→Name, and updates arguments type. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/McpServerToolApprovalResponseContent.cs | Removes deprecated MCP approval response content type. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/McpServerToolApprovalRequestContent.cs | Removes deprecated MCP approval request content type. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/InputResponseContent.cs | Introduces new InputResponseContent base type for input responses. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/InputRequestContent.cs | Introduces new InputRequestContent base type for input requests. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ImageGenerationToolResultContent.cs | Updates image result content to derive from ToolResultContent and use ctor CallId. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ImageGenerationToolCallContent.cs | Updates image call content to derive from ToolCallContent and use ctor CallId. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionResultContent.cs | Updates function result content to derive from ToolResultContent. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionCallContent.cs | Updates function call content to derive from ToolCallContent. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionApprovalResponseContent.cs | Removes deprecated function approval response content type. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionApprovalRequestContent.cs | Removes deprecated function approval request content type. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/CodeInterpreterToolResultContent.cs | Updates code interpreter result content to derive from ToolResultContent and use ctor CallId. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/CodeInterpreterToolCallContent.cs | Updates code interpreter call content to derive from ToolCallContent and use ctor CallId. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/AIContent.cs | Registers stabilized tool/approval content types as derived types of AIContent. |
| src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseExtensions.cs | Updates content coalescing logic for ctor-based tool content and CallId usage. |
ericstj
reviewed
Feb 17, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ToolApprovalRequestContent.cs
Outdated
Show resolved
Hide resolved
ericstj
reviewed
Feb 17, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ToolApprovalRequestContent.cs
Show resolved
Hide resolved
ericstj
reviewed
Feb 17, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ToolApprovalRequestContent.cs
Outdated
Show resolved
Hide resolved
ericstj
reviewed
Feb 17, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Tools/HostedMcpServerTool.cs
Show resolved
Hide resolved
ericstj
reviewed
Feb 17, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionCallContent.cs
Show resolved
Hide resolved
ericstj
reviewed
Feb 17, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/FunctionCallContent.cs
Show resolved
Hide resolved
ericstj
reviewed
Feb 17, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ToolResultContent.cs
Show resolved
Hide resolved
1111f09 to
5343bb0
Compare
ericstj
approved these changes
Feb 18, 2026
Member
ericstj
left a comment
There was a problem hiding this comment.
This looks good to me - your call on the output abstraction. At least think through how you might do it compatibly.
stephentoub
reviewed
Mar 2, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ToolCallContent.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Mar 2, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/ToolResultContent.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Mar 2, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Mar 2, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.Defaults.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Mar 2, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Utilities/AIJsonUtilities.Defaults.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Mar 2, 2026
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Mar 2, 2026
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Mar 2, 2026
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Mar 2, 2026
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs
Outdated
Show resolved
Hide resolved
stephentoub
reviewed
Mar 2, 2026
src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs
Show resolved
Hide resolved
stephentoub
reviewed
Mar 2, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/Tools/HostedMcpServerTool.cs
Show resolved
Hide resolved
stephentoub
reviewed
Mar 2, 2026
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseExtensions.cs
Outdated
Show resolved
Hide resolved
…ontent, InputRequestContent, and InputResponseContent; remove redundant [JsonSerializable] entries from AIJsonUtilities.Defaults * Consolidate AddDerivedContentType into AddAIContentType with baseType param * Make ToolCallContent and ToolResultContent constructors public
…ems to ToolCallContent/ToolResultContent in OpenAIResponsesChatClient (both non-streaming and streaming paths) * Store ToolApprovalRequestContent in mcpApprovalRequests dictionary instead of McpToolCallApprovalRequestItem, reusing ToolCall on correlation
…_approval_content2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Alternative to #7245.
Benefits:
Exception.Cost:
OutputswithResult(can be deferred, non-breaking in the future).CallIdnullability and name