Bugfix: Why does the VSCode extension auth flow fail with 'Failed to...
Documentation for Sessions
🐛 Bugfix: Why does the VSCode extension auth flow fail with 'Failed to...
Date: 2026-02-28
Time: 20:41:34 UTC
Session: gspace1-155.3
Agent: angular
Confidence: 95%
Status: ✅ Documented
📋 Decision Context
Question:
Why does the VSCode extension auth flow fail with 'Failed to execute json on Response: Unexpected end of JSON input' after clicking Authorize Access?
Task: Fix VSCode extension auth flow JSON parsing error
🎯 Decision Made
Chosen:
Two fixes in McpAuthComponent.authorize(): (1) Added resolveBackendApiUrl() that returns absolute URL 'https://api.gograb.space/api' when page is on production (app.gograb.space), or relative '/api' for local dev (Angular proxy). (2) Changed response parsing from unconditional response.json() to response.text() + JSON.parse() with proper error handling showing a helpful message.
Options Considered:
- Use relative URL with proxy only
- Pass backend URL from extension via query param
- Detect environment in component and resolve absolute URL
- Import Angular environment config
💭 Reasoning
ROOT CAUSE: fetch('/api/auth/mcp/callback') used a relative URL. This only works in local dev where the Angular dev proxy forwards /api/* to localhost:3000. When the VSCode extension's resolveFrontendUrl() falls back to 'https://app.gograb.space' (which happens when no local frontend is detected on ports 5200/6200), the relative /api/... URL hits the Angular SPA's own origin (app.gograb.space), not the backend (api.gograb.space). The SPA returns index.html (HTML, not JSON), and response.json() throws 'Unexpected end of JSON input'. Secondary fix: parsing response as text first then JSON.parse() gives a meaningful error message instead of a cryptic one.
📁 Files Involved
apps/gograb-space/src/app/auth/mcp-auth/mcp-auth.component.ts
🔗 Related
- Decision ID:
dev_1772311294800_ps3o4np - Session: 155
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation