Fix form mode elicitation schema check to apply for all form requests (#1151)

This commit is contained in:
Copilot 2026-01-19 21:26:28 -05:00 • committed by GitHub
commit 0585c27d53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 50 additions and 1 deletions

View file

@ -488,7 +488,7 @@ public abstract partial class McpServer : McpSession
throw new InvalidOperationException("Client does not support elicitation requests.");
}
if (string.Equals(request.Mode, "form", StringComparison.Ordinal) && elicitationCapability.Form is null)
if (string.Equals(request.Mode, "form", StringComparison.Ordinal))
{
if (request.RequestedSchema is null)
{

View file

@ -163,6 +163,26 @@ public partial class UrlElicitationTests(ITestOutputHelper testOutputHelper) : C
throw new McpException(ex.Message);
}
}
else if (request.Params.Name == "TestFormElicitationMissingSchema")
{
try
{
await request.Server.ElicitAsync(new()
{
Message = "Form elicitation without schema should fail.",
},
cancellationToken);
}
catch (ArgumentException ex)
{
throw new McpException(ex.Message);
}
return new CallToolResult
{
Content = [new TextContentBlock { Text = "missing-schema-succeeded" }],
};
}
Assert.Fail($"Unexpected tool name: {request.Params.Name}");
return new CallToolResult { Content = [] };
@ -506,6 +526,35 @@ public partial class UrlElicitationTests(ITestOutputHelper testOutputHelper) : C
Assert.Equal("Authorization is required to access Example Co.", elicitation.Message);
}
[Fact]
public async Task FormElicitation_Requires_RequestedSchema()
{
var elicitationHandlerCalled = false;
await using McpClient client = await CreateMcpClientForServer(new McpClientOptions
{
Capabilities = new ClientCapabilities
{
Elicitation = new(),
},
Handlers = new McpClientHandlers()
{
ElicitationHandler = (request, cancellationToken) =>
{
elicitationHandlerCalled = true;
return new ValueTask<ElicitResult>(new ElicitResult());
},
}
});
var result = await client.CallToolAsync("TestFormElicitationMissingSchema", cancellationToken: TestContext.Current.CancellationToken);
Assert.True(result.IsError);
var textContent = Assert.IsType<TextContentBlock>(result.Content[0]);
Assert.Equal("An error occurred invoking 'TestFormElicitationMissingSchema': Form mode elicitation requests require a requested schema.", textContent.Text);
Assert.False(elicitationHandlerCalled);
}
private ElicitationCapability AssertServerElicitationCapability()
{
var capabilities = Server.ClientCapabilities;