Skip to content

fix(httpapi): hold profile-pinned agent tokens to their pin on GET /api/v1/servers - #1684

Merged
Dumbris merged 1 commit into
smart-mcp-proxy:mainfrom
james-crowley:fix/profile-token-rest-server-scope
Oct 20, 2026
Merged

Dumbris merged 1 commit into
smart-mcp-proxy:mainfrom
james-crowley:fix/profile-token-rest-server-scope

Conversation

@james-crowley

Copy link
Copy Markdown
Contributor

Description

Fixes #1682.

A token created with --profile takes its scope from the profile, so its AllowedServers is usually "*". The #1166 gate (visibleServers -> CanEnumerateServer) only consults AllowedServers, so a bare GET /api/v1/servers listed every configured server to a profile-pinned token, while /tools, preflight and the MCP surface were already held to the pin.

This applies the caller's own pin to a bare GET /servers (no ?profile=): it is now equivalent to GET /servers?profile=<the caller's own pin>. Rows outside the pin disappear, tool_count counts only tools the pin admits, and stats narrow with the list (no count oracle). Admins, the tray socket and legacy --servers tokens are unchanged, since callerHasProfilePin is false for them.

The change is limitServersToCallerPin in view_as.go (reusing limitServersToProfile with a pass-through evaluator) and one call in each of the two branches of handleGetServers (management service and legacy fallback).

Scope note: I only changed /api/v1/servers. Other REST reads gate on canSeeServer (AllowedServers), so a pinned token may still see out-of-pin servers there (for example per-server subtree routes). I left those alone because the scope comments in scope_subtree.go describe the pin as ergonomics rather than the boundary, and that looks like a maintainer decision. Happy to follow up if you want the pin applied to canSeeServer itself.

Testing

  • I have tested these changes locally
  • I have added/updated tests that prove my fix is effective or my feature works
  • All existing tests pass

Verification:

  • go test ./internal/httpapi/ ./internal/auth/ passes.
  • New TestServersBareListHeldToCallerPin runs both handleGetServers branches and fails on main ({"filesystem":1,"github":2,"notion":2} instead of {"github":1}).
  • End to end with a built binary (2 stdio servers a, b; profile prof = a): admin lists ["a","b"], the --profile prof token lists ["a"], and a legacy --servers a token lists ["a"]. On v0.71.1 the profile token listed both.

A token created with --profile takes its scope from the profile, so its AllowedServers is usually "*" and the smart-mcp-proxy#1166 filter (visibleServers) listed every configured server to it, while /tools, preflight and the MCP surface were already limited to the pin.

Apply the caller's own pin to a bare GET /servers, the same way GET /servers?profile=<own pin> does: rows outside the pin disappear, tool_count counts only tools the pin admits, and stats narrow with the list. Admins and legacy-scoped tokens are unchanged.

Fixes smart-mcp-proxy#1682
@Dumbris

Dumbris commented Oct 20, 2026

Copy link
Copy Markdown
Member

Thanks a lot, @james-crowley! This is a clean, well-scoped fix. Reusing limitServersToProfile means a bare GET /servers now matches ?profile=<own pin> and /tools row for row, including the stats. The test covers both handleGetServers branches and fails on main exactly as you described.

Your scope note was right, too. Other read paths (/status, /events, /review, /attention, /profiles, /annotations/coverage) still gate only on AllowedServers, and the doc comment in scope_subtree.go treats the pin as ergonomics. Before anyone patches more endpoints, we need to decide whether the pin is a real visibility boundary, so I opened #1686 to track that decision and the shared-predicate fix. If you want to pick it up, you're very welcome. Merging this now 🙏

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Dumbris
Dumbris merged commit d25e92b into smart-mcp-proxy:main Oct 20, 2026
42 of 46 checks passed
Dumbris added a commit that referenced this pull request Nov 3, 2026
…redicate (Spec 118) (#1821)

## Description

Related #1686 (Spec 118, `specs/118-pin-visibility-boundary/spec.md`,
maintainer decision Option A).

A token minted with `--profile <p>` takes its grant from the profile, so
its stored `allowed_servers` is normally `"*"`. The REST surface's
shared enumeration predicate (`auth.CanEnumerateServer` → `canSeeServer`
/ `visibleServers`) consulted only that grant, so the same token that
`GET /servers` (#1684) and `GET /tools` (#1437) held to its pin could
still learn every out-of-pin server's name, state and counts from `GET
/status`, the `/events` stream, `GET /review`, `GET /attention`, `GET
/profiles` and `GET /annotations/coverage`, and diff the counts across
doors to learn how many servers were hidden.

### What changes

- **One seam, one set.** `auth.AuthContext.BoundToPinReach(reach)`
returns a copy of the context whose `AllowedServers` is grant ∩ reach
(the pinned profile's `EffectiveServers` under the live config).
`bindCallerToPin` (`internal/httpapi/pin_boundary.go`) applies it at the
two places that mint an agent token's context: `handleAgentTokenAuth`
(every REST request) and `newSSECallerContextRefresher` (before every
identity-bearing SSE frame). From there every read door, every
recomputed count, `scopeAllowedServers` (activity / tool-call filters
and the usage cache key), preflight's `TokenServers` and
`management.Doctor` read the resolved set. No per-door pin filters were
added; `limitServersToCallerPin` (#1684) stays for its `tool_count`
narrowing and now admits exactly the predicate's set.
- **Fail closed (FR-002).** A pin naming a deleted or empty profile, one
whose servers are unconfigured, or one with no overlap with the grant
binds to an empty **non-nil** set, so every door answers the same shape
as a token granted `[]` (lists empty, counts zero, subtree 404s). The
reach is resolved per request and per frame, never cached (FR-003).
- **Profile doors (FR-009, FR-012).** A pinned caller may learn only its
own pin: `profileReachable` refuses every other name on the same path as
an unknown one, so `/profiles` lists one profile (narrowed,
`switchable_to` cleared), and `/profiles/{name}`,
`/profiles/{name}/effective-tools`, `?profile=` on `/servers` and
`/tools` answer the non-disclosing 404 for anything else. `GET
/profiles/active` now withholds the slug from **every**
non-administrator unless the profile is selectable by that caller — the
one deliberate compatibility change (FR-004): an unpinned `--servers`
token reads `""` for an active profile disjoint from its grant, where it
used to read the slug.
- **SSE (FR-007).** `serversChangedDeliverable` drops a
`servers.changed` frame only when every identity extra names a hidden
server and the narrowed embed is empty or absent (the notify-only path,
where the extra was the whole payload). Frames with a visible row, a
visible identity or no identity still arrive with hidden extras
withheld. The snapshot residual (a change to a hidden server alone while
visible rows exist) is documented, not suppressed.
- **Docs.** `scope_subtree.go` header rewritten (FR-016): the pin is
part of the boundary; the two ergonomic filters are named.
`docs/features/agent-tokens.md` "Server Scoping" + "Profile Pinning",
`docs/api/rest-api.md` events table, three swagger descriptions (`oas/`
regenerated).

### Scope note

Left for follow-ups, per spec: the MCP↔REST parity test (FR-013) and the
CLI test with a pinned token (FR-015). Both surfaces already read the
same set (MCP applies the pin as its first resolver tier; the CLI reads
REST), so neither needs a code change here.

## Testing

- [x] `internal/httpapi/pin_boundary_test.go` drives the production
route table with a `*`-scoped token pinned to `work-readonly=[github]`
over a `github/notion/filesystem` fleet (notion quarantined): `/status`
(map keys + every scalar), `/annotations/coverage`, `/review`,
`/attention`, `/profiles` (+ `{name}`, `/effective-tools`, `/active` for
pinned, legacy and admin), `?profile=` on `/servers` and `/tools`, the
`/servers/{id}` subtree, the grant-as-filter seam through the real
middleware, `/diagnostics`, the live `/events` stream (dropped audit
event, dropped hidden-only `servers.changed`, narrowed coalesced frame),
a deleted pin and a non-overlapping pin compared field-by-field against
an empty-grant token, an empty pin, `serversChangedDeliverable` in
isolation, the activity door through the production
`ActivityFilter.Matches`, usage-cache key isolation (pinned `*` vs
unpinned `*` vs deleted pin), hidden-server change counts withheld,
`active_profile.changed` rendering, live status frames and a mid-stream
pin deletion.
- [x] `internal/auth/pin_boundary_test.go`: the pure intersection
(star/listed grant, nil/empty reach, dedup, admin/unpinned/nil
pass-through, predicate wiring).
- [x] Pre-existing tests updated to the spec's rules:
`servers_profile_caller_pin_test.go` (`?profile=<wider>` is now 404 for
a pinned caller), `preflight_test.go` (fixture configures the pinned
profile), `sse_scope_reveal_test.go` (hidden-only notify frame dropped;
identity-less and visible ones delivered).
- [x] `go test -race ./internal/httpapi/ ./internal/auth/
./internal/management/ ./internal/profile/`
- [x] CI server-tag race set (`-tags server`, unit-tests.yml skip regex)
on `serveredition`, `httpapi`, `server`
- [x] `./scripts/test-api-e2e.sh` — 70/70
- [x] `golangci-lint` with `.github/.golangci.yml`, bare and
`--build-tags server`: only the pre-existing `TopK` baseline finding
- [x] Cross-model review: opencode `github-copilot/gpt-6.1-sol`, 3
rounds (round 1: 2 MUST-FIX + 4 SHOULD-FIX, all fixed; round 2: no
production defects; round 3: NIT only). Summary in the first PR comment.
Dumbris added a commit that referenced this pull request Nov 20, 2026
`roadmap.yaml` had no epics after Spec 117. This PR adds them and
regenerates `ROADMAP.md`.

- **Shipped:** 118 auto-rescan (#1689), 118 pin visibility boundary
(#1684, #1688, #1821), 119 (#1740), 120 (#1781), 122 (#1818) and 123
(#1886, #1887, #1888, #1891).
- **In review:** 121 install surfaces (#1711). There is no `spec:` link
yet because its folder exists only on the PR branch.
- **In progress:** 124 (PR-1 #1918 done; PR-2 CLI and PR-3 Web UI to do)
and 125 (spec plus PR-1..3 done; PR-4 Web UI to do). Merged PRs are
listed as done child tasks, so `--check-github` doesn't flag a merged PR
under an in-progress epic.
- **Spec-only PRs:** 127 (#1943), 128 (#1944) and 129 (#1945).

Merge this after #1943, #1944 and #1945. Until then, `--check-github`
reports their `spec:` links as unresolved; `--check`, the pre-commit
hook, passes.

Not covered: Spec 126 (#1940, open) and the unsynced tasks.md checkboxes
for 123 and 124.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: GET /api/v1/servers lists every server to a profile-pinned agent token (#1166 filter only covers legacy allowed_servers)

3 participants