[Bug]: OAuth token exchange fails with 'Time.UnmarshalJSON: input is not a JSON string' when provider returns numeric expires_at
What happened?
When completing the OAuth 2.0 authorization code exchange against an OAuth provider whose token endpoint includes a numeric "expires_at" field (Unix epoch timestamp) or null in the token response alongside "expires_in", MCPProxy fails the token exchange with:
OAuth token exchange failed for <server>: failed to decode token response: Time.UnmarshalJSON: input is not a JSON string
Root cause
github.com/mark3labs/mcp-go(v1.0.0,client/transport/oauth.go:78-91) definestransport.Tokenwith:type Token struct { AccessToken string `json:"access_token"` TokenType string `json:"token_type"` RefreshToken string `json:"refresh_token,omitempty"` ExpiresIn int64 `json:"expires_in,omitempty"` Scope string `json:"scope,omitempty"` ExpiresAt time.Time `json:"expires_at,omitzero"` }- Both
ProcessAuthorizationResponse(oauth.go:1153-1161) andrefreshToken(oauth.go:311-319) calljson.Unmarshal(body, &tokenResp)directly intoTokenbefore overwritingExpiresAtfromExpiresIn:var tokenResp Token if err := json.Unmarshal(body, &tokenResp); err != nil { return fmt.Errorf("failed to decode token response: %w", err) } if tokenResp.ExpiresIn > 0 { tokenResp.ExpiresAt = time.Now().Add(time.Duration(tokenResp.ExpiresIn) * time.Second) } - RFC 6749 §5.1 specifies
expires_in(seconds), and several OAuth/OIDC servers (e.g. Better Auth OAuth2 endpoints) also include"expires_at"as a numeric Unix timestamp in the JSON response. Becausetime.Time.UnmarshalJSONrequires a quoted RFC 3339 string, decoding fails immediately withTime.UnmarshalJSON: input is not a JSON string.
Suggested fix
OAuthTransportWrapper.RoundTrip (internal/oauth/transport_wrapper.go) already intercepts w.matchesToken(req) responses to normalize HTTP 201 Created → 200 OK for mcp-go. Normalizing the JSON token response body there—by stripping "expires_at" when it is not an RFC 3339 string (and optionally deriving "expires_in" from a numeric "expires_at" if "expires_in" is missing)—would fix both initial token exchange and token refresh without waiting on an upstream mcp-go change.
Expected behavior
OAuth token exchange and token refresh succeed when the authorization server returns a valid OAuth 2.0 token response containing a numeric or non-RFC3339 "expires_at" field.
Steps to reproduce
- Configure an HTTP MCP upstream server in
mcpproxythat uses an OAuth 2.0 token endpoint returning a numeric"expires_at"field in its JSON token response (e.g.,{"access_token":"...","token_type":"Bearer","expires_in":3600,"expires_at":1794307530}). - Run
mcpproxy auth login --server=<server>(or trigger sign-in from the tray/Web UI) and complete the browser consent redirect. - Observe that the callback succeeds,
ProcessAuthorizationResponseexchanges the code, andjson.Unmarshalfails withfailed to decode token response: Time.UnmarshalJSON: input is not a JSON string.
MCPProxy version
v0.73.0 (personal) darwin/arm64
Operating system
macOS
Relevant logs
INFO | oauth.oauth-callback | ✅ OAuth callback parameters delivered to the waiting flow | {"server": "<redacted>", "bind_host": "127.0.0.1", "port": 62379, "path": "/oauth/callback"}
ERROR | core/connection_oauth.go:2030 | ❌ Failed to exchange authorization code | {"server": "<redacted>", "error": "failed to decode token response: Time.UnmarshalJSON: input is not a JSON string"}
WARN | oauth/config.go:388 | Recording OAuth failure on server status | {"server": "<redacted>", "error": "OAuth token exchange failed for <redacted>: failed to decode token response: Time.UnmarshalJSON: input is not a JSON string"}
Pre-submission checklist
- [x] I searched existing issues and did not find a duplicate
- [x] I ran
mcpproxy doctorand reviewed the output
Thanks for the precise report and root cause, @j0bro. Fix is up in #1880: the OAuth transport wrapper now normalizes token responses before mcp-go decodes them, dropping any expires_at that is not an RFC 3339 string (numeric epoch, null, all-digit strings) and deriving expires_in from a numeric epoch when the provider omits it. It covers both the code exchange and the refresh, since both go through the same client. It will land in the next release.