warder 0.1.0

A policy gate for MCP tool calls - blocks destructive AI agent actions before they run
Documentation
//! Shim configuration.
//!
//! Read from a file next to the client's MCP config, or from `AGENTSENTRY_CONFIG`.
//! Deliberately small: anything that needs to change at runtime belongs in the signed
//! policy bundle, not here.

use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Config {
    /// Logical name of the upstream MCP server, used in policy resource UIDs.
    pub server: String,
    /// The real MCP server the shim launches as a child process.
    pub command: String,
    #[serde(default)]
    pub args: Vec<String>,
    /// Identity of the calling agent. In production this is resolved from the brokered
    /// credential rather than configured, so it cannot be self-asserted.
    #[serde(default = "default_agent")]
    pub agent_id: String,
    /// Path to the compiled, signed policy bundle.
    pub policy_path: String,
    /// Path to the persisted tool-description pin store.
    #[serde(default = "default_pins")]
    pub pin_path: String,
    /// Deny when the policy engine cannot evaluate. Defaults to false for the local
    /// shim: a shim bug must never break a developer's session. Server-side sidecar
    /// deployments set this to true.
    #[serde(default)]
    pub fail_closed: bool,
    /// Per-tenant opt-in for full payload capture. Off by default, and off is the
    /// correct default — see audit.rs.
    #[serde(default)]
    pub capture_raw_arguments: bool,
    #[serde(default = "default_buffer")]
    pub audit_buffer: usize,
}

fn default_agent() -> String {
    "local-agent".into()
}
fn default_pins() -> String {
    ".warder/pins.json".into()
}
fn default_buffer() -> usize {
    4096
}

impl Config {
    /// Deliberately not `FromStr`: that trait's error type would have to be
    /// `anyhow::Error`, and a config parse failure deserves the file path in the
    /// message, which the trait signature cannot carry.
    pub fn from_json(s: &str) -> anyhow::Result<Self> {
        Ok(serde_json::from_str(s)?)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn minimal_config_parses_with_safe_defaults() {
        let c = Config::from_json(
            r#"{"server":"postgres","command":"mcp-server-postgres","policy_path":"p.cedar"}"#,
        )
        .unwrap();
        assert_eq!(c.server, "postgres");
        assert!(c.args.is_empty());
        assert_eq!(c.agent_id, "local-agent");
        assert!(!c.capture_raw_arguments, "raw capture must default to off");
        assert!(!c.fail_closed, "local shim must default to fail-open");
        assert_eq!(c.audit_buffer, 4096);
    }

    #[test]
    fn rejects_config_missing_required_fields() {
        assert!(Config::from_json(r#"{"server":"postgres"}"#).is_err());
    }
}