Fix form mode elicitation schema check to apply for all form requests (#1151)
This commit is contained in:
parent
eca882e48c
commit
0585c27d53
2 changed files with 50 additions and 1 deletions
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue