Skip to content

Approach 2: MCP/Approvals/Tool Contents stabilization#7299

Open
jozkee wants to merge 11 commits intodotnet:mainfrom
jozkee:tool_approval_content2
Open

Approach 2: MCP/Approvals/Tool Contents stabilization#7299
jozkee wants to merge 11 commits intodotnet:mainfrom
jozkee:tool_approval_content2

Conversation

@jozkee
Copy link
Member

@jozkee jozkee commented Feb 13, 2026

@jozkee jozkee requested a review from a team as a code owner February 13, 2026 18:12
@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Feb 13, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to ToolApprovalRequestContent / ToolApprovalResponseContent.
  • Updates OpenAI Responses conversion + OpenTelemetry serialization to the new content model (e.g., Outputs vs Output, MCP call Name vs ToolName, 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 ToolNameName, 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 OutputOutputs.
src/Libraries/Microsoft.Extensions.AI.Abstractions/Contents/McpServerToolCallContent.cs Updates MCP tool calls to derive from ToolCallContent, renames ToolNameName, 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.

// as well as the [JsonSerializable] attributes for them on the JsonContext should be removed.
// [JsonDerivedType(typeof(CodeInterpreterToolResultContent), "codeInterpreterToolResult")]
// [JsonDerivedType(typeof(ImageGenerationToolResultContent), "imageGenerationToolResult")]
public class ToolResultContent : AIContent
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without a property that represents the result of the tool, folks will need to downcast to some tool type they know that will have output. I wonder if it makes sense to have a result property on this, even if it's not the serialized property.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We would need to reconciliate object? Result from FRC and IList<AIContent>? Outputs from the rest. I suggest we defer for future this kind of breaking change. This could come handy for APIs that could accept the loose ToolResultContent, for now, we have it just for symmetry with ToolCallContent and we don't really use it for more. It's also related to #7057.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you worried about reconciling it later making a breaking change? I suppose we could always create a new read-only virtual property that's implemented by the derived types. This PR nearly solves #7057. It does look like a few reference counts on a unified base output property.

@jozkee jozkee force-pushed the tool_approval_content2 branch from 1111f09 to 5343bb0 Compare February 18, 2026 04:18
Copy link
Member

@ericstj ericstj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me - your call on the output abstraction. At least think through how you might do it compatibly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments