use rust_mcp_schema::schema_utils::CallToolError;
use rust_mcp_schema::CallToolResult;
use rust_mcp_sdk::macros::{mcp_tool, JsonSchema};
use serde::{Deserialize, Serialize};
use crate::op::OpClient;
use crate::tools::enums::TokenExpiry;
use crate::tools::{json_result, op_error_to_tool_error, text_result};
#[mcp_tool(
name = "service_account_create",
description = "Create a new 1Password service account. Service accounts are used for automated access to vaults without user interaction. Returns a token that must be saved securely."
)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct ServiceAccountCreateTool {
pub name: String,
#[serde(default)]
pub vaults: Option<Vec<String>>,
#[serde(default)]
pub expires_in: Option<TokenExpiry>,
}
impl ServiceAccountCreateTool {
pub async fn call(&self, client: &OpClient) -> Result<CallToolResult, CallToolError> {
let vaults_refs: Option<Vec<&str>> = self
.vaults
.as_ref()
.map(|v| v.iter().map(|s| s.as_str()).collect());
let expires_in_str = self.expires_in.as_ref().map(|e| e.to_string());
let result = client
.service_account_create(&self.name, vaults_refs.as_deref(), expires_in_str.as_deref())
.await
.map_err(op_error_to_tool_error)?;
text_result(result)
}
}
#[mcp_tool(
name = "service_account_ratelimit",
description = "Check the current rate limit status and usage for a service account. Shows requests made, limit, and reset time."
)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct ServiceAccountRatelimitTool {}
impl ServiceAccountRatelimitTool {
pub async fn call(&self, client: &OpClient) -> Result<CallToolResult, CallToolError> {
let result = client
.service_account_ratelimit()
.await
.map_err(op_error_to_tool_error)?;
json_result(&result)
}
}