2
0

fix mcp token file

This commit is contained in:
2026-03-24 20:54:02 +09:00
parent 72a3d34395
commit ebfbcad685

View File

@@ -60,6 +60,21 @@ pub fn load_session() -> Result<Session> {
}
}
}
// 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::<serde_json::Value>(&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<Session> {
}
}
}
// 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::<serde_json::Value>(&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))
}