fix(cli): login over HTTPS + suggest last-used email #78

Merged
michal merged 1 commits from fix/login-https-and-email-suggest into main 2026-07-17 20:07:01 +00:00
Owner

Fixes mcpctl login crashing with "JSON Parse error: Unexpected EOF" when mcpdUrl uses https.

Root cause

auth.ts used node:http unconditionally with port: url.port. An https:// mcpdUrl (no explicit port) connected to the ingress on :80, got a 301 redirect with an empty body (status < 400 so the error guard passed), then JSON.parse('') threw. api-client.ts (used by get servers) already picked https/443 correctly — only the auth commands had the bug.

Changes

  • All 4 auth request fns pick https/443 + the TLS driver from the URL protocol, mirroring api-client.ts.
  • parseJsonResponse() guard: non-JSON <400 body -> clear "Invalid response from mcpd" error instead of a raw SyntaxError.
  • login suggests the previously-used email (same mcpd) so Enter reuses it after a session expires.

Tests

  • New real-HTTP regression tests drive the actual default* request fns: valid JSON, empty body, HTML redirect body, https driver selection.
  • Email-suggestion behaviour covered (same-mcpd suggests, different-mcpd does not).
  • Full CLI suite: 508 passed. Verified live: installed RPM gets past the status check and prompts for credentials.

🤖 Generated with Claude Code

Fixes `mcpctl login` crashing with "JSON Parse error: Unexpected EOF" when mcpdUrl uses https. ## Root cause `auth.ts` used `node:http` unconditionally with `port: url.port`. An `https://` mcpdUrl (no explicit port) connected to the ingress on :80, got a 301 redirect with an empty body (status < 400 so the error guard passed), then `JSON.parse('')` threw. `api-client.ts` (used by `get servers`) already picked https/443 correctly — only the auth commands had the bug. ## Changes - All 4 auth request fns pick https/443 + the TLS driver from the URL protocol, mirroring `api-client.ts`. - `parseJsonResponse()` guard: non-JSON <400 body -> clear "Invalid <ctx> response from mcpd" error instead of a raw SyntaxError. - `login` suggests the previously-used email (same mcpd) so Enter reuses it after a session expires. ## Tests - New real-HTTP regression tests drive the actual `default*` request fns: valid JSON, empty body, HTML redirect body, https driver selection. - Email-suggestion behaviour covered (same-mcpd suggests, different-mcpd does not). - Full CLI suite: 508 passed. Verified live: installed RPM gets past the status check and prompts for credentials. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
michal added 1 commit 2026-07-17 20:06:50 +00:00
fix(cli): login over HTTPS + suggest last-used email
Some checks failed
CI/CD / typecheck (pull_request) Successful in 1m19s
CI/CD / lint (pull_request) Successful in 2m13s
CI/CD / test (pull_request) Successful in 1m18s
CI/CD / smoke (pull_request) Failing after 2m35s
CI/CD / build (pull_request) Successful in 2m25s
CI/CD / publish (pull_request) Has been skipped
6ef16f12b6
auth.ts talked to mcpd over node:http unconditionally with port:url.port,
so an https:// mcpdUrl connected to the ingress on :80, got a 301 redirect
with an empty body (status < 400), and JSON.parse('') crashed login with
"Unexpected end of JSON input". api-client.ts already handled this; the auth
commands did not.

- All 4 auth request fns now pick https/443 and the TLS driver from the URL
  protocol, mirroring api-client.ts.
- parseJsonResponse() guard turns any non-JSON <400 body into a clear
  "Invalid <ctx> response from mcpd" error instead of a raw SyntaxError.
- login now suggests the previously-used email (when a session for the same
  mcpd exists) so pressing Enter reuses it after a session expires.
- Regression tests drive the real default* request fns against a local
  HTTP server (valid JSON, empty body, HTML redirect body, https driver
  selection) and cover the email-suggestion behaviour.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
michal merged commit e2db8d9003 into main 2026-07-17 20:07:01 +00:00
michal deleted branch fix/login-https-and-email-suggest 2026-07-17 20:07:01 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: michal/mcpctl#78