| 333 | } |
| 334 | |
| 335 | func validateToolOrder(t *testing.T, proxy mcp.ServerProxier) { |
| 336 | t.Helper() |
| 337 | |
| 338 | tools := proxy.ListTools() |
| 339 | require.NotEmpty(t, tools) |
| 340 | require.Greater(t, len(tools), 1) |
| 341 | |
| 342 | // Ensure tools are sorted by ID; unstable order can bust the cache and lead to increased costs. |
| 343 | sorted := slices.Clone(tools) |
| 344 | slices.SortFunc(sorted, func(a, b *mcp.Tool) int { |
| 345 | return strings.Compare(a.ID, b.ID) |
| 346 | }) |
| 347 | for i, tool := range tools { |
| 348 | require.Equal(t, tool.ID, sorted[i].ID, "tool order is not stable") |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | func createMockMCPSrv(t *testing.T) http.Handler { |
| 353 | t.Helper() |