modelcontextprotocol / modelcontextprotocol/csharp-sdk

Allow JsonSerializerOptions without TypeInfoResolver

Open
#1,150 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement needs confirmation P3
Dominant language
C#
Stars
4.5k
Forks
814
Avg merge
9d 19h
Merged PRs (30d)
4

Description

I have JsonSerializerOptions which only adds some converters and set the naming policy. I don't have a source generated JsonSerializerContext and therefore no TypeInfoResolver.

When passing these options to a WithTools function, I get the exception:

JsonSerializerOptions instance must specify a TypeInfoResolver setting before being marked as read-only.

I understand that making these options read only is a good thing, but I don't understand enough about the difference to the overload of MakeReadOnly(populateMissingResolver) on the options.

I can set TypeInfoResolver = new DefaultJsonTypeInfoResolver() on my options, but that seems a bit weird.

To Reproduce
Steps to reproduce the behavior:

  1. Pass a new System.Text.Json.JsonSerializerOptions() object to one of the WithTools functions.

Expected behavior
No exception should be thrown.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the WithTools implementation mentioned in the issue and trace how the supplied JsonSerializerOptions are made read-only. Reproduce the behavior with a new System.Text.Json.JsonSerializerOptions that only adds converters and a naming policy; done means passing it to WithTools throws no exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.