Skip to content

Register List<object> JSON metadata for Native AOT array tool arguments - #1872

Open
girishkvs wants to merge 1 commit into
modelcontextprotocol:mainfrom
girishkvs:dev/girishkvs/native-aot-list-arguments
Open

Register List<object> JSON metadata for Native AOT array tool arguments#1872
girishkvs wants to merge 1 commit into
modelcontextprotocol:mainfrom
girishkvs:dev/girishkvs/native-aot-list-arguments

Conversation

@girishkvs

@girishkvs girishkvs commented Sep 12, 2026

Copy link
Copy Markdown

Fixes #1846

Problem

Passing an array argument to a tool throws at runtime under Native AOT:

System.NotSupportedException: JsonTypeInfo metadata for type 'System.Collections.Generic.List`1[System.Object]'
was not provided by TypeInfoResolver of type '[ModelContextProtocol.McpJsonUtilities+JsonContext, ...]'.
   at ModelContextProtocol.Client.McpClient.ToArgumentsDictionary(IReadOnlyDictionary`2 arguments, JsonSerializerOptions options)
   at ModelContextProtocol.Client.McpClient.CallToolAsync(...)

ToArgumentsDictionary serializes each argument value through McpJsonUtilities.JsonContext. A List<object> argument has no generated metadata there, so the source-generated resolver has nothing to return and serialization fails. Trimmed/AOT apps hit this on any array-valued tool parameter.

Change

Add [JsonSerializable(typeof(List<object>))] to McpJsonUtilities.JsonContext, next to the existing IDictionary<string, object> and IReadOnlyDictionary<string, object> entries.

Extend the AOT compatibility test app with a Join(string[] items) tool and invoke it with a populated and an empty List<object>, so the scenario is covered by make test-aot.

Validation

make test-aot equivalent — dotnet publish with PublishAot=true then run the produced native binary:

Build Result
With this change Success!, exit 0
With the JsonSerializable line reverted NotSupportedException as above, exit non-zero

The new test app assertions fail without the one-line McpJsonUtilities change, so the regression is covered rather than assumed.

dotnet build src/ModelContextProtocol.Core is clean across netstandard2.0, net8.0, net9.0 and net10.0 — 0 warnings, 0 errors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 982e92aa-0c58-4fa5-a59c-8645c6c241f3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Serialization exception when invoking a tool with an array parameter

1 participant