json-serialization
Skill1 starsChanged 6 days agoMITView on GitHub
How this MCP server reads tool arguments and writes results with System.Text.Json - McpSerializer.Options built on the SDK defaults, the source-generated AppJsonSerializerContext and which types it lists, and how tests use the same options. Use when adding a result model, changing how JSON looks, or when a value serialises differently than expected.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- bkywksj/knowledge-basetheir own version, first seen Oct 8, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- bkywksj/knowledge-base★ 340same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- add-a-use-caseSkill
- api-conventionsSkill
- branches-and-pull-requestsSkill
- cancellationSkill
- ci-for-your-solutionSkill
- ci-pipelineSkill
- clean-architecture-layersSkill
- configuration-and-environmentsSkill
- coverageSkill
- csharp-house-styleSkill
- data-access-ef-coreSkill
- database-migrationsSkill
- docker-and-composeSkill
- docs-and-voiceSkill
- errors-and-exceptionsSkill
- expose-a-use-caseSkill
- family-syncSkill
- health-checksSkill
- integration-testsSkill
- mapping-with-mapperlySkill
- mcp-inspectorSkill
- mediatorSkill
- optional-token-authSkill
- packages-and-dependenciesSkill
- pagingSkill
- presentation-integration-testsSkill
- releasesSkill
- sample-dataSkill
- security-findingsSkill
- serilogSkill
- telemetrySkill
- template-authoringSkill
- test-designSkill
- time-providerSkill
- unit-testsSkill
- validationSkill
- writing-a-skillSkill
- xml-docs-and-openapiSkill
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 30
Add every new result model, and the ResultPage<T> you return, to AppJsonSerializerContext with [JsonSerializable(typeof(...))].
- Distinctive: line 31
Remove a type from the context when nothing returns it any more.
- Very specific: line 51
Add ReferenceHandler.IgnoreCycles or Preserve to hide a cycle.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
JSON serialization (MCP)
The rule
Tool arguments, tool results, resources and prompt attachments all use one set of options: McpSerializer.Options in src/Presentation/Serialization/McpSerializer.cs. It starts from the SDK's McpJsonUtilities.DefaultOptions, then sets camelCase names and writes nulls, because tool output schemas list nullable fields such as nextOffset as required and strict clients reject a result that leaves them out, and puts AppJsonSerializerContext first in the resolver chain so the listed types use generated code. The options are read-only once built.
| Used by | How |
| Tools and prompts | WithToolsFromAssembly(serializerOptions: McpSerializer.Options) and WithPromptsFromAssembly(...) |
| Resources and embedded prompt resources | McpSerializer.Serialize(value) |
| Integration tests | Deserialize<T>() in tests/Presentation.Tests.Integration/Extensions/JsonSerializerExtensions.cs |
AppJsonSerializerContext lists exactly the types the server writes: the result models, their ResultPage<T> forms and Version.
Results are trees. A review inside a movie carries the movie's id and title, not the movie, so there's no cycle handling.
Tool schemas are generated from the C# types, and a nullable field comes out as "type": ["string", "null"]. That's valid JSON Schema, but clients that map schemas onto a single-type dialect, such as Gemini's function declarations, can reject it or drop its constraints. PortableSchemaFilter rewrites each one to an anyOf of single types when tools are listed, keeping description, title and default on the outer node. It runs for every tool, so a new tool needs nothing extra. ListTools_ShouldWrite_PortableSchemas fails if a type array gets through.
The filter is a workaround for those clients, and nothing else needs it. Delete it, with that test, once they accept type arrays. To check, take it out and confirm the Inspector shows no schema portability warnings on any tool.
Steps
- Add every new result model, and the
ResultPage<T>you return, toAppJsonSerializerContextwith[JsonSerializable(typeof(...))]. - Remove a type from the context when nothing returns it any more.
- Change how JSON looks only in
McpSerializer.CreateOptions. Keep the context's[JsonSourceGenerationOptions]matching it. - Serialise resources with
McpSerializer.Serialize, neverJsonSerializer.Serializewith default options.
Example
// src/Presentation/Serialization/McpSerializer.cs
var options = new JsonSerializerOptions(McpJsonUtilities.DefaultOptions)
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.Never
};
options.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
options.MakeReadOnly();Don't
- Build your own
JsonSerializerOptions, including in tests. - Add
ReferenceHandler.IgnoreCyclesorPreserveto hide a cycle. Change the result shape. - List Application entities in the context unless a resource returns one directly.
- Use Newtonsoft.Json.
- Hand-write a tool schema to get around a portability warning. Change
PortableSchemaFilter.
Check
dotnet test tests/Presentation.Tests.IntegrationDoes it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

