Skip to content

Conversation

tzolov
Copy link
Contributor

@tzolov tzolov commented Aug 25, 2025

Ensure PromptReference equality is based solely on identifier and type fields, ignoring other fields like title

Motivation and Context

The PromptReference class lacked proper equals() and hashCode() implementations, which could lead to incorrect behavior when using these objects in collections (HashMap, HashSet, etc.) or when comparing instances. This change ensures that PromptReference equality is based solely on the identifying fields (identifier and type) rather than all object fields, meaning two PromptReference objects with the same identifier and type are considered equal regardless of other descriptive fields like title.

How Has This Been Tested?

  • Added comprehensive unit tests in PromptReferenceEqualsTest.java to verify equals() and hashCode() contract
  • Tested equality scenarios with same identifier/type but different titles
  • Verified hashCode consistency with equals() implementation
  • Ensured reflexive, symmetric, and transitive properties of equals()

Breaking Changes

No breaking changes. This is an additive change that implements standard Java object contracts. Existing code will continue to work as before, but will now benefit from proper object equality semantics.

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

Ensure PromptReference equality is based solely on identifier and type fields, ignoring other fields like title

Signed-off-by: Christian Tzolov <[email protected]>
@tzolov tzolov added this to the 0.12.0 milestone Aug 25, 2025
@tzolov tzolov merged commit 888e555 into modelcontextprotocol:main Aug 25, 2025
1 of 3 checks passed
tzolov added a commit that referenced this pull request Aug 25, 2025
…514)

Ensure PromptReference equality is based solely on identifier and type fields, ignoring other fields like title

Signed-off-by: Christian Tzolov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant