op-mcp 0.1.0

MCP server providing LLM access to 1Password CLI
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
//! Shared enums for MCP tool parameters
//!
//! These enums provide LLM-friendly schemas by exposing valid values directly
//! in the JSON Schema, rather than relying on documentation strings.

use serde::{Deserialize, Serialize};
use std::fmt;

// ============================================================================
// ItemCategory - Categories for 1Password items
// ============================================================================

/// Item categories supported by 1Password.
///
/// When serialized, variants use SCREAMING_SNAKE_CASE (e.g., `Login` -> `"LOGIN"`).
/// The `Other` variant allows forward compatibility with unknown categories.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ItemCategory {
    Login,
    SecureNote,
    CreditCard,
    Identity,
    Password,
    Document,
    BankAccount,
    Database,
    DriverLicense,
    EmailAccount,
    Membership,
    OutdoorLicense,
    Passport,
    RewardProgram,
    Server,
    SocialSecurityNumber,
    SoftwareLicense,
    SshKey,
    WirelessRouter,
    ApiCredential,
    MedicalRecord,
    /// Fallback for unknown/future categories
    #[serde(untagged)]
    Other(String),
}

impl ItemCategory {
    /// Returns the JSON Schema for this enum type.
    pub fn json_schema() -> serde_json::Map<String, serde_json::Value> {
        let mut schema = serde_json::Map::new();
        schema.insert(
            "type".to_string(),
            serde_json::Value::String("string".to_string()),
        );
        schema.insert(
            "description".to_string(),
            serde_json::Value::String(
                "Item category. Use one of the known values, or any string for forward compatibility.".to_string(),
            ),
        );
        schema.insert(
            "enum".to_string(),
            serde_json::Value::Array(vec![
                serde_json::Value::String("LOGIN".to_string()),
                serde_json::Value::String("SECURE_NOTE".to_string()),
                serde_json::Value::String("CREDIT_CARD".to_string()),
                serde_json::Value::String("IDENTITY".to_string()),
                serde_json::Value::String("PASSWORD".to_string()),
                serde_json::Value::String("DOCUMENT".to_string()),
                serde_json::Value::String("BANK_ACCOUNT".to_string()),
                serde_json::Value::String("DATABASE".to_string()),
                serde_json::Value::String("DRIVER_LICENSE".to_string()),
                serde_json::Value::String("EMAIL_ACCOUNT".to_string()),
                serde_json::Value::String("MEMBERSHIP".to_string()),
                serde_json::Value::String("OUTDOOR_LICENSE".to_string()),
                serde_json::Value::String("PASSPORT".to_string()),
                serde_json::Value::String("REWARD_PROGRAM".to_string()),
                serde_json::Value::String("SERVER".to_string()),
                serde_json::Value::String("SOCIAL_SECURITY_NUMBER".to_string()),
                serde_json::Value::String("SOFTWARE_LICENSE".to_string()),
                serde_json::Value::String("SSH_KEY".to_string()),
                serde_json::Value::String("WIRELESS_ROUTER".to_string()),
                serde_json::Value::String("API_CREDENTIAL".to_string()),
                serde_json::Value::String("MEDICAL_RECORD".to_string()),
            ]),
        );
        schema
    }
}

impl fmt::Display for ItemCategory {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            ItemCategory::Login => write!(f, "LOGIN"),
            ItemCategory::SecureNote => write!(f, "SECURE_NOTE"),
            ItemCategory::CreditCard => write!(f, "CREDIT_CARD"),
            ItemCategory::Identity => write!(f, "IDENTITY"),
            ItemCategory::Password => write!(f, "PASSWORD"),
            ItemCategory::Document => write!(f, "DOCUMENT"),
            ItemCategory::BankAccount => write!(f, "BANK_ACCOUNT"),
            ItemCategory::Database => write!(f, "DATABASE"),
            ItemCategory::DriverLicense => write!(f, "DRIVER_LICENSE"),
            ItemCategory::EmailAccount => write!(f, "EMAIL_ACCOUNT"),
            ItemCategory::Membership => write!(f, "MEMBERSHIP"),
            ItemCategory::OutdoorLicense => write!(f, "OUTDOOR_LICENSE"),
            ItemCategory::Passport => write!(f, "PASSPORT"),
            ItemCategory::RewardProgram => write!(f, "REWARD_PROGRAM"),
            ItemCategory::Server => write!(f, "SERVER"),
            ItemCategory::SocialSecurityNumber => write!(f, "SOCIAL_SECURITY_NUMBER"),
            ItemCategory::SoftwareLicense => write!(f, "SOFTWARE_LICENSE"),
            ItemCategory::SshKey => write!(f, "SSH_KEY"),
            ItemCategory::WirelessRouter => write!(f, "WIRELESS_ROUTER"),
            ItemCategory::ApiCredential => write!(f, "API_CREDENTIAL"),
            ItemCategory::MedicalRecord => write!(f, "MEDICAL_RECORD"),
            ItemCategory::Other(s) => write!(f, "{}", s),
        }
    }
}

impl AsRef<str> for ItemCategory {
    fn as_ref(&self) -> &str {
        match self {
            ItemCategory::Login => "LOGIN",
            ItemCategory::SecureNote => "SECURE_NOTE",
            ItemCategory::CreditCard => "CREDIT_CARD",
            ItemCategory::Identity => "IDENTITY",
            ItemCategory::Password => "PASSWORD",
            ItemCategory::Document => "DOCUMENT",
            ItemCategory::BankAccount => "BANK_ACCOUNT",
            ItemCategory::Database => "DATABASE",
            ItemCategory::DriverLicense => "DRIVER_LICENSE",
            ItemCategory::EmailAccount => "EMAIL_ACCOUNT",
            ItemCategory::Membership => "MEMBERSHIP",
            ItemCategory::OutdoorLicense => "OUTDOOR_LICENSE",
            ItemCategory::Passport => "PASSPORT",
            ItemCategory::RewardProgram => "REWARD_PROGRAM",
            ItemCategory::Server => "SERVER",
            ItemCategory::SocialSecurityNumber => "SOCIAL_SECURITY_NUMBER",
            ItemCategory::SoftwareLicense => "SOFTWARE_LICENSE",
            ItemCategory::SshKey => "SSH_KEY",
            ItemCategory::WirelessRouter => "WIRELESS_ROUTER",
            ItemCategory::ApiCredential => "API_CREDENTIAL",
            ItemCategory::MedicalRecord => "MEDICAL_RECORD",
            ItemCategory::Other(s) => s.as_str(),
        }
    }
}

// ============================================================================
// VaultPermission - Permissions for vault access
// ============================================================================

/// Vault access permissions.
///
/// Multiple permissions can be combined (e.g., `allow_viewing,allow_editing`).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum VaultPermission {
    AllowViewing,
    AllowEditing,
    AllowManaging,
}

impl VaultPermission {
    /// Returns the JSON Schema for this enum type.
    pub fn json_schema() -> serde_json::Map<String, serde_json::Value> {
        let mut schema = serde_json::Map::new();
        schema.insert(
            "type".to_string(),
            serde_json::Value::String("string".to_string()),
        );
        schema.insert(
            "description".to_string(),
            serde_json::Value::String("Vault access permission level.".to_string()),
        );
        schema.insert(
            "enum".to_string(),
            serde_json::Value::Array(vec![
                serde_json::Value::String("allow_viewing".to_string()),
                serde_json::Value::String("allow_editing".to_string()),
                serde_json::Value::String("allow_managing".to_string()),
            ]),
        );
        schema
    }
}

impl fmt::Display for VaultPermission {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            VaultPermission::AllowViewing => write!(f, "allow_viewing"),
            VaultPermission::AllowEditing => write!(f, "allow_editing"),
            VaultPermission::AllowManaging => write!(f, "allow_managing"),
        }
    }
}

impl AsRef<str> for VaultPermission {
    fn as_ref(&self) -> &str {
        match self {
            VaultPermission::AllowViewing => "allow_viewing",
            VaultPermission::AllowEditing => "allow_editing",
            VaultPermission::AllowManaging => "allow_managing",
        }
    }
}

/// Helper to convert a list of VaultPermissions to a comma-separated string.
pub fn permissions_to_string(permissions: &[VaultPermission]) -> String {
    permissions
        .iter()
        .map(|p| p.as_ref())
        .collect::<Vec<_>>()
        .join(",")
}

// ============================================================================
// ShareExpiry - Expiration duration for shared item links
// ============================================================================

/// Share link expiration duration.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ShareExpiry {
    /// 1 hour
    #[serde(rename = "1h")]
    OneHour,
    /// 1 day
    #[serde(rename = "1d")]
    OneDay,
    /// 7 days (default)
    #[serde(rename = "7d")]
    SevenDays,
    /// 14 days
    #[serde(rename = "14d")]
    FourteenDays,
    /// 30 days
    #[serde(rename = "30d")]
    ThirtyDays,
}

impl ShareExpiry {
    /// Returns the JSON Schema for this enum type.
    pub fn json_schema() -> serde_json::Map<String, serde_json::Value> {
        let mut schema = serde_json::Map::new();
        schema.insert(
            "type".to_string(),
            serde_json::Value::String("string".to_string()),
        );
        schema.insert(
            "description".to_string(),
            serde_json::Value::String(
                "Share link expiration duration. Default is 7 days.".to_string(),
            ),
        );
        schema.insert(
            "enum".to_string(),
            serde_json::Value::Array(vec![
                serde_json::Value::String("1h".to_string()),
                serde_json::Value::String("1d".to_string()),
                serde_json::Value::String("7d".to_string()),
                serde_json::Value::String("14d".to_string()),
                serde_json::Value::String("30d".to_string()),
            ]),
        );
        schema
    }
}

impl fmt::Display for ShareExpiry {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            ShareExpiry::OneHour => write!(f, "1h"),
            ShareExpiry::OneDay => write!(f, "1d"),
            ShareExpiry::SevenDays => write!(f, "7d"),
            ShareExpiry::FourteenDays => write!(f, "14d"),
            ShareExpiry::ThirtyDays => write!(f, "30d"),
        }
    }
}

impl AsRef<str> for ShareExpiry {
    fn as_ref(&self) -> &str {
        match self {
            ShareExpiry::OneHour => "1h",
            ShareExpiry::OneDay => "1d",
            ShareExpiry::SevenDays => "7d",
            ShareExpiry::FourteenDays => "14d",
            ShareExpiry::ThirtyDays => "30d",
        }
    }
}

impl Default for ShareExpiry {
    fn default() -> Self {
        ShareExpiry::SevenDays
    }
}

// ============================================================================
// TokenExpiry - Expiration duration for tokens (Connect, Service Account, Events API)
// ============================================================================

/// Token expiration duration for Connect tokens, service accounts, and Events API.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum TokenExpiry {
    /// 30 days
    #[serde(rename = "30d")]
    ThirtyDays,
    /// 1 year
    #[serde(rename = "1y")]
    OneYear,
    /// Never expires
    #[serde(rename = "never")]
    Never,
}

impl TokenExpiry {
    /// Returns the JSON Schema for this enum type.
    pub fn json_schema() -> serde_json::Map<String, serde_json::Value> {
        let mut schema = serde_json::Map::new();
        schema.insert(
            "type".to_string(),
            serde_json::Value::String("string".to_string()),
        );
        schema.insert(
            "description".to_string(),
            serde_json::Value::String("Token expiration duration.".to_string()),
        );
        schema.insert(
            "enum".to_string(),
            serde_json::Value::Array(vec![
                serde_json::Value::String("30d".to_string()),
                serde_json::Value::String("1y".to_string()),
                serde_json::Value::String("never".to_string()),
            ]),
        );
        schema
    }
}

impl fmt::Display for TokenExpiry {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            TokenExpiry::ThirtyDays => write!(f, "30d"),
            TokenExpiry::OneYear => write!(f, "1y"),
            TokenExpiry::Never => write!(f, "never"),
        }
    }
}

impl AsRef<str> for TokenExpiry {
    fn as_ref(&self) -> &str {
        match self {
            TokenExpiry::ThirtyDays => "30d",
            TokenExpiry::OneYear => "1y",
            TokenExpiry::Never => "never",
        }
    }
}

// ============================================================================
// EventFeature - Event types for Events API subscriptions
// ============================================================================

/// Event types available for Events API subscriptions.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum EventFeature {
    /// Sign-in attempt events
    Signinattempts,
    /// Item usage events
    Itemusages,
    /// Audit events
    Auditevents,
}

impl EventFeature {
    /// Returns the JSON Schema for this enum type.
    pub fn json_schema() -> serde_json::Map<String, serde_json::Value> {
        let mut schema = serde_json::Map::new();
        schema.insert(
            "type".to_string(),
            serde_json::Value::String("string".to_string()),
        );
        schema.insert(
            "description".to_string(),
            serde_json::Value::String("Event type for Events API subscription.".to_string()),
        );
        schema.insert(
            "enum".to_string(),
            serde_json::Value::Array(vec![
                serde_json::Value::String("signinattempts".to_string()),
                serde_json::Value::String("itemusages".to_string()),
                serde_json::Value::String("auditevents".to_string()),
            ]),
        );
        schema
    }
}

impl fmt::Display for EventFeature {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            EventFeature::Signinattempts => write!(f, "signinattempts"),
            EventFeature::Itemusages => write!(f, "itemusages"),
            EventFeature::Auditevents => write!(f, "auditevents"),
        }
    }
}

impl AsRef<str> for EventFeature {
    fn as_ref(&self) -> &str {
        match self {
            EventFeature::Signinattempts => "signinattempts",
            EventFeature::Itemusages => "itemusages",
            EventFeature::Auditevents => "auditevents",
        }
    }
}

/// Helper to convert a list of EventFeatures to a comma-separated string.
pub fn features_to_vec(features: &[EventFeature]) -> Vec<&str> {
    features.iter().map(|f| f.as_ref()).collect()
}

// ============================================================================
// GroupUserRole - Roles for users within groups
// ============================================================================

/// Role for a user within a group.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum GroupUserRole {
    /// Regular group member
    Member,
    /// Group manager with additional permissions
    Manager,
}

impl GroupUserRole {
    /// Returns the JSON Schema for this enum type.
    pub fn json_schema() -> serde_json::Map<String, serde_json::Value> {
        let mut schema = serde_json::Map::new();
        schema.insert(
            "type".to_string(),
            serde_json::Value::String("string".to_string()),
        );
        schema.insert(
            "description".to_string(),
            serde_json::Value::String("Role for a user within a group.".to_string()),
        );
        schema.insert(
            "enum".to_string(),
            serde_json::Value::Array(vec![
                serde_json::Value::String("member".to_string()),
                serde_json::Value::String("manager".to_string()),
            ]),
        );
        schema
    }
}

impl fmt::Display for GroupUserRole {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            GroupUserRole::Member => write!(f, "member"),
            GroupUserRole::Manager => write!(f, "manager"),
        }
    }
}

impl AsRef<str> for GroupUserRole {
    fn as_ref(&self) -> &str {
        match self {
            GroupUserRole::Member => "member",
            GroupUserRole::Manager => "manager",
        }
    }
}

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

    #[test]
    fn test_item_category_serialization() {
        assert_eq!(
            serde_json::to_string(&ItemCategory::Login).unwrap(),
            "\"LOGIN\""
        );
        assert_eq!(
            serde_json::to_string(&ItemCategory::SecureNote).unwrap(),
            "\"SECURE_NOTE\""
        );
        assert_eq!(
            serde_json::to_string(&ItemCategory::SshKey).unwrap(),
            "\"SSH_KEY\""
        );
    }

    #[test]
    fn test_item_category_deserialization() {
        assert_eq!(
            serde_json::from_str::<ItemCategory>("\"LOGIN\"").unwrap(),
            ItemCategory::Login
        );
        assert_eq!(
            serde_json::from_str::<ItemCategory>("\"SECURE_NOTE\"").unwrap(),
            ItemCategory::SecureNote
        );
        // Unknown category should deserialize to Other
        assert_eq!(
            serde_json::from_str::<ItemCategory>("\"UNKNOWN_FUTURE_TYPE\"").unwrap(),
            ItemCategory::Other("UNKNOWN_FUTURE_TYPE".to_string())
        );
    }

    #[test]
    fn test_share_expiry_serialization() {
        assert_eq!(
            serde_json::to_string(&ShareExpiry::OneHour).unwrap(),
            "\"1h\""
        );
        assert_eq!(
            serde_json::to_string(&ShareExpiry::SevenDays).unwrap(),
            "\"7d\""
        );
    }

    #[test]
    fn test_token_expiry_serialization() {
        assert_eq!(
            serde_json::to_string(&TokenExpiry::ThirtyDays).unwrap(),
            "\"30d\""
        );
        assert_eq!(
            serde_json::to_string(&TokenExpiry::Never).unwrap(),
            "\"never\""
        );
    }

    #[test]
    fn test_vault_permission_serialization() {
        assert_eq!(
            serde_json::to_string(&VaultPermission::AllowViewing).unwrap(),
            "\"allow_viewing\""
        );
    }

    #[test]
    fn test_permissions_to_string() {
        let perms = vec![VaultPermission::AllowViewing, VaultPermission::AllowEditing];
        assert_eq!(permissions_to_string(&perms), "allow_viewing,allow_editing");
    }

    #[test]
    fn test_event_feature_serialization() {
        assert_eq!(
            serde_json::to_string(&EventFeature::Signinattempts).unwrap(),
            "\"signinattempts\""
        );
    }

    #[test]
    fn test_group_user_role_serialization() {
        assert_eq!(
            serde_json::to_string(&GroupUserRole::Member).unwrap(),
            "\"member\""
        );
        assert_eq!(
            serde_json::to_string(&GroupUserRole::Manager).unwrap(),
            "\"manager\""
        );
    }

    #[test]
    fn test_item_category_json_schema() {
        let schema = ItemCategory::json_schema();
        assert_eq!(
            schema.get("type").unwrap(),
            &serde_json::Value::String("string".to_string())
        );
        let enum_values = schema.get("enum").unwrap().as_array().unwrap();
        assert!(enum_values.contains(&serde_json::Value::String("LOGIN".to_string())));
        assert!(enum_values.contains(&serde_json::Value::String("SECURE_NOTE".to_string())));
    }

    #[test]
    fn test_share_expiry_json_schema() {
        let schema = ShareExpiry::json_schema();
        let enum_values = schema.get("enum").unwrap().as_array().unwrap();
        assert!(enum_values.contains(&serde_json::Value::String("1h".to_string())));
        assert!(enum_values.contains(&serde_json::Value::String("7d".to_string())));
    }
}