Skip to content

fix(server): use canonical OAuth health in REST server list and diagnostics - #1622

Merged
Dumbris merged 1 commit into
smart-mcp-proxy:mainfrom
HaloCollar:upstream-pr/clear-stale-health
Oct 14, 2026
Merged

Dumbris merged 1 commit into
smart-mcp-proxy:mainfrom
HaloCollar:upstream-pr/clear-stale-health

Conversation

@electrolobzik

Copy link
Copy Markdown
Contributor

Problem

Server.GetAllServers sits behind GET /api/v1/servers/{id}/diagnostics, the REST server-list fallback and the other controller readers. It rebuilt each server's health from connection state only, without the OAuth token status or expiry.

As a result, a connected OAuth server with a valid stored token and listed tools was reported as "Authentication required" (sign_in_required, usable=false). For the same server, the runtime, the CLI and the MCP upstream_servers list (since #1525, issue #1522) all reported it as Ready.

Fix

  • Reuse the runtime's canonical health projection, the same way fix(server): use canonical OAuth health in MCP upstream list #1525 did for handleListUpstreams.
  • The runtime projection reads its own snapshot, so its health is used only when its admin state (enabled, quarantined) matches the row's own snapshot. A row therefore never mixes two admin states.
  • Otherwise, including when the runtime has no entry for the server yet, the existing connection-based calculation is used as the fallback.
  • How authentication is enforced does not change:
    • a missing or expired token still requires sign-in;
    • a valid token never makes a quarantined or disabled server usable.

Tests

New TestServerGetAllServersOAuthHealth in internal/server/server_oauth_health_test.go. It covers these cases:

  • valid token
  • token without expiry
  • expired token
  • missing token
  • quarantined server with a valid token
  • disabled server with a valid token

It asserts that the REST/diagnostics health equals the runtime health, and checks the expected status and usable flag.

  • On main: the "valid token" and "token without expiry" cases fail, reporting sign_in_required / usable=false. The "expired token" case fails with summary "Authentication required" instead of "Token expired".
  • With this change: all cases pass. The existing fix(server): use canonical OAuth health in MCP upstream list #1525 TestMCPUpstreamList* tests also still pass.

Other checks:

  • go build ./... and go build -tags server ./... pass.
  • go vet on ./internal/server/ and ./internal/httpapi/ passes, and gofmt is clean.
  • internal/httpapi and internal/health tests pass.

🤖 Generated with Claude Code

…ostics

Server.GetAllServers (the httpapi controller projection behind
GET /api/v1/servers/{id}/diagnostics, the REST list fallback and other
controller readers) rebuilt each server's health from connection state
only, without OAuth token status or expiry. A connected OAuth server with
a valid stored token and listed tools was therefore reported as
"Authentication required / sign_in_required / usable=false", while the
runtime, CLI and (since smart-mcp-proxy#1525) the MCP upstream_servers list reported it
Ready.

Reuse the runtime's canonical health projection, as smart-mcp-proxy#1525 did for
handleListUpstreams. The projection is adopted only when its admin state
(enabled, quarantined) matches the row's own snapshot, so one row never
mixes two admin states; otherwise, and when the runtime has no entry, the
connection-based calculation is kept as the fallback. Missing and expired
tokens still report sign-in required, and a valid token never makes a
quarantined or disabled server usable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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

❌ Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/server/server.go 81.81% 2 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@Dumbris
Dumbris merged commit b39867b into smart-mcp-proxy:main Oct 14, 2026
49 checks passed
@Dumbris

Dumbris commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thank you @electrolobzik — merged! 🎉

This fixes a real inconsistency: the REST list and /servers/{id}/diagnostics now report the same OAuth health as the runtime, CLI and MCP upstream_servers (finishing what #1525 started). I liked that the admin-state match guard keeps a valid token from making a quarantined or disabled server usable. The table test also fails on main and passes with the fix, which is exactly what we want.

One note from the cross-review, not blocking: the controller and runtime read two separate StateView snapshots. So for a moment during a reconnect or an endpoint change, a row could show health from a slightly newer state. It is display-only and fixes itself on the next poll. One shared projection would remove it fully, if you ever want to follow up.

Thanks again for the careful work!

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.

3 participants