Repository navigation
Commit e5da24c
fix(server): sort default toolset alphabetically for stable ordering (#3539)
## Summary
This PR resolves issue #3463 by sorting the tools in the default toolset
alphabetically during server initialization.
Currently, the default toolset (`cfg.ToolsetConfigs[""]`) is populated
by iterating over the `toolsMap`. Because map iteration order in Go is
randomized, tools were being returned in an arbitrary order across
server restarts. This broke client-side optimizations like Anthropic
Prompt Caching that rely on a stable tool order.
By sorting `allToolNames` with `slices.Sort()` prior to populating the
default toolset, we guarantee stable alphabetical ordering while leaving
custom toolsets (which are manually ordered in user configs) untouched.
## Testing
- Added unit test `TestDefaultToolsetIsAlphabeticallySorted` in
`internal/server/server_test.go` to explicitly verify that out-of-order
tools get sorted correctly in the default toolset.
- Verified that all existing server unit tests pass.
Fixes #3463
---------
Co-authored-by: Yuan Teoh <45984206+Yuan325@users.noreply.github.com>1 parent 7292613 commit e5da24c
2 files changed
Lines changed: 37 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
335 | 335 | | |
336 | 336 | | |
337 | 337 | | |
| 338 | + | |
338 | 339 | | |
339 | 340 | | |
340 | 341 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1449 | 1449 | | |
1450 | 1450 | | |
1451 | 1451 | | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
0 commit comments