fix(server): safely drop detached tokio join handles and refactor timestamp boilerplate
This commit is contained in:
1 parent
13c7eca4c2
commit
478655698e
15 files changed
+457
-312
No files matched your search
@@ -4,7 +4,6 @@ use crate::tools::*;
|
||||
use async_trait::async_trait;
|
||||
use serde_json::Value;
|
||||
use std::sync::Arc;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
pub struct UpdateEnvFingerprintHandler;
|
||||
|
||||
@@ -32,10 +31,7 @@ impl McpTool for UpdateEnvFingerprintHandler {
|
||||
os: std::env::consts::OS.to_string(),
|
||||
shell: std::env::var("SHELL").unwrap_or_else(|_| "unknown".to_string()),
|
||||
tool_versions: req.tool_versions,
|
||||
updated_at: SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs(),
|
||||
updated_at: crate::handlers_v2::utils::now_secs(),
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -61,9 +57,9 @@ impl McpTool for ReadEnvFingerprintHandler {
|
||||
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> Result<String, String> {
|
||||
let req: ReadEnvFingerprintTool =
|
||||
serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
let data = state.env_fingerprints.read_with(|fps| {
|
||||
fps.get(&req.namespace).cloned()
|
||||
});
|
||||
let data = state
|
||||
.env_fingerprints
|
||||
.read_with(|fps| fps.get(&req.namespace).cloned());
|
||||
if let Some(fp) = data {
|
||||
let data = serde_json::to_string(&fp).unwrap_or_default();
|
||||
Ok(data.to_string())
|
||||
@@ -129,10 +125,7 @@ impl McpTool for RegisterEnvironmentHandler {
|
||||
url: req.url,
|
||||
description: req.description,
|
||||
requires_vpn: req.requires_vpn,
|
||||
updated_at: SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
.unwrap_or_default()
|
||||
.as_secs(),
|
||||
updated_at: crate::handlers_v2::utils::now_secs(),
|
||||
});
|
||||
});
|
||||
Ok("Environment registered".to_string())
|
||||
@@ -158,12 +151,12 @@ impl McpTool for GetEnvironmentDetailsHandler {
|
||||
let req: GetEnvironmentDetailsTool =
|
||||
serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
let data = state.environments.read_with(|envs| {
|
||||
let filtered: Vec<_> = envs.iter().filter(|e| e.namespace == req.namespace).collect();
|
||||
let filtered: Vec<_> = envs
|
||||
.iter()
|
||||
.filter(|e| e.namespace == req.namespace)
|
||||
.collect();
|
||||
serde_json::to_string(&filtered).unwrap_or_default()
|
||||
});
|
||||
Ok(data.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user