use serde_json::{json, Value};
use super::tools::McpContext;
use super::types::{codes, JsonRpcError};
const LOG_LEVELS: &[&str] = &[
"debug",
"info",
"notice",
"warning",
"error",
"critical",
"alert",
"emergency",
];
const COMPLETION_CAP: usize = 100;
pub fn set_log_level(params: Value) -> Result<Value, JsonRpcError> {
let level = params.get("level").and_then(Value::as_str).ok_or_else(|| {
JsonRpcError::invalid_params("logging/setLevel requires a string `level`")
})?;
if !LOG_LEVELS.contains(&level) {
return Err(JsonRpcError::invalid_params(format!(
"unknown log level `{level}` (expected one of {})",
LOG_LEVELS.join(", ")
)));
}
Ok(json!({}))
}
pub async fn complete(ctx: &McpContext, params: Value) -> Result<Value, JsonRpcError> {
let prefix = params
.get("argument")
.and_then(|a| a.get("value"))
.and_then(Value::as_str)
.unwrap_or("");
let mut candidates: Vec<String> = ctx.agent.skills.clone();
let resources = crate::tenancy::resources_for_skills_pool(&ctx.pool, &ctx.agent.skills)
.await
.map_err(|e| JsonRpcError::new(codes::INTERNAL_ERROR, e.to_string()))?;
candidates.extend(resources.into_iter().map(|r| r.resource_uri));
let mut values: Vec<String> = candidates
.into_iter()
.filter(|c| c.starts_with(prefix))
.collect();
values.sort();
values.dedup();
let total = values.len();
let has_more = total > COMPLETION_CAP;
values.truncate(COMPLETION_CAP);
Ok(json!({
"completion": { "values": values, "total": total, "hasMore": has_more }
}))
}