Skip to content

Consolidate the three GET /api/config hooks into one useInitialConfig #1643

Description

@cliffhall

Summary

The web app currently makes three independent GET /api/config fetches on load — useSandboxUrl, useServerListWritable, and useInspectorVersion (added in #1641) each fetch the same static payload and read one field from it. Consolidate them into a single useInitialConfig hook that fetches once and exposes version / sandboxUrl / writable (+ loading).

Background

GET /api/config returns one InitialConfigPayload (core/mcp/remote/node/server.ts) with sandboxUrl, writable, version, and the default-transport fields. Three hooks (core/react/useSandboxUrl.ts, useServerListWritable.ts, useInspectorVersion.ts) each fetch it separately and extract one field. They're intentionally near-identical (each documents that it mirrors the others), so this is an established-pattern cleanup, not a regression — but it's 3 requests for one static payload.

Scope

  • Add core/react/useInitialConfig.ts: fetch GET /api/config once, expose { version, sandboxUrl, writable, loading } with the same tolerant parsing/defaults the three hooks use today (writable defaults true; sandboxUrl/version undefined when absent; unmount-safe).
  • Update App.tsx to use it instead of the three separate hooks.
  • Deprecate/remove useSandboxUrl / useServerListWritable / useInspectorVersion (or reimplement them as thin selectors over the shared hook) once nothing else uses them.
  • Keep full test coverage (the fetch-branch matrix the three hooks currently cover).

Acceptance

  • One GET /api/config fetch on load (verify in the network panel / a test).
  • version / sandboxUrl / writable behave exactly as before, including legacy-backend tolerance.
  • Per-file ≥90 coverage maintained.

Follow-up raised in review of #1641.

Metadata

Metadata

Assignees

Labels

v2Issues and PRs for v2

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions