Repository navigation
Conversation
The generic overload ran ThrowIfElicitationUnsupported before calling the untyped ElicitAsync, which already does that check and skips it on purpose when an outgoing-request interceptor is installed. With an interceptor and a client that doesn't advertise elicitation, the untyped call worked and the typed one threw. Drop the duplicate check so both overloads behave the same, like SampleAsync and RequestRootsAsync. Fixes modelcontextprotocol#1854
|
You missed the same pattern in |
…s set AsSamplingChatClient always called ThrowIfSamplingUnsupported, so a facade with an outgoing-request interceptor still threw "Client does not support sampling" for a client that doesn't advertise the capability. SampleAsync on the same facade already skipped the check and reached the interceptor. SamplingChatClient just calls SampleAsync, so skip the check here too, like RequestRootsAsync.
|
Thanks, you were right. AsSamplingChatClient was still calling ThrowIfSamplingUnsupported up front, so on an interceptor facade it threw "Client does not support sampling." even though SampleAsync on the same facade already reached the interceptor. I skipped the check when OutgoingRequestInterceptor is set, same as SampleAsync and RequestRootsAsync. Added a test for both calls with a client that doesn't advertise sampling. Note I used an AI coding assistant to help investigate the issue and draft the change and tests. I reviewed the code, understand it, and ran the tests myself. |
Removes the duplicate capability check from
ElicitAsync<T>so it behaves like the untypedElicitAsyncwhen an outgoing-request interceptor is installed.Fixes #1854
Motivation and Context
ElicitAsync<T>calledThrowIfElicitationUnsupportedbefore delegating to the untypedElicitAsync. The untyped overload already runs that check itself and intentionally skips it when an interceptor is installed, since the interceptor delivers the request over its own channel (this is how the Tasks package sends requests from background tasks). So with an interceptor and a client that doesn't advertise elicitation, the untyped call returned the interceptor's result and the typed call threwInvalidOperationException.SampleAsyncandRequestRootsAsyncalready check the interceptor first. This makesElicitAsync<T>match them, and leaves a single place for the check.Credit to @ConnorMoss02, who reported this and proposed the same approach in #1853 (closed without merging).
How Has This Been Tested?
New tests in
McpServerTests, all using a client initialized with emptyClientCapabilities:ElicitAsyncOfT_Should_Use_Interceptor_When_Client_Does_Not_Support_Elicitation: the typed call reaches the interceptor, deserializes its result, and sends nothing over the transport. It fails onmainwithClient does not support elicitation requests.and passes with this change.ElicitAsyncOfT_Should_Return_Non_Accepted_Interceptor_Result_Without_Content: when the interceptor returnsnullor{"action":"decline"}, the typed call returnscancelordeclinewith no content.ElicitAsyncOfT_Should_Throw_Exception_If_Client_Does_Not_Support_Elicitation: without an interceptor, the typed call still throwsClient does not support elicitation requests., so the check is still enforced through the untyped path.The tests use a source-generated
JsonSerializerContextbecause reflection-based serialization is disabled in the test project.Local runs on net10.0:
tests/ModelContextProtocol.Tests: 3678 passed, 7 skipped, 0 failedtests/ModelContextProtocol.AspNetCore.Tests: 754 passed, 45 skipped, 0 failedBreaking Changes
None.
ElicitAsync<T>still throws the same exceptions when no interceptor is installed. The only change is on theMCPEXP002interceptor path, where it no longer throws.Types of changes
Checklist
Additional context
No docs change needed. The XML docs on
ElicitAsync<T>still describe the no-interceptor behavior correctly.Note
I used an AI coding assistant to help investigate the issue and draft the change and tests. I reviewed the code, understand it, and ran the tests myself.