@@ -35,8 +35,10 @@ await RunConnected(async (client, server) =>
3535
3636 // Wait for server-side activities to be exported. The server processes messages
3737 // via fire-and-forget tasks, so activities may not be immediately available
38- // after the client operation completes.
39- await WaitForAsync ( ( ) => activities . Count ( a => a . Kind == ActivityKind . Server ) >= 4 ) ;
38+ // after the client operation completes. Wait for the specific activity we need
39+ // rather than a count, as other server activities may be exported first.
40+ await WaitForAsync ( ( ) => activities . Any ( a =>
41+ a . DisplayName == "tools/call DoubleValue" && a . Kind == ActivityKind . Server ) ) ;
4042 }
4143
4244 Assert . NotEmpty ( activities ) ;
@@ -103,8 +105,11 @@ await RunConnected(async (client, server) =>
103105 await Assert . ThrowsAsync < McpProtocolException > ( async ( ) => await client . CallToolAsync ( "does-not-exist" , cancellationToken : TestContext . Current . CancellationToken ) ) ;
104106 } , [ ] ) ;
105107
106- // Wait for server-side activities to be exported.
107- await WaitForAsync ( ( ) => activities . Count ( a => a . Kind == ActivityKind . Server ) >= 4 ) ;
108+ // Wait for server-side activities to be exported. Wait for specific activities
109+ // rather than a count, as other server activities may be exported first.
110+ await WaitForAsync ( ( ) =>
111+ activities . Any ( a => a . DisplayName == "tools/call Throw" && a . Kind == ActivityKind . Server ) &&
112+ activities . Any ( a => a . DisplayName == "tools/call does-not-exist" && a . Kind == ActivityKind . Server ) ) ;
108113 }
109114
110115 Assert . NotEmpty ( activities ) ;
@@ -173,8 +178,10 @@ await RunConnected(async (client, server) =>
173178 await tool . InvokeAsync ( new ( ) { [ "amount" ] = 42 } , TestContext . Current . CancellationToken ) ;
174179 } , [ ] ) ;
175180
176- // Wait for server-side activities to be exported.
177- await WaitForAsync ( ( ) => activities . Count ( a => a . Kind == ActivityKind . Server ) >= 3 ) ;
181+ // Wait for server-side activities to be exported. Wait for specific activities
182+ // rather than a count, as other server activities may be exported first.
183+ await WaitForAsync ( ( ) => activities . Any ( a =>
184+ a . DisplayName == "tools/call DoubleValue" && a . Kind == ActivityKind . Server ) ) ;
178185 }
179186
180187 // The outer activity should have MCP-specific attributes added to it
0 commit comments