-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can structural equality be implemented for McpServerConfig? #181
Comments
For this out of the box without a custom comparer we would need to use a custom collection type that supports structural equality comparison, such as the ones used in the dotnet/runtime source generators or PolyType. The problem is that these collections are immutable, as best practice dictates that we shouldn't implement |
Why use |
It's mostly inheritance from the mcpdotnet library I would think. @halter73 is working towards making all configuration types mutable so that they better work using the options pattern. |
Is there another use case for |
No other use case exists to my knowledge. Me and @stephentoub have been discussing the possibility of ditching the type altogether in favor of |
I'm not sure we want to remove it altogether. There's enough input here that a) it would make a big signature to accept as flattened arguments, and b) it's likely there are additional arguments we'd want to add in the future, and it's much easier to do that by adding a property to an options bag. But changing the type to be iequatable with whatever immutability requirements are necessary, or just including a concrete iequalitycomparer implementation in the lib as well, would be fine. |
To be clear, I'm not suggesting we remove options objects altogether but that instead each transport implementation should define its own options object if necessary. The current approach means that some properties are applied to slightly different concepts depending on the transport: csharp-sdk/src/ModelContextProtocol/Configuration/McpServerConfig.cs Lines 24 to 28 in 674cb15
and we're being incentivized to include catch-alls in case we need to adopt it to third-party transports: csharp-sdk/src/ModelContextProtocol/Configuration/McpServerConfig.cs Lines 35 to 38 in 674cb15
|
That sounds reasonable. |
@eiriktsarpalis Should we close this now that you removed McpServerConfig in #230? |
I think we still need to do it for the individual option types used by the transports. Right @AArnott? |
I haven't seen the version where you removed |
The
McpServerConfig
type is arecord
, which tends to implement structural equality by default for scalar values. However, it has an array and a dictionary, which requires special handling to achieve structural equality.csharp-sdk/src/ModelContextProtocol/Configuration/McpServerConfig.cs
Lines 30 to 38 in 25bcb44
For my use case, when we're looking at identifying duplicate server configurations across files or across reloads of a changed mcp.json file, it's useful to be able to recognize when two server config objects are identical.
I can implement this myself with a custom
IEqualityComparer
, but as the config may change over time to get new properties, having it build into the type itself would be great.The text was updated successfully, but these errors were encountered: