Skip to content

Clarify auth requirement for /internal API tools#13

Open
harkin wants to merge 1 commit intomainfrom
hl/auth-error-clarity
Open

Clarify auth requirement for /internal API tools#13
harkin wants to merge 1 commit intomainfrom
hl/auth-error-clarity

Conversation

@harkin
Copy link
Copy Markdown
Member

@harkin harkin commented Apr 30, 2026

Why?

get_infrastructure and get_metrics hit the /internal API surface, which only accepts OAuth2 tokens. Service tokens silently 404 against /internal (not 401), so service-token-only callers see a generic "Not found" error with no actionable signal — masking the real problem (the user needs to authenticate with pscale auth login).

Separately, the get_infrastructure tool description previously implied it returns more than it does. Downstream consumers built rubrics on the assumption that storage utilization and per-tablet compute usage were in the response, when in fact only topology and SKU information are returned.

How?

A new authCannotAccessInternalApi() helper in lib/auth.ts lets /internal tools detect when a service token is being used and return a clear OAuth-required message instead of a bare 404. Tool descriptions for get_infrastructure and get_metrics now document the OAuth requirement, and get_infrastructure is explicit about what it does not return. .env.example rewritten to document both auth modes.

Generated with Claude Code

`get_infrastructure` and `get_metrics` hit the /internal API surface, which
only accepts OAuth2 tokens. Service tokens get 404 (not 401) for the entire
/internal surface, so a service-token user calling these tools sees a bare
"Not found" error with no actionable signal — masking the real problem
(needs `pscale auth login`).

This commit:

- Adds `authCannotAccessInternalApi()` and a standard message in `auth.ts`
  so any tool can detect and explain the service-token-on-/internal case
- Wires the helper into `get_infrastructure` and `get_metrics` 404 handlers
  to return the OAuth-required message instead of a generic 404
- Updates the descriptions of both tools to document the OAuth requirement
- Strengthens `get_infrastructure`'s description to be explicit that it does
  NOT return storage utilization, CPU/memory utilization, or query metrics
  (caller skill documentation downstream had been claiming it does)
- Rewrites `.env.example` to document both auth methods and which tools
  need OAuth vs. work with service token

No behavior change for OAuth-authenticated callers. Service-token callers
of `get_infrastructure` / `get_metrics` now get a clear pointer to the fix
instead of a misleading 404.
@harkin harkin self-assigned this Apr 30, 2026
@lorcan
Copy link
Copy Markdown
Member

lorcan commented Apr 30, 2026

We might be able to retire the get_infrastructure tool in favor of a v1 api that's better in most ways: #14

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.

2 participants