Skip to content

AnthropicBetaClientExtensions breaks with Microsoft.Extensions.AI >= 10.4.0 #145

@Millmer

Description

@Millmer

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

  1. Create a project using Anthropic 12.9.0 and Microsoft.Extensions.AI 10.4.0 (or 10.4.1)
  2. Use the AnthropicBetaClientExtensions (IBetaService.AsIChatClient()) to send a message that triggers an MCP tool call
  3. Observe MissingMethodException thrown from ToAIContent

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingsdk

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions