Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions tests/ModelContextProtocol.AspNetCore.Tests/MapMcpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ await client.CallToolAsync("sampling-tool",
public async Task OutgoingFilter_MultipleFilters_ExecuteInOrder()
{
var executionOrder = new List<string>();
var allFiltersComplete = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

Builder.Services.AddMcpServer()
.WithHttpTransport(ConfigureStateless)
Expand All @@ -411,6 +412,7 @@ public async Task OutgoingFilter_MultipleFilters_ExecuteInOrder()
if (context.JsonRpcMessage is JsonRpcResponse r2 && r2.Result is JsonObject obj2 && obj2.ContainsKey("tools"))
{
executionOrder.Add("filter1-after");
allFiltersComplete.TrySetResult();
}
});

Expand Down Expand Up @@ -439,6 +441,11 @@ public async Task OutgoingFilter_MultipleFilters_ExecuteInOrder()

await client.ListToolsAsync(cancellationToken: TestContext.Current.CancellationToken);

// The outermost filter's "after" callback runs after the response has been
// sent to the client, so ListToolsAsync may return before it executes.
// Wait for it to complete before asserting.
await allFiltersComplete.Task.WaitAsync(TestContext.Current.CancellationToken);
Comment thread
ericstj marked this conversation as resolved.
Outdated

Assert.Equal(["filter1-before", "filter2-before", "filter2-after", "filter1-after"], executionOrder);
}

Expand Down
Loading