-
Notifications
You must be signed in to change notification settings - Fork 58
AnthropicBetaClientExtensions breaks with Microsoft.Extensions.AI >= 10.4.0 #145
Description
SDK version: 12.9.0 (latest)
Microsoft.Extensions.AI version: 10.4.0 / 10.4.1
Platform: .NET
Description
Upgrading Microsoft.Extensions.AI from 10.3.0 to 10.4.x causes a MissingMethodException when the AnthropicBetaClientExtensions.AnthropicChatClient attempts to deserialise an API response containing an MCP tool use block.
In Microsoft.Extensions.AI 10.4.0, the MCP Server Tool Content APIs were promoted from experimental (MEAI001) to stable. As part of this stabilisation, McpServerToolCallContent appears to have undergone a breaking API change: the Arguments property setter signature changed from accepting IReadOnlyDictionary<string, object?> to IDictionary which somehow seems incompatible with how the Anthropic C# SDK currently tries to set it.
I think the issue lies in the ToAIContent method in AnthropicBetaClientExtensions.cs within the switch statement where it parses the tool content:
case BetaMcpToolUseBlock mcpToolUse:
return new McpServerToolCallContent(
mcpToolUse.ID,
mcpToolUse.Name,
mcpToolUse.ServerName
)
{
Arguments = mcpToolUse.Input.ToDictionary(
e => e.Key,
e => (object?)e.Value
),
RawRepresentation = mcpToolUse,
};This fails at runtime because the set_Arguments method no longer exists with the expected signature in 10.4.x.
Error
Method not found: 'Void Microsoft.Extensions.AI.McpServerToolCallContent.set_Arguments(System.Collections.Generic.IReadOnlyDictionary`2<System.String,System.Object>)'.
System.MissingMethodException: Method not found: 'Void Microsoft.Extensions.AI.McpServerToolCallContent.set_Arguments(System.Collections.Generic.IReadOnlyDictionary`2<System.String,System.Object>)'
at Microsoft.Extensions.AI.AnthropicBetaClientExtensions.AnthropicChatClient.ToAIContent(BetaContentBlock block)
at System.Linq.Enumerable.IListSelectIterator`2.MoveNext()
at System.Collections.Generic.List`1.AddRange(IEnumerable`1 collection)
at Microsoft.Extensions.AI.AnthropicBetaClientExtensions.AnthropicChatClient.GetResponseAsync(...) in AnthropicBetaClientExtensions.cs:line 276
Root cause (I think)
In Microsoft.Extensions.AI 10.4.0, McpServerToolCallContent was graduated from experimental to stable. As part of this, it is now a derived type of ToolContent (which itself derives from AIContent) rather than deriving directly from AIContent. This inheritance change likely also altered the Arguments property's setter visibility or signature, breaking the object initialiser pattern used in ToAIContent.
Steps to reproduce
- Create a project using
Anthropic12.9.0 andMicrosoft.Extensions.AI10.4.0 (or 10.4.1) - Use the
AnthropicBetaClientExtensions(IBetaService.AsIChatClient()) to send a message that triggers an MCP tool call - Observe
MissingMethodExceptionthrown fromToAIContent
Workaround
Pin Microsoft.Extensions.AI to 10.3.0 to avoid the issue until the SDK is updated.
Expected behaviour
The SDK should be compatible with Microsoft.Extensions.AI 10.4.x and correctly map BetaMcpToolUseBlock to the updated McpServerToolCallContent API.
Additional context
The relevant upstream change in Microsoft.Extensions.AI is described as:
MCP Server Tool Content and Function Call Approval APIs are now stable (previously
MEAI001)
I think the fix will likely require updating the ToAIContent method in AnthropicBetaClientExtensions.cs to use the new constructor or property assignment pattern for McpServerToolCallContent as it exists in 10.4.x.