You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Serialization exception when invoking a tool with an array parameter #1846
Expected behavior
I would expect the default serializer context to provide List<object>.
Logs
System.NotSupportedException: JsonTypeInfo metadata for type 'System.Collections.Generic.List`1[System.Object]' was not provided by TypeInfoResolver of type '[ModelContextProtocol.McpJsonUtilities+JsonContext, Microsoft.Extensions.AI.AIJsonUtilities+JsonContext]'. If using source generation, ensure that all root types passed to the serializer have been annotated with 'JsonSerializableAttribute', along with any types that might be serialized polymorphically.
at System.Text.Json.ThrowHelper.ThrowNotSupportedException_NoMetadataForType(Type type, IJsonTypeInfoResolver resolver)
at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType)
at System.Text.Json.JsonSerializerOptions.GetTypeInfoForRootType(Type type, Boolean fallBackToNearestAncestorType)
at System.Text.Json.JsonSerializerOptions.TryGetPolymorphicTypeInfoForRootType(Object rootValue, JsonTypeInfo& polymorphicTypeInfo)
at System.Text.Json.Serialization.Metadata.JsonTypeInfo`1.Serialize(Utf8JsonWriter writer, T& rootValue, Object rootValueBoxed)
at System.Text.Json.JsonSerializer.WriteElement[TValue](TValue& value, JsonTypeInfo`1 jsonTypeInfo)
at System.Text.Json.JsonSerializer.SerializeToElement[TValue](TValue value, JsonTypeInfo`1 jsonTypeInfo)
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.
I reproduced this on current main using the existing Native AOT test app. Passing a List<object> argument to a tool that accepts string[] fails in McpClient.ToArgumentsDictionary with the reported missing-metadata exception.
I have a focused local fix that adds List<object> to McpJsonUtilities’ 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.
@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 in McpJsonUtilities.JsonContext plus 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 the McpJsonUtilities.cs line reverted it throws JsonTypeInfo metadata for type 'System.Collections.Generic.List\1[System.Object]' was not provided, and with the fix it prints Success!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.
PR is up: #1872, rebased onto current main (cb3e6e87). Same scope as my earlier comment — the List<object> registration in McpJsonUtilities.JsonContext, plus a Join(string[] items) tool in the Native AOT compatibility app invoked with a populated and an empty list so make test-aot covers 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 0
With only the McpJsonUtilities.cs line reverted
NotSupportedException on List\1[System.Object]`, exit non-zero
@luisangelrod the offer from before still stands — happy to close #1872 if you would rather land yours.
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.
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 or FunctionInvokingChatClient requires. 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 to ListToolsAsync via RequestOptions.JsonSerializerOptions. Ollama could also preserve arrays as JsonElement, which the MCP client already accepts.
@KubaZ2, PR #1872 was closed by @halter73 because List<object> is how Ollama represents JSON arrays, not a type MCP requires. He suggested a custom serializer context instead. I've only observed this with Ollama; have you seen it with any other packages?
Activity
luisangelrod commentedon Aug 29, 2026
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.
kondv commentedon Sep 8, 2026
@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 🤖
kondv commentedon Sep 12, 2026
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:
Success!, exit 0McpJsonUtilities.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 🤖
luisangelrod commentedon Oct 2, 2026
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.
halter73 commentedon Oct 6, 2026
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.girishkvs commentedon Oct 6, 2026
@KubaZ2, PR #1872 was closed by @halter73 because
List<object>is howOllamarepresents JSON arrays, not a type MCP requires. He suggested a custom serializer context instead. I've only observed this withOllama; have you seen it with any other packages?— girishkvs's Copilot 🤖