Skip to content

chore: add #[non_exhaustive] to remaining public structs#768

Open
DaleSeo wants to merge 4 commits intomainfrom
chore/non-exhaustive-missing-structs
Open

chore: add #[non_exhaustive] to remaining public structs#768
DaleSeo wants to merge 4 commits intomainfrom
chore/non-exhaustive-missing-structs

Conversation

@DaleSeo
Copy link
Member

@DaleSeo DaleSeo commented Mar 22, 2026

Motivation and Context

PR #715 began the effort to mark public types as #[non_exhaustive] ahead of the 1.0 release, but missed several structs and enums across transport, service, handler, auth, and task_manager modules. Without this attribute, any new field or variant addition is a semver-breaking change for downstream consumers.

To prevent this class of omission from recurring, this PR also enables clippy::exhaustive_structs and clippy::exhaustive_enums as warn in Cargo.toml. Types that are intentionally exhaustive (unit structs, newtype wrappers, and protocol-spec model types) are annotated with #[allow]. Any new public struct or enum added without #[non_exhaustive] will now produce a Clippy warning.

How Has This Been Tested?

All the existing tests have passed.

Breaking Changes

Yes. Adding #[non_exhaustive] to structs that previously had all public fields is technically a semver-breaking change. However, this is the same intentional tradeoff made in #715: accepting a one-time break now to prevent repeated breaks every time a field is added in the future. Most consumers already use Default or constructor methods, so the practical impact should be limited. For OAuthClientConfig, which had no constructor, a new() builder was added.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@DaleSeo DaleSeo self-assigned this Mar 22, 2026
@github-actions github-actions bot added T-test Testing related changes T-core Core library changes T-examples Example code changes T-handler Handler implementation changes T-transport Transport layer changes T-service Service layer changes T-dependencies Dependencies related changes T-config Configuration file changes T-model Model/data structure changes labels Mar 22, 2026
@DaleSeo DaleSeo force-pushed the chore/non-exhaustive-missing-structs branch 2 times, most recently from 7a87bc3 to 6d411ae Compare March 22, 2026 21:20
@DaleSeo DaleSeo marked this pull request as ready for review March 22, 2026 22:17
@DaleSeo DaleSeo requested a review from a team as a code owner March 22, 2026 22:17
jamadeo
jamadeo previously approved these changes Mar 25, 2026
Copy link
Contributor

@jamadeo jamadeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. For the untagged deserialization changes, do you think it's worth having tests such that we don't regress there? Is it sensitive to the ordering of the variants in the enum?

@DaleSeo DaleSeo force-pushed the chore/non-exhaustive-missing-structs branch 3 times, most recently from 919b8ca to 447943b Compare March 26, 2026 00:32
@DaleSeo DaleSeo force-pushed the chore/non-exhaustive-missing-structs branch from 447943b to ce49fc9 Compare March 26, 2026 00:47
@DaleSeo
Copy link
Member Author

DaleSeo commented Mar 26, 2026

Thanks for the review, @jamadeo! You're right that the untagged deserialization is sensitive to variant ordering. I've added a few regression tests.

@DaleSeo DaleSeo requested a review from jamadeo March 26, 2026 00:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-config Configuration file changes T-core Core library changes T-dependencies Dependencies related changes T-examples Example code changes T-handler Handler implementation changes T-model Model/data structure changes T-service Service layer changes T-test Testing related changes T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants