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
//! Item management tools for 1Password

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::{ItemCategory, ShareExpiry};
use crate::tools::{json_result, op_error_to_tool_error, text_result};

// ============================================================================
// item_list Tool
// ============================================================================

/// List items in one or all vaults.
#[mcp_tool(
    name = "item_list",
    description = "List items in 1Password. Can filter by vault, categories, tags, or favorite status. Returns item summaries without sensitive field values."
)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct ItemListTool {
    /// Optional vault name or ID to filter items. If not specified, lists items from all vaults.
    #[serde(default)]
    pub vault: Option<String>,

    /// Optional list of categories to filter by.
    #[serde(default)]
    pub categories: Option<Vec<ItemCategory>>,

    /// Optional list of tags to filter by.
    #[serde(default)]
    pub tags: Option<Vec<String>>,

    /// If true, only return items marked as favorites.
    #[serde(default)]
    pub favorite: Option<bool>,
}

impl ItemListTool {
    pub async fn call(&self, client: &OpClient) -> Result<CallToolResult, CallToolError> {
        let categories_strs: Option<Vec<String>> = self
            .categories
            .as_ref()
            .map(|c| c.iter().map(|cat| cat.to_string()).collect());
        let categories_refs: Option<Vec<&str>> = categories_strs
            .as_ref()
            .map(|c| c.iter().map(|s| s.as_str()).collect());
        let tags_refs: Option<Vec<&str>> = self
            .tags
            .as_ref()
            .map(|t| t.iter().map(|s| s.as_str()).collect());

        let result = client
            .item_list(
                self.vault.as_deref(),
                categories_refs.as_deref(),
                tags_refs.as_deref(),
                self.favorite,
            )
            .await
            .map_err(op_error_to_tool_error)?;
        json_result(&result)
    }
}

// ============================================================================
// item_get Tool
// ============================================================================

/// Get full details for a specific item.
#[mcp_tool(
    name = "item_get",
    description = "Get detailed information about a specific item by name or ID. By default, sensitive fields like passwords are hidden. Set reveal=true to show all field values."
)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct ItemGetTool {
    /// The name or ID of the item to retrieve.
    pub item: String,

    /// Optional vault name or ID. Required if multiple items have the same name.
    #[serde(default)]
    pub vault: Option<String>,

    /// If true, reveal sensitive field values (passwords, keys, etc.). Default is false for security.
    #[serde(default)]
    pub reveal: bool,
}

impl ItemGetTool {
    pub async fn call(&self, client: &OpClient) -> Result<CallToolResult, CallToolError> {
        let result = client
            .item_get(&self.item, self.vault.as_deref(), self.reveal)
            .await
            .map_err(op_error_to_tool_error)?;
        json_result(&result)
    }
}

// ============================================================================
// item_create Tool
// ============================================================================

/// Create a new item in a vault.
#[mcp_tool(
    name = "item_create",
    description = "Create a new item in 1Password. Specify a category, title, vault, and fields. Fields are specified as 'field=value' or 'section.field=value' pairs."
)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct ItemCreateTool {
    /// The category of item to create.
    pub category: ItemCategory,

    /// The title for the new item.
    pub title: String,

    /// The vault name or ID to create the item in.
    #[serde(default)]
    pub vault: Option<String>,

    /// Generate a password for the item. Can be a recipe like 'letters,digits,symbols,32' or just 'true' for defaults.
    #[serde(default)]
    pub generate_password: Option<String>,

    /// URL associated with the item (for LOGIN items).
    #[serde(default)]
    pub url: Option<String>,

    /// Tags to apply to the item.
    #[serde(default)]
    pub tags: Option<Vec<String>>,

    /// Field assignments in 'field=value' or 'section.field[type]=value' format.
    #[serde(default)]
    pub fields: Option<Vec<String>>,

    /// Mark the item as a favorite.
    #[serde(default)]
    pub favorite: bool,
}

impl ItemCreateTool {
    pub async fn call(&self, client: &OpClient) -> Result<CallToolResult, CallToolError> {
        let category_str = self.category.to_string();
        let tags_refs: Option<Vec<&str>> = self
            .tags
            .as_ref()
            .map(|t| t.iter().map(|s| s.as_str()).collect());
        let fields_refs: Option<Vec<&str>> = self
            .fields
            .as_ref()
            .map(|f| f.iter().map(|s| s.as_str()).collect());

        let result = client
            .item_create(
                &category_str,
                &self.title,
                self.vault.as_deref(),
                self.generate_password.as_deref(),
                self.url.as_deref(),
                tags_refs.as_deref(),
                fields_refs.as_deref(),
                self.favorite,
            )
            .await
            .map_err(op_error_to_tool_error)?;
        json_result(&result)
    }
}

// ============================================================================
// item_edit Tool
// ============================================================================

/// Edit an existing item.
#[mcp_tool(
    name = "item_edit",
    description = "Edit an existing item's fields, title, tags, or other properties. Fields are specified as 'field=value' or 'section.field=value' pairs."
)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct ItemEditTool {
    /// The name or ID of the item to edit.
    pub item: String,

    /// Optional vault name or ID.
    #[serde(default)]
    pub vault: Option<String>,

    /// New title for the item.
    #[serde(default)]
    pub title: Option<String>,

    /// URL to update.
    #[serde(default)]
    pub url: Option<String>,

    /// Generate a new password. Can be a recipe like 'letters,digits,symbols,32'.
    #[serde(default)]
    pub generate_password: Option<String>,

    /// Tags to set on the item (replaces existing tags).
    #[serde(default)]
    pub tags: Option<Vec<String>>,

    /// Field assignments in 'field=value' or 'section.field[type]=value' format.
    #[serde(default)]
    pub fields: Option<Vec<String>>,

    /// Set favorite status.
    #[serde(default)]
    pub favorite: Option<bool>,
}

impl ItemEditTool {
    pub async fn call(&self, client: &OpClient) -> Result<CallToolResult, CallToolError> {
        let tags_refs: Option<Vec<&str>> = self
            .tags
            .as_ref()
            .map(|t| t.iter().map(|s| s.as_str()).collect());
        let fields_refs: Option<Vec<&str>> = self
            .fields
            .as_ref()
            .map(|f| f.iter().map(|s| s.as_str()).collect());

        let result = client
            .item_edit(
                &self.item,
                self.vault.as_deref(),
                self.title.as_deref(),
                self.url.as_deref(),
                self.generate_password.as_deref(),
                tags_refs.as_deref(),
                fields_refs.as_deref(),
                self.favorite,
            )
            .await
            .map_err(op_error_to_tool_error)?;
        json_result(&result)
    }
}

// ============================================================================
// item_delete Tool
// ============================================================================

/// Delete an item.
#[mcp_tool(
    name = "item_delete",
    description = "Delete or archive an item. By default, items are archived (moved to trash) and can be recovered. Use archive=false to permanently delete."
)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct ItemDeleteTool {
    /// The name or ID of the item to delete.
    pub item: String,

    /// Optional vault name or ID.
    #[serde(default)]
    pub vault: Option<String>,

    /// If true (default), archive the item instead of permanently deleting.
    #[serde(default = "default_true")]
    pub archive: bool,
}

fn default_true() -> bool {
    true
}

impl ItemDeleteTool {
    pub async fn call(&self, client: &OpClient) -> Result<CallToolResult, CallToolError> {
        let result = client
            .item_delete(&self.item, self.vault.as_deref(), self.archive)
            .await
            .map_err(op_error_to_tool_error)?;
        text_result(result)
    }
}

// ============================================================================
// item_move Tool
// ============================================================================

/// Move an item to a different vault.
#[mcp_tool(
    name = "item_move",
    description = "Move an item from one vault to another. Requires appropriate permissions in both vaults."
)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct ItemMoveTool {
    /// The name or ID of the item to move.
    pub item: String,

    /// The current vault name or ID (source).
    #[serde(default)]
    pub current_vault: Option<String>,

    /// The destination vault name or ID.
    pub destination_vault: String,
}

impl ItemMoveTool {
    pub async fn call(&self, client: &OpClient) -> Result<CallToolResult, CallToolError> {
        let result = client
            .item_move(&self.item, self.current_vault.as_deref(), &self.destination_vault)
            .await
            .map_err(op_error_to_tool_error)?;
        text_result(result)
    }
}

// ============================================================================
// item_share Tool
// ============================================================================

/// Create a shareable link for an item.
#[mcp_tool(
    name = "item_share",
    description = "Create a secure, time-limited link to share an item with someone. The link expires after the specified duration and can be limited to specific email addresses."
)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct ItemShareTool {
    /// The name or ID of the item to share.
    pub item: String,

    /// Optional vault name or ID.
    #[serde(default)]
    pub vault: Option<String>,

    /// Link expiration duration. Default is 7 days.
    #[serde(default)]
    pub expiry: Option<ShareExpiry>,

    /// Limit access to these email addresses (comma-separated or array).
    #[serde(default)]
    pub emails: Option<Vec<String>>,

    /// If true, require the recipient to view the item only once.
    #[serde(default)]
    pub view_once: bool,
}

impl ItemShareTool {
    pub async fn call(&self, client: &OpClient) -> Result<CallToolResult, CallToolError> {
        let expiry_str = self.expiry.as_ref().map(|e| e.to_string());
        let emails_refs: Option<Vec<&str>> = self
            .emails
            .as_ref()
            .map(|e| e.iter().map(|s| s.as_str()).collect());

        let result = client
            .item_share(
                &self.item,
                self.vault.as_deref(),
                expiry_str.as_deref(),
                emails_refs.as_deref(),
                self.view_once,
            )
            .await
            .map_err(op_error_to_tool_error)?;
        text_result(result)
    }
}

// ============================================================================
// item_template_list Tool
// ============================================================================

/// List available item templates.
#[mcp_tool(
    name = "item_template_list",
    description = "List all available item templates/categories that can be used when creating new items."
)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct ItemTemplateListTool {}

impl ItemTemplateListTool {
    pub async fn call(&self, client: &OpClient) -> Result<CallToolResult, CallToolError> {
        let result = client
            .item_template_list()
            .await
            .map_err(op_error_to_tool_error)?;
        json_result(&result)
    }
}

// ============================================================================
// item_template_get Tool
// ============================================================================

/// Get details for a specific item template.
#[mcp_tool(
    name = "item_template_get",
    description = "Get the field structure and details for a specific item template/category. Useful for understanding what fields are available when creating items."
)]
#[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct ItemTemplateGetTool {
    /// The template name (category) to retrieve (e.g., 'LOGIN', 'SECURE_NOTE', 'CREDIT_CARD').
    pub template: String,
}

impl ItemTemplateGetTool {
    pub async fn call(&self, client: &OpClient) -> Result<CallToolResult, CallToolError> {
        let result = client
            .item_template_get(&self.template)
            .await
            .map_err(op_error_to_tool_error)?;
        json_result(&result)
    }
}