{"record":{"id":"9dc6cb9cb020c3d4","repo":"Kuberwastaken/claurst","slug":"failed-to-store-mcp-token-for","errorCode":null,"errorMessage":"Failed to store MCP token for '{}': {}","messagePattern":"Failed to store MCP token for '(.+?)': (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-rust/crates/mcp/src/lib.rs","lineNumber":1281,"sourceCode":"        token: &str,\r\n        expires_in: Option<u64>,\r\n    ) -> anyhow::Result<()> {\r\n        let expires_at = expires_in.map(|secs| {\r\n            std::time::SystemTime::now()\r\n                .duration_since(std::time::UNIX_EPOCH)\r\n                .unwrap_or_default()\r\n                .as_secs()\r\n                + secs\r\n        });\r\n        let mcp_token = oauth::McpToken {\r\n            access_token: token.to_string(),\r\n            refresh_token: None,\r\n            expires_at,\r\n            scope: None,\r\n            server_name: server_name.to_string(),\r\n        };\r\n        oauth::store_mcp_token(&mcp_token)\r\n            .map_err(|e| anyhow::anyhow!(\"Failed to store MCP token for '{}': {}\", server_name, e))\r\n    }\r\n\r\n    /// Load the stored OAuth access token for an MCP server, if any.\r\n    ///\r\n    /// Returns `None` if no token is stored or the token cannot be refreshed.\r\n    pub async fn load_token(&self, server_name: &str) -> Option<String> {\r\n        let config = self.server_configs.get(server_name)?;\r\n        let server_url = config.url.as_deref()?;\r\n        oauth::get_valid_mcp_access_token(server_name, server_url)\r\n            .await\r\n            .ok()\r\n            .flatten()\r\n    }\r\n\r\n    // -----------------------------------------------------------------------\r\n    // Notification dispatch loop\r\n    // -----------------------------------------------------------------------\r\n\r","sourceCodeStart":1263,"sourceCodeEnd":1299,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/mcp/src/lib.rs#L1263-L1299","documentation":"After a successful OAuth flow completes, the resulting token is persisted via oauth::store_mcp_token. If persistence fails (I/O error, storage backend unavailable), the original error is wrapped with this message naming the server. The token may still be valid in memory but was not saved, so it will not survive the session.","triggerScenarios":"run_mcp_auth_flow() finished the browser flow but store_mcp_token(&mcp_token) returned Err — disk full, auth-store file locked/unwritable, storage directory missing, or serialization failure.","commonSituations":"Home directory or config dir not writable (sandboxed process, read-only FS); concurrent runs of the auth flow corrupting/locking the token store; disk quota exceeded; corrupted auth store file forcing rewrite failure.","solutions":["Inspect the inner error text to see the underlying storage failure","Check that the token/config directory exists and is writable by the process","Re-run the auth flow once the storage issue is fixed — the token is not persisted","Free disk space / resolve file locks if the store could not be written"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"let dir = token_store_dir()?;\nlet probe = dir.join(\".write-probe\");\nstd::fs::write(&probe, b\"ok\").context(\"token store dir not writable\")?;\nlet _ = std::fs::remove_file(&probe);","typeGuard":null,"tryCatchPattern":"match oauth::store_mcp_token(&token) {\n    Ok(()) => {}\n    Err(e) => {\n        eprintln!(\"warning: token for {server} not persisted: {e}; re-auth next session\");\n    }\n}","preventionTips":["Ensure the config/token directory exists and is writable before starting auth","Avoid running multiple auth flows concurrently against the same store","Monitor free disk space on hosts running the auth flow","On failure, re-run authentication before relying on the token later"],"tags":["mcp","oauth","persistence","io"],"backgroundTag":"file-write-failed","analyzedSha":"b0637c97ec34144387cbf2f74f65df6d16a6cef1","analyzedAt":"2026-09-10T00:24:58.650Z","contentChangedAt":"2026-09-10T00:24:58.650Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}