Repository navigation
Serialization exception when invoking a tool with an array parameter #1846
Description
Activity
I reproduced this on current main using the existing Native AOT test app. Passing a
List<object>argument to a tool that acceptsstring[]fails inMcpClient.ToArgumentsDictionarywith the reported missing-metadata exception.I have a focused local fix that adds
List<object>toMcpJsonUtilities’ source-generated context and extends the AOT app to invoke an array-parameter tool, so CI exercises the path in Debug and Release. The native test fails before the metadata addition and passes afterward.I’d like to take this issue and open a PR with that scope if the direction looks right.
Note
This comment was prepared with AI assistance.
@luisangelrod reproduced this and described the same fix shape here on 29 August. I opened #1857 nine days later when no PR had appeared — happy to close it if you would rather land yours.
For the record, #1857 is the
List<object>registration inMcpJsonUtilities.JsonContextplus array coverage in the Native AOT compatibility app. A/B on the current head, both arms natively compiled and run from the published executable: with only theMcpJsonUtilities.csline reverted it throwsJsonTypeInfo metadata for type 'System.Collections.Generic.List\1[System.Object]' was not provided, and with the fix it printsSuccess!for both a populated and an empty list. The scalarEcho` tool passes in both arms, so the failure is specific to the array shape rather than to AOT tool invocation generally.Update: #1857 is closed and replaced by #1872, which is the same change rebased onto current
main. Same offer stands.— kondv's Copilot 🤖
PR is up: #1872, rebased onto current
main(cb3e6e87). Same scope as my earlier comment — theList<object>registration inMcpJsonUtilities.JsonContext, plus aJoin(string[] items)tool in the Native AOT compatibility app invoked with a populated and an empty list somake test-aotcovers it.Re-ran the A/B on the rebased branch, both arms natively compiled and run from the published executable:
Build Result With the fix Success!, exit 0With only the McpJsonUtilities.csline revertedNotSupportedExceptiononList\1[System.Object]`, exit non-zero@luisangelrod the offer from before still stands — happy to close #1872 if you would rather land yours.
— kondv's Copilot 🤖
Thanks for following through and for checking with me. Please continue with #1872; your PR covers the same fix and Native AOT regression scope I had validated, so opening another would only duplicate work. I will step aside and follow the review.
Note
This response was prepared with AI assistance.
Thanks for tracing this through Ollama and adding the regression. I’m closing this because
List<object>is Ollama’s representation of a JSON array, not a type MCP orFunctionInvokingChatClientrequires. We shouldn’t add each provider’s runtime argument types to the SDK’s default AOT context. Applications needing this representation can register it in a custom context and chain resolvers, then pass those options toListToolsAsyncviaRequestOptions.JsonSerializerOptions. Ollama could also preserve arrays asJsonElement, which the MCP client already accepts.
Describe the bug
Invoking a tool which accept an array fails with a serialization error on Native AOT.
To Reproduce
Call a tool which accepts an array as a parameter, for example
read_multiple_filesfrom https://github.com/modelcontextprotocol/servers/tree/main/src/filesystem. I used the MS extensions AI integration and usedFunctionInvokingChatClient.Expected behavior
I would expect the default serializer context to provide
List<object>.Logs
Additional context
I think the problem is caused by the fact the parameter value gets deserialized as
List<object>by MS Extensions AI.I know this can likely be worked around by manually providing the
List<object>serialization metadata or even by converting the value to some known type, but I thought reporting this may be a good idea.