Tighten draft protocol negotiation boundaries (#1692)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Tarek Mahmoud Sayed <tarekms@ntdev.microsoft.com>
This commit is contained in:
Stephen Halter 2026-07-12 14:30:49 -07:00 • committed by GitHub
commit fd38f51e27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -127,24 +127,23 @@ public class TaskProtocolGatingTests : ClientServerTestBase
}
[Fact]
public async Task LegacyClient_CallToolRaw_WithForgedTaskOptIn_ServerReturnsDirectResult()
public async Task LegacyClient_CallToolRaw_WithForgedTaskOptIn_RejectsReservedMetadata()
{
await using var client = await CreateMcpClientForServer(new McpClientOptions { ProtocolVersion = LatestStableVersion });
var ct = TestContext.Current.CancellationToken;
// Forge a SEP-2575 capabilities envelope carrying the tasks extension opt-in on a legacy
// request. The server must still refuse to create a task because the per-request protocol
// version is not the 2026-07-28 protocol.
var result = await client.CallToolRawAsync(
// request. The server rejects reserved per-request metadata before it can affect behavior.
var ex = await Assert.ThrowsAsync<McpProtocolException>(async () => await client.CallToolRawAsync(
new CallToolRequestParams
{
Name = "test-tool",
Arguments = CreateArguments("input", "forged"),
Meta = CreateForgedTaskOptInMeta(),
}, ct);
}, ct));
Assert.False(result.IsTask);
Assert.NotNull(result.Result);
Assert.Equal(McpErrorCode.InvalidRequest, ex.ErrorCode);
Assert.Contains(ClientCapabilitiesMetaKey, ex.Message);
}
[Fact]