Uh oh!
There was an error while loading. Please reload this page.
Audit protocol types - #892
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
eiriktsarpalis
commented
Oct 17, 2025
For context, the presence of |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
halter73
commented
Oct 17, 2025
What are our principles around this? I know JsonNode is mutable and JsonElement is not, but why is JsonNode use for params and results and JsonElement or |
Exactly what I'm wondering too 🙂 Maybe we could get an STJ expert to weigh in on this? Edit: @eiriktsarpalis , do you have any thoughts about this? |
@MackinnonBuck I've opened a new pull request, #923, to work on those changes. Once the pull request is ready, I'll request review from you. |
eiriktsarpalis
commented
Oct 29, 2025
|
* Initial plan * Add DefaultSamplingMaxTokens property to McpServerOptions Co-authored-by: MackinnonBuck <10456961+MackinnonBuck@users.noreply.github.com> * Add test to verify DefaultSamplingMaxTokens is respected Co-authored-by: MackinnonBuck <10456961+MackinnonBuck@users.noreply.github.com> * Merge test into existing SampleAsync_Messages_Forwards_To_McpServer_SendRequestAsync Co-authored-by: MackinnonBuck <10456961+MackinnonBuck@users.noreply.github.com> * Update src/ModelContextProtocol.Core/Server/McpServerOptions.cs --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: MackinnonBuck <10456961+MackinnonBuck@users.noreply.github.com> Co-authored-by: Mackinnon Buck <mackinnon.buck@gmail.com>
MackinnonBuck
commented
Oct 31, 2025
Thanks for the clarification, @eiriktsarpalis! I'll leave the properties representing JSON objects as-is for this PR, then. Nothing jumps out at me as obviously using the wrong type. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: David Cantú <dacantu@microsoft.com>
Co-authored-by: David Cantú <dacantu@microsoft.com>
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
| /// </remarks> | ||
| [JsonPropertyName("id")] | ||
| public RequestId Id { get; init; } | ||
| public required RequestId Id { get; set; } |
There was a problem hiding this comment.
This seems like a problem. We have code that checks whether Id has been set and if it hasn't it sets it to the next ID in the sequence. With this change, the developer needs to explicitly set the ID, and that code we have would appear to be dead? Making this required places a significant burden on a developer to track sent IDs and will make it likely I think that they end up sending duplicated IDs, violating the protocol.
There was a problem hiding this comment.
Looking at the rest of the changes, I guess the intent is that it's ok to set it to default? That of course still begs the question then why it's required.
Summary
Audits and standardizes MCP protocol types for consistency.
Fixes#519
Description
There are several inconsistencies across protocol types, including:
initvs.setrequiredvs. default property valuesenumvs.stringJsonNodevs.JsonElementvs.IDictionary<string, JsonElement>vs.IDictionary<string, object>This PR applies the following set of conventions to improve consistency:
Property Mutability
Guideline: Always use
set- noinit-only properties.Rationale:
setorinit, it's easier to standardize onsetbecause doing so is non-breakinginitmeans that if we do want to mutate a property after initialization, we need to clone the its containing object, which can be error-prone and isn't great for perfRequired Properties
Guideline: Use
requiredwhen the spec indicates a property is required, unless a clear, safe default exists.Rationale:
Safe defaults include:
Avoid defaults such as:
"") - this is rarely the expected value for a "required" propertyCollections
Guideline: Prefer
IList<T>/IDictionary<TKey, TValue>overIReadOnlyList<T>/IReadOnlyDictionary<TKey, TValue>.Rationale:
Open Questions
The following inconsistencies remain for further discussion:
enumvs.string: propertiesThe MCP schema defines some properties as unions of string values.
enumoffers strong typingstringis more future-proof (e.g., if new values are added)Existing examples of each:
enum:ContextInclusion,Rolestring:ElicitResult.ActionJSON-like Structures:
The use of
JsonNode,JsonElement,IDictionary<string, JsonElement>, andIDictionary<string, object>varies.Additional Notes