Repository navigation
Commit 464dea4
authored
fix(connect): resolve duplicate mcpproxy entries deterministically (#1769)
## Bug
`findEntryJSONBytes` and `findEntryTOMLBytes`
(`internal/connect/connect.go`) return the first entry in `range
serversMap` whose URL points at this instance. Go randomizes map
iteration, so when a client config holds two such entries the answer
changes from call to call.
That's a common shape: a legacy `?apikey=` entry under a custom key left
next to the current `mcpproxy` entry. `findEquivalentJSONServerName` was
already made deterministic for exactly this reason (Spec 091 FR-005).
The status lookup was not.
## Trigger
A Cursor `mcp.json` with these entries:
```json
{"mcpServers": {
"mcpproxy": {"url": "http://127.0.0.1:8080/mcp"},
"old-proxy": {"url": "http://127.0.0.1:8080/mcp?apikey=OLD"}
}}
```
With this config, `GetStatus` reports `server_name` as `mcpproxy` or
`old-proxy` depending on the call. `ClientSecret`, which the credential
reconciler uses, reads the credential from whichever entry won. So it
sometimes sees `OLD` and sometimes the current key.
## Fix
Both finders now scan in a fixed order through a small `entryScanOrder`
helper: the default `mcpproxy` key first, then the remaining names
sorted. The name-only fallback and the PointsHere preference are
unchanged.
## Verification
- `go test -count=1 -run TestFindEntry_TwoEntriesPointingHere
./internal/connect/` passes. The test covers both the JSON (cursor) and
TOML (codex) paths and runs 50 lookups each.
- With `connect.go` reverted (`git stash push
internal/connect/connect.go`), the same test fails: `cursor lookup 0:
got entry "old-proxy" (pointsHere=true), want "mcpproxy"`.
- `go test -count=1 ./internal/connect/` passes.
- `go vet ./internal/connect/` is clean.
- `gofmt -l internal/connect/` is clean.
Commands were run with `GOFLAGS=-mod=readonly CGO_ENABLED=0`.1 parent 3af8e25 commit 464dea4
2 files changed
Lines changed: 72 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1610 | 1610 | | |
1611 | 1611 | | |
1612 | 1612 | | |
1613 | | - | |
1614 | | - | |
| 1613 | + | |
| 1614 | + | |
1615 | 1615 | | |
1616 | 1616 | | |
1617 | 1617 | | |
| |||
1646 | 1646 | | |
1647 | 1647 | | |
1648 | 1648 | | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
1649 | 1668 | | |
1650 | 1669 | | |
1651 | 1670 | | |
| |||
1859 | 1878 | | |
1860 | 1879 | | |
1861 | 1880 | | |
1862 | | - | |
1863 | | - | |
| 1881 | + | |
| 1882 | + | |
1864 | 1883 | | |
1865 | 1884 | | |
1866 | 1885 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
0 commit comments