Skip to content

Introduce acceptance helpers to ElicitResult and client capability checks on IMcpServer #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 4 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.ClientSupportsElicitation()
  • IMcpServer.ClientSupportsSampling()
  • IMcpServer.ClientSupportsRoots()
  • 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
Copy link
Contributor

@halter73 halter73 left a comment

Choose a reason for hiding this comment

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

I'm personally a fan of IsAccepted/IsDeclined/IsCanceled so you don't have to carefully read the doc comments or look up the spec to see what the possible values are. An alternative might be an enum, but this is certainly more flexible.

If we add SupportsElicitation, I think we should add SupportsSampling and SupportsRoots for completeness.

/// <remarks>
/// When <see langword="true"/>, the server can call <see cref="McpServerExtensions.ElicitAsync"/> to request additional information from the user via the client.
/// </remarks>
public static bool SupportsElicitation(this IMcpServer server)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe ClientSupportsElicitation? The convenience of not going through client capabilities is reasonable, but it feels weird to have a client capability be a direct pseudo-property on IMcpServer with the client link being entirely implicit.

Copy link
Author

Choose a reason for hiding this comment

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

renamed with ClientSupportsElicitation

Throw.IfNull(server);
return server.ClientCapabilities?.Elicitation is not null;
}

private static void ThrowIfSamplingUnsupported(IMcpServer server)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same as above. Having the Client word would reduce risk of developer confusion.

Copy link
Author

Choose a reason for hiding this comment

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

renamed

@dogukandemir
Copy link
Author

I'm personally a fan of IsAccepted/IsDeclined/IsCanceled so you don't have to carefully read the doc comments or look up the spec to see what the possible values are. An alternative might be an enum, but this is certainly more flexible.

If we add SupportsElicitation, I think we should add SupportsSampling and SupportsRoots for completeness.

@halter73 Checking support of sampling and roots extension methods are added with ClientSupportsSampling and ClientSupportsRoots method names. Client prefix is suggested by @PederHP and it totally makes sense in this context.

@dogukandemir dogukandemir changed the title Improve code readability and reduce potential string comparison errors on ElicitResult Introduce acceptance helpers to ElicitResult and client capability checks on IMcpServer Aug 6, 2025
@dogukandemir dogukandemir force-pushed the feature/elicitation-extension-methods-to-improve-readability branch from 213cbe9 to 9c6314f Compare August 6, 2025 20:42
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.

4 participants