{"record":{"id":"fff0c975b73d0abd","repo":"Significant-Gravitas/AutoGPT","slug":"failed-to-store-token","errorCode":null,"errorMessage":"Failed to store token","messagePattern":"Failed to store token","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunMCPTool/components/MCPSetupCard/MCPSetupCard.tsx","lineNumber":244,"sourceCode":"    }\n  }\n\n  async function handleManualToken() {\n    // Re-entrancy guard first — mirrors ``handleConnect`` so both flows\n    // present the same shape to readers.  See the comment on\n    // ``handleConnect``'s guard for the double-click race this prevents.\n    if (loading) return;\n    const token = manualToken.trim();\n    if (!token) return;\n    setLoading(true);\n    setError(null);\n    try {\n      const res = await postV2StoreABearerTokenForAnMcpServer({\n        server_url: serverUrl,\n        token,\n      });\n      if (!(res.status >= 200 && res.status < 300))\n        throw new Error(\"Failed to store token\");\n      // Only clear the force-disconnect override AFTER the API confirms\n      // the token was stored.  Clearing it before the await would let\n      // ``liveHasCred=true`` (from an existing stale cred) re-render the\n      // Connected pill while the request is still in flight, briefly\n      // showing a false \"Connected\" state to the user.\n      setForceDisconnected(false);\n      setConnected(true);\n      onSend(retryInstruction ?? \"I've connected. Please retry.\");\n    } catch (e: unknown) {\n      // Keep the force-disconnect override on so the not-connected\n      // branch (error banner + manual-token input) stays visible — an\n      // existing ``liveHasCred=true`` would otherwise re-render the\n      // Connected pill.\n      setForceDisconnected(true);\n      const err = e as Record<string, unknown>;\n      setError(\n        (typeof err?.message === \"string\" ? err.message : null) ||\n          \"Failed to save token. Please try again.\",","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunMCPTool/components/MCPSetupCard/MCPSetupCard.tsx#L226-L262","documentation":"Error \"Failed to store token\" thrown in Significant-Gravitas/AutoGPT.","triggerScenarios":"Thrown at autogpt_platform/frontend/src/app/(platform)/copilot/tools/RunMCPTool/components/MCPSetupCard/MCPSetupCard.tsx:244 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the backend token storage endpoint is reachable and the user session is valid.","Check browser storage/cookie permissions and retry the MCP setup flow.","Inspect backend logs for the underlying storage failure."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}