From ebfbcad68516ee1cd667f8f1c77773c1a298f843 Mon Sep 17 00:00:00 2001 From: syui Date: Tue, 24 Mar 2026 20:54:02 +0900 Subject: [PATCH] fix mcp token file --- src/commands/token.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/commands/token.rs b/src/commands/token.rs index 6e69b61..881619b 100644 --- a/src/commands/token.rs +++ b/src/commands/token.rs @@ -60,6 +60,21 @@ pub fn load_session() -> Result { } } } + // Fallback: config.json (DID only, no auth tokens — for MCP tools that only need DID) + let config_path = path.with_file_name("config.json"); + if let Ok(content) = fs::read_to_string(&config_path) { + if let Ok(config) = serde_json::from_str::(&content) { + if let (Some(did), Some(handle)) = (config["did"].as_str(), config["handle"].as_str()) { + return Ok(Session { + did: did.to_string(), + handle: handle.to_string(), + access_jwt: String::new(), + refresh_jwt: String::new(), + pds: config["network"].as_str().map(|s| format!("https://{s}")), + }); + } + } + } Err(anyhow::anyhow!("Token file not found: {:?}. Run 'ailog login' or 'ailog oauth' first.", path)) } @@ -94,6 +109,22 @@ pub fn load_bot_session() -> Result { } } } + // Fallback: config.json bot section (DID only) + let config_path = path.with_file_name("config.json"); + if let Ok(content) = fs::read_to_string(&config_path) { + if let Ok(config) = serde_json::from_str::(&content) { + let bot = &config["bot"]; + if let (Some(did), Some(handle)) = (bot["did"].as_str(), bot["handle"].as_str()) { + return Ok(Session { + did: did.to_string(), + handle: handle.to_string(), + access_jwt: String::new(), + refresh_jwt: String::new(), + pds: config["network"].as_str().map(|s| format!("https://{s}")), + }); + } + } + } Err(anyhow::anyhow!("Bot token file not found: {:?}. Run 'ailog login --bot' or 'ailog oauth --bot' first.", path)) }