ibridge-server 1.0.0

MCP server, tool routers and error mapping.
Documentation
// SPDX-License-Identifier: Apache-2.0

//! Tool arguments and structured results.

use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

fn default_page_limit() -> u32 {
    25
}

/// Arguments for `mail_search`.
#[derive(Debug, Default, Deserialize, JsonSchema)]
pub struct SearchParams {
    /// Mailbox path. Omit to use `role` or the inbox.
    #[serde(default)]
    pub mailbox: Option<String>,
    /// Well-known role: inbox, sent, drafts, trash, junk, archive, notes.
    #[serde(default)]
    pub role: Option<String>,
    /// From header contains this text.
    #[serde(default)]
    pub from: Option<String>,
    /// To header contains this text.
    #[serde(default)]
    pub to: Option<String>,
    /// Subject contains this text.
    #[serde(default)]
    pub subject: Option<String>,
    /// Body or subject contains this text.
    #[serde(default)]
    pub text: Option<String>,
    /// Messages on or after this date.
    #[serde(default)]
    pub since: Option<String>,
    /// Messages before this date.
    #[serde(default)]
    pub before: Option<String>,
    /// When set, only unseen messages.
    #[serde(default)]
    pub unread: Option<bool>,
    /// When set, only flagged messages.
    #[serde(default)]
    pub flagged: Option<bool>,
    /// Page size. Omitted means 25. More than 100 is rejected.
    #[serde(default = "default_page_limit")]
    pub limit: u32,
    /// Cursor from the previous page.
    #[serde(default)]
    pub cursor: Option<String>,
}

/// Arguments for `mail_send` and `mail_create_draft`.
#[derive(Debug, Default, Deserialize, JsonSchema)]
pub struct SendParams {
    /// Recipients.
    pub to: Vec<String>,
    /// Subject.
    pub subject: String,
    /// Body as text.
    pub body: String,
    /// From address when it is not the signed-in Apple ID.
    #[serde(default)]
    pub from: Option<String>,
    /// Opaque id of the message this one replies to.
    #[serde(default)]
    pub reply_to_id: Option<String>,
}

/// Arguments for `mail_get_message`.
#[derive(Debug, Default, Deserialize, JsonSchema)]
pub struct GetMessageParams {
    /// Opaque message id.
    pub id: String,
    /// Unicode scalar offset into the body. Omitted means the start.
    #[serde(default)]
    pub offset: u64,
}

/// Arguments for `mail_get_attachment`.
#[derive(Debug, Default, Deserialize, JsonSchema)]
pub struct GetAttachmentParams {
    /// Opaque message id.
    pub id: String,
    /// Part identifier from `mail_get_message`.
    pub part: String,
    /// Unicode scalar offset into a text part. Omitted means the start.
    #[serde(default)]
    pub offset: u64,
}

/// Arguments for `mail_save_attachment`.
#[derive(Debug, Default, Deserialize, JsonSchema)]
pub struct SaveAttachmentParams {
    /// Opaque message id.
    pub id: String,
    /// Part identifier from `mail_get_message`.
    pub part: String,
}

/// Arguments for `mail_move`.
#[derive(Debug, Default, Deserialize, JsonSchema)]
pub struct MoveParams {
    /// Opaque message id.
    pub id: String,
    /// Mailbox path. Set this or `role`, not both.
    #[serde(default)]
    pub mailbox: Option<String>,
    /// Role: inbox, archive, trash, junk, sent, drafts, or notes.
    #[serde(default)]
    pub role: Option<String>,
}

/// Arguments for `mail_set_flags`.
#[derive(Debug, Default, Deserialize, JsonSchema)]
pub struct FlagParams {
    /// Opaque message id.
    pub id: String,
    /// Seen flag. Omit to leave it unchanged.
    #[serde(default)]
    pub seen: Option<bool>,
    /// Flagged flag. Omit to leave it unchanged.
    #[serde(default)]
    pub flagged: Option<bool>,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct MailboxOut {
    pub(crate) path: String,
    pub(crate) role: String,
    pub(crate) total: u32,
    pub(crate) unread: u32,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct MailboxListOut {
    pub(crate) mailboxes: Vec<MailboxOut>,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct SearchHitOut {
    pub(crate) id: String,
    pub(crate) from: String,
    pub(crate) subject: String,
    pub(crate) date: String,
    pub(crate) unread: bool,
    pub(crate) flagged: bool,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct SearchOut {
    pub(crate) messages: Vec<SearchHitOut>,
    pub(crate) next_cursor: Option<String>,
    pub(crate) warnings: u32,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct AttachmentInfoOut {
    pub(crate) part: String,
    pub(crate) content_type: String,
    pub(crate) size: u64,
    pub(crate) name: String,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct MessageOut {
    pub(crate) id: String,
    pub(crate) from: String,
    pub(crate) to: Vec<String>,
    pub(crate) subject: String,
    pub(crate) date: String,
    pub(crate) body: String,
    pub(crate) attachments: Vec<AttachmentInfoOut>,
    pub(crate) next_offset: Option<u64>,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct AttachmentOut {
    pub(crate) content_type: String,
    pub(crate) name: String,
    pub(crate) size: u64,
    pub(crate) text: Option<String>,
    pub(crate) bytes_base64: Option<String>,
    pub(crate) next_offset: Option<u64>,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct SavedAttachmentOut {
    pub(crate) path: String,
    pub(crate) size: u64,
    pub(crate) content_type: String,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct IdOut {
    pub(crate) id: String,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct SendOut {
    pub(crate) id: Option<String>,
    pub(crate) warning: Option<String>,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct MoveOut {
    pub(crate) moved: bool,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct FlagsOut {
    pub(crate) updated: bool,
}

#[derive(Debug, Clone, Copy, Serialize, JsonSchema)]
#[serde(rename_all = "lowercase")]
pub(crate) enum ServiceState {
    On,
    Off,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct ServiceOut {
    pub(crate) name: String,
    pub(crate) status: ServiceState,
    pub(crate) reason: Option<String>,
}

#[derive(Debug, Serialize, JsonSchema)]
pub(crate) struct AccountStatusOut {
    pub(crate) apple_id: String,
    pub(crate) services: Vec<ServiceOut>,
    pub(crate) version: &'static str,
}