Skip to content

Improve code readability and reduce potential string comparison errors on ElicitResult #666

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dogukandemir
Copy link

@dogukandemir dogukandemir commented Aug 1, 2025

This PR has following additions on IMcpServer and ElicitResult.

  • IMcpServer.SupportsElicitation()
  • ElicitResult.IsAccepted
  • ElicitResult.IsDeclined
  • ElicitResult.IsCancelled

Motivation and Context

Motivation is to make code more readable and less error-prone than direct string comparisons.

How Has This Been Tested?

All newly added functionality tested in unit tests.

Breaking Changes

There is no breaking change.

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
    • Note: Since this change is not related with protocol itself, I haven't read it all.
  • 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

Additional context

{
Throw.IfNull(result);
return string.Equals(result.Action, "cancel", StringComparison.OrdinalIgnoreCase);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If we want to do this, why not have them as JsonIgnore properties directly on ElicitResult?

Copy link
Author

Choose a reason for hiding this comment

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

Great point. While I was writing SupportsElicitation method, I biased to use extension method. Having properties with JsonIgnore would makes more sense. I'll refactor it.

Copy link
Author

Choose a reason for hiding this comment

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

@stephentoub I've completed refactoring with your eye-opening question. Do you think this PR contributes to developer experience and you'd like to see it in the SDK?

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks. We'll discuss it.

@dogukandemir dogukandemir changed the title Elicitation extension methods to improve code readability and reduce potential string comparison errors Improve code readability and reduce potential string comparison errors on ElicitResult Aug 1, 2025
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.

2 participants