Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ A community-built [Model Context Protocol (MCP)](https://modelcontextprotocol.io

## Features

### Tools (8)
### Tools (13)

| Tool | Description |
|------|-------------|
| `vault_list` | List all accessible vaults |
| `item_lookup` | Search items by title in a vault |
| `item_list` | List all items in a vault (id, title, category, tags, updatedAt) |
| `item_get` | Retrieve a full item (title, category, tags, notes, fields); conceals secret values unless `reveal` is true |
| `item_edit` | Edit an item's title, notes, tags, URL, and fields (upsert/remove); empty `notes` clears notes |
| `item_delete` | Delete an item from a vault |
| `item_archive` | Archive an item (move to archive instead of permanently deleting) |
| `note_create` | Create a Secure Note item with optional tags and custom fields |
| `password_create` | Create a new password/login item |
| `password_read` | Retrieve a password via secret reference (`op://vault/item/field`) or vault/item ID |
| `password_update` | Rotate/update an existing password |
Expand Down
10 changes: 10 additions & 0 deletions src/tools/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { registerVaultList } from "./vault-list.js";
import { registerItemLookup } from "./item-lookup.js";
import { registerItemDelete } from "./item-delete.js";
import { registerItemGet } from "./item-get.js";
import { registerItemEdit } from "./item-edit.js";
import { registerItemList } from "./item-list.js";
import { registerItemArchive } from "./item-archive.js";
import { registerNoteCreate } from "./note-create.js";
import { registerPasswordCreate } from "./password-create.js";
import { registerPasswordRead } from "./password-read.js";
import { registerPasswordUpdate } from "./password-update.js";
Expand All @@ -17,6 +22,11 @@ export function registerAllTools(server: McpServer): void {
registerVaultList(server);
registerItemLookup(server);
registerItemDelete(server);
registerItemGet(server);
registerItemEdit(server);
registerItemList(server);
registerItemArchive(server);
registerNoteCreate(server);
registerPasswordCreate(server);
registerPasswordRead(server);
registerPasswordUpdate(server);
Expand Down
36 changes: 36 additions & 0 deletions src/tools/item-archive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* item_archive — Archive an item in a 1Password vault (instead of hard-deleting).
*/

import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { getClient } from "../client.js";
import { log, logError } from "../logger.js";
import { jsonResult, errorResult } from "../utils.js";

export function registerItemArchive(server: McpServer): void {
server.tool(
"item_archive",
"Archive an item in a 1Password vault. The item is moved to the archive and hidden from regular views, rather than being permanently deleted.",
{
vaultId: z.string().min(1).describe("Vault ID containing the item."),
itemId: z.string().min(1).describe("Item ID to archive."),
},
async ({ vaultId, itemId }) => {
try {
log("debug", "Tool call: item_archive.", { vaultId, itemId });
const client = await getClient();
if (!client?.items?.archive) {
throw new Error(
"Your @1password/sdk version does not support archiving items.",
);
}
await client.items.archive(vaultId, itemId);
return jsonResult({ archived: true, vaultId, itemId });
} catch (error) {
logError("item_archive failed.", error);
return errorResult(error);
}
},
);
}
189 changes: 189 additions & 0 deletions src/tools/item-edit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/**
* item_edit — Edit an existing 1Password item: title, notes, tags, url, and fields.
*
* The item is fetched, changes are applied immutably, and the result is written
* back via items.put. Unreferenced fields are preserved untouched. Field values
* are never logged.
*/

import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import {
ItemFieldType,
AutofillBehavior,
type Item,
type ItemField,
type Website,
} from "@1password/sdk";
import { getClient } from "../client.js";
import { log, logError } from "../logger.js";
import { jsonResult, errorResult } from "../utils.js";

/** A field upsert request from the caller. */
const fieldInput = z.object({
idOrTitle: z
.string()
.min(1)
.describe("Field id or title to match (case-insensitive). Created if absent."),
type: z
.enum(["text", "concealed"])
.describe("Field type: 'text' for plain values, 'concealed' for secrets."),
value: z.string().describe("New value for the field."),
section: z
.string()
.optional()
.describe("Optional section id to associate the field with."),
});

/** Does a field match the caller-supplied id-or-title? */
function fieldMatches(field: ItemField, idOrTitle: string): boolean {
const target = idOrTitle.toLowerCase();
return (
field.id?.toLowerCase() === target ||
field.title?.toLowerCase() === target
);
}

export function registerItemEdit(server: McpServer): void {
server.tool(
"item_edit",
"Edit an existing 1Password item. Update the title, notes (pass an empty string to clear notes), tags, website URL, upsert fields, or remove fields. Only referenced fields are changed; all others are preserved.",
{
vaultId: z.string().min(1).describe("Vault ID containing the item."),
itemId: z.string().min(1).describe("Item ID to edit."),
title: z.string().min(1).optional().describe("New item title."),
notes: z
.string()
.optional()
.describe(
"Full replacement of the item's notes. Pass an empty string to clear notes.",
),
tags: z
.array(z.string().min(1))
.optional()
.describe("Replacement set of tags (replaces all existing tags)."),
url: z
.string()
.url()
.optional()
.describe("Replacement primary website URL for the item."),
fields: z
.array(fieldInput)
.optional()
.describe("Fields to upsert (create or update) by id or title."),
removeFields: z
.array(z.string().min(1))
.optional()
.describe("Field ids or titles to remove from the item."),
},
async ({ vaultId, itemId, title, notes, tags, url, fields, removeFields }) => {
try {
// NOTE: field values are intentionally excluded from logs.
log("debug", "Tool call: item_edit.", {
vaultId,
itemId,
changeTitle: title !== undefined,
changeNotes: notes !== undefined,
changeTags: tags !== undefined,
changeUrl: url !== undefined,
upsertCount: fields?.length ?? 0,
removeCount: removeFields?.length ?? 0,
});

const client = await getClient();
if (!client?.items?.get) {
throw new Error(
"Your @1password/sdk version does not support getting items.",
);
}
if (!client?.items?.put) {
throw new Error(
"Your @1password/sdk version does not support updating items.",
);
}

const existing: Item = await client.items.get(vaultId, itemId);

// Build the next field list immutably, preserving unreferenced fields.
const removeSet = new Set(
(removeFields ?? []).map((value) => value.toLowerCase()),
);

let nextFields: ItemField[] = (existing.fields ?? []).filter(
(field) =>
!removeSet.has(field.id?.toLowerCase()) &&
!removeSet.has(field.title?.toLowerCase()),
);

for (const upsert of fields ?? []) {
const fieldType =
upsert.type === "concealed"
? ItemFieldType.Concealed
: ItemFieldType.Text;
const index = nextFields.findIndex((field) =>
fieldMatches(field, upsert.idOrTitle),
);

if (index >= 0) {
const current = nextFields[index];
const replacement: ItemField = {
...current,
fieldType,
value: upsert.value,
sectionId: upsert.section ?? current.sectionId,
};
nextFields = nextFields.map((field, i) =>
i === index ? replacement : field,
);
} else {
nextFields = [
...nextFields,
{
id: upsert.idOrTitle,
title: upsert.idOrTitle,
fieldType,
value: upsert.value,
sectionId: upsert.section,
},
];
}
}

let nextWebsites: Website[] | undefined = existing.websites;
if (url !== undefined) {
nextWebsites = [
{
url,
label: "website",
autofillBehavior: AutofillBehavior.AnywhereOnWebsite,
},
];
}

const updated: Item = {
...existing,
title: title ?? existing.title,
notes: notes ?? existing.notes,
tags: tags ?? existing.tags,
websites: nextWebsites,
fields: nextFields,
};

const result: Item = await client.items.put(updated);

return jsonResult({
id: result.id,
title: result.title,
vaultId: result.vaultId,
category: result.category,
tags: result.tags ?? [],
fieldCount: result.fields?.length ?? 0,
updatedAt: result.updatedAt,
});
} catch (error) {
logError("item_edit failed.", error);
return errorResult(error);
}
},
);
}
Loading
Loading