@icoretech/warden-mcp 0.2.17 → 0.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -594,6 +594,8 @@ Orgs/collections:
594
594
  Attachments:
595
595
 
596
596
  - `keychain_create_attachment`, `keychain_delete_attachment`, `keychain_get_attachment`
597
+ - `keychain_get_item` exposes safe attachment metadata (`id`, `fileName`, size) while redacting signed download URLs, so clients can discover the exact attachment id before downloading
598
+ - `keychain_get_attachment` accepts an attachment id or an unambiguous filename and returns `{ filename, bytes, contentBase64 }`; decode `contentBase64` locally when you need the original file bytes
597
599
 
598
600
  Sends:
599
601
 
package/dist/bw/bwCli.js CHANGED
@@ -164,7 +164,7 @@ export async function runBw(args, opts = {}) {
164
164
  if (debug) {
165
165
  console.log(`[bw] ok: ms=${Date.now() - startedAt}`);
166
166
  }
167
- resolve({ stdout, stderr });
167
+ resolve({ stdout, stdoutBuffer: Buffer.concat(stdoutChunks), stderr });
168
168
  });
169
169
  });
170
170
  });
@@ -376,6 +376,42 @@ export class KeychainSdk {
376
376
  contentBase64: buf.toString('base64'),
377
377
  };
378
378
  }
379
+ attachmentsFromItem(item) {
380
+ if (!item || typeof item !== 'object')
381
+ return [];
382
+ const attachments = item.attachments;
383
+ if (!Array.isArray(attachments))
384
+ return [];
385
+ return attachments
386
+ .filter((a) => Boolean(a) && typeof a === 'object')
387
+ .map((a) => ({
388
+ id: typeof a.id === 'string' ? a.id : undefined,
389
+ fileName: typeof a.fileName === 'string' ? a.fileName : undefined,
390
+ size: typeof a.size === 'string' || typeof a.size === 'number'
391
+ ? a.size
392
+ : undefined,
393
+ sizeName: typeof a.sizeName === 'string' ? a.sizeName : undefined,
394
+ }));
395
+ }
396
+ resolveAttachment(item, selector) {
397
+ const needle = selector.toLowerCase();
398
+ const matches = this.attachmentsFromItem(item).filter((a) => {
399
+ const id = a.id?.toLowerCase();
400
+ const fileName = a.fileName?.toLowerCase();
401
+ return id === needle || Boolean(fileName?.includes(needle));
402
+ });
403
+ const exactFileNameMatches = matches.filter((a) => a.fileName?.toLowerCase() === needle);
404
+ if (exactFileNameMatches.length === 1)
405
+ return exactFileNameMatches[0];
406
+ if (matches.length === 0)
407
+ return null;
408
+ if (matches.length === 1)
409
+ return matches[0];
410
+ const ids = matches
411
+ .map((a) => a.id)
412
+ .filter((id) => typeof id === 'string' && id.length > 0);
413
+ throw new Error(`Attachment selector matched multiple attachments: ${ids.join(', ')}`);
414
+ }
379
415
  redactPasswordHistoryForTool(history) {
380
416
  // For secret-returning tools we avoid returning sentinel strings like "[REDACTED]"
381
417
  // because downstream utilities might accidentally pass them through.
@@ -433,22 +469,24 @@ export class KeychainSdk {
433
469
  }
434
470
  async getAttachment(input) {
435
471
  return this.bw.withSession(async (session) => {
436
- const dir = await mkdtemp(join(tmpdir(), 'keychain-attachment-'));
437
- try {
438
- await this.bw.runForSession(session, [
439
- 'get',
440
- 'attachment',
441
- input.attachmentId,
442
- '--itemid',
443
- input.itemId,
444
- '--output',
445
- dir,
446
- ], { timeoutMs: 120_000 });
447
- return await this.readSingleFileAsBase64(dir);
448
- }
449
- finally {
450
- await rm(dir, { recursive: true, force: true });
451
- }
472
+ const { stdout: itemOut } = await this.bw.runForSession(session, ['get', 'item', input.itemId], { timeoutMs: 60_000 });
473
+ const item = this.parseBwJson(itemOut);
474
+ const metadata = this.resolveAttachment(item, input.attachmentId);
475
+ const attachmentSelector = metadata?.id ?? input.attachmentId;
476
+ const { stdout, stdoutBuffer } = await this.bw.runForSession(session, [
477
+ 'get',
478
+ 'attachment',
479
+ attachmentSelector,
480
+ '--itemid',
481
+ input.itemId,
482
+ '--raw',
483
+ ], { timeoutMs: 120_000 });
484
+ const buf = stdoutBuffer ?? Buffer.from(stdout, 'utf8');
485
+ return {
486
+ filename: metadata?.fileName ?? input.attachmentId,
487
+ bytes: buf.byteLength,
488
+ contentBase64: buf.toString('base64'),
489
+ };
452
490
  });
453
491
  }
454
492
  async sendList() {
@@ -108,6 +108,31 @@ export function registerTools(server, deps) {
108
108
  if (Array.isArray(rec.collectionIds) && rec.collectionIds.length > 0) {
109
109
  parts.push(`collectionIds=${quoteText(rec.collectionIds.join(', '))}`);
110
110
  }
111
+ if (Array.isArray(rec.attachments) && rec.attachments.length > 0) {
112
+ const attachments = rec.attachments
113
+ .map((attachment) => {
114
+ if (!attachment || typeof attachment !== 'object')
115
+ return null;
116
+ const att = attachment;
117
+ const attParts = [];
118
+ if (typeof att.id === 'string')
119
+ attParts.push(`id=${att.id}`);
120
+ if (typeof att.fileName === 'string') {
121
+ attParts.push(`fileName=${quoteText(att.fileName)}`);
122
+ }
123
+ if (typeof att.size === 'string' || typeof att.size === 'number') {
124
+ attParts.push(`size=${att.size}`);
125
+ }
126
+ if (typeof att.sizeName === 'string') {
127
+ attParts.push(`sizeName=${quoteText(att.sizeName)}`);
128
+ }
129
+ return attParts.length > 0 ? `{${attParts.join(' ')}}` : null;
130
+ })
131
+ .filter((attachment) => attachment !== null);
132
+ if (attachments.length > 0) {
133
+ parts.push(`attachments=${quoteText(attachments.join(', '))}`);
134
+ }
135
+ }
111
136
  if (typeof rec.favorite === 'boolean')
112
137
  parts.push(`favorite=${rec.favorite}`);
113
138
  return `- ${parts.length > 0 ? parts.join(' ') : stringifyScalar(rec)}`;
@@ -887,7 +912,7 @@ export function registerTools(server, deps) {
887
912
  const structuredContent = { attachment };
888
913
  return {
889
914
  structuredContent,
890
- content: toolTextContent(structuredContent, 'OK'),
915
+ content: toolTextContent(structuredContent, `Downloaded attachment: filename=${quoteText(attachment.filename)} bytes=${attachment.bytes}`),
891
916
  };
892
917
  });
893
918
  registerTool(`${deps.toolPrefix}.send_list`, {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@icoretech/warden-mcp",
4
- "version": "0.2.17",
4
+ "version": "0.2.18",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "description": "Vaultwarden/Bitwarden MCP server backed by Bitwarden CLI (bw).",