@sendsafely/mcp-server-local 0.0.0-stage → 1.0.5
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/LICENSE +201 -0
- package/NOTICE +22 -0
- package/README.md +390 -2
- package/dist/context.d.ts +2 -0
- package/dist/context.js +21 -0
- package/dist/credentials.d.ts +7 -0
- package/dist/credentials.js +59 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +47 -0
- package/dist/setupCredentials.d.ts +2 -0
- package/dist/setupCredentials.js +151 -0
- package/dist/trustedDeviceKeyStore.d.ts +3 -0
- package/dist/trustedDeviceKeyStore.js +34 -0
- package/node_modules/@sendsafely/mcp-tools-core/LICENSE +201 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/approval.d.ts +51 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/approval.js +148 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/constants.d.ts +5 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/constants.js +8 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/context.d.ts +25 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/context.js +16 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/index.d.ts +18 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/index.js +17 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/instructions.d.ts +1 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/instructions.js +17 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/jsonResult.d.ts +3 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/jsonResult.js +15 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/recipientAddContext.d.ts +42 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/recipientAddContext.js +182 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/runTool.d.ts +2 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/runTool.js +22 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/safeHandler.d.ts +17 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/safeHandler.js +32 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/sdk/clientFactory.d.ts +17 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/sdk/clientFactory.js +29 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/sdk/oauthError.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/sdk/oauthError.js +34 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/sdk/sdkPromise.d.ts +53 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/sdk/sdkPromise.js +462 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/sdk/signedFetch.d.ts +6 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/sdk/signedFetch.js +28 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/store/keyStore.d.ts +6 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/store/keyStore.js +1 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/store/packageSecretCache.d.ts +18 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/store/packageSecretCache.js +39 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/createDirectory.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/createDirectory.js +53 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/deleteDirectory.d.ts +10 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/deleteDirectory.js +46 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/deleteFile.d.ts +11 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/deleteFile.js +53 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getActivityLog.d.ts +8 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getActivityLog.js +44 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getDirectory.d.ts +12 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getDirectory.js +51 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getEnterpriseInfo.d.ts +5 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getEnterpriseInfo.js +27 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getFileInformation.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getFileInformation.js +34 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getPackageInformation.d.ts +7 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getPackageInformation.js +41 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getReceivedPackages.d.ts +5 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getReceivedPackages.js +54 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getRecipient.d.ts +8 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getRecipient.js +30 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getSentPackages.d.ts +7 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getSentPackages.js +84 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getWorkspaces.d.ts +5 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/getWorkspaces.js +114 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/index.d.ts +46 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/index.js +92 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/moveDirectory.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/moveDirectory.js +39 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/removeRecipient.d.ts +8 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/removeRecipient.js +34 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/renameDirectory.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/renameDirectory.js +34 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/setRecipientPhoneNumber.d.ts +10 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/setRecipientPhoneNumber.js +40 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/addPackageMessage.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/addPackageMessage.js +37 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/addRecipient.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/addRecipient.js +109 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/addRecipientWithSms.d.ts +11 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/addRecipientWithSms.js +115 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/addRecipientsBulk.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/addRecipientsBulk.js +110 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/createPackage.d.ts +6 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/createPackage.js +65 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/createWorkspace.d.ts +10 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/createWorkspace.js +107 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/deletePackage.d.ts +10 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/deletePackage.js +39 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/downloadFileFromDirectory.d.ts +12 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/downloadFileFromDirectory.js +91 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/downloadPackageFiles.d.ts +12 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/downloadPackageFiles.js +205 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/finalizePackage.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/finalizePackage.js +111 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/finalizeUndisclosedPackage.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/finalizeUndisclosedPackage.js +57 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/generateTrustedDeviceKeypair.d.ts +10 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/generateTrustedDeviceKeypair.js +75 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/getPackageInformationFromLink.d.ts +8 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/getPackageInformationFromLink.js +50 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/getPackageKeycode.d.ts +11 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/getPackageKeycode.js +120 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/getPackageMessage.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/getPackageMessage.js +59 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/listDownloadedFiles.d.ts +5 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/listDownloadedFiles.js +71 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/readDownloadedFile.d.ts +8 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/readDownloadedFile.js +176 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/uploadFile.d.ts +12 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/uploadFile.js +69 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/updateFile.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/updateFile.js +38 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/updatePackage.d.ts +14 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/updatePackage.js +122 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/updateRecipientRole.d.ts +9 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/updateRecipientRole.js +45 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/verifyCredentials.d.ts +5 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/tools/verifyCredentials.js +27 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/types/sendsafely.d.ts +432 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/utils/packageChecksum.d.ts +1 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/utils/packageChecksum.js +7 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/utils/packageDir.d.ts +8 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/utils/packageDir.js +50 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/utils/packageLink.d.ts +2 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/utils/packageLink.js +4 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/utils/sanitizeFilename.d.ts +4 -0
- package/node_modules/@sendsafely/mcp-tools-core/dist/utils/sanitizeFilename.js +8 -0
- package/node_modules/@sendsafely/mcp-tools-core/package.json +40 -0
- package/npm-shrinkwrap.json +1632 -0
- package/package.json +58 -4
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { jsonError, jsonResult } from "../../jsonResult.js";
|
|
3
|
+
import { MissingPackageSecretsError, } from "../../store/packageSecretCache.js";
|
|
4
|
+
import { buildShareLinkMessage, classifyRecipientAddContext, promptAndApplyWorkspaceRole, tryBuildKeyedLink, } from "../../recipientAddContext.js";
|
|
5
|
+
import { runTool } from "../../runTool.js";
|
|
6
|
+
import { safeHandler } from "../../safeHandler.js";
|
|
7
|
+
import { addRecipientWithSMS, packageInformation } from "../../sdk/sdkPromise.js";
|
|
8
|
+
export async function handleAddRecipientWithSms(args, extra, ctx, cacheFor) {
|
|
9
|
+
return runTool("add_recipient_with_sms", "Failed to add recipient", async () => {
|
|
10
|
+
const client = await ctx.getClient(extra);
|
|
11
|
+
const secrets = cacheFor(extra).get(args.package_id);
|
|
12
|
+
if (!secrets)
|
|
13
|
+
throw new MissingPackageSecretsError(args.package_id);
|
|
14
|
+
const info = await packageInformation(client, args.package_id);
|
|
15
|
+
const context = classifyRecipientAddContext(info);
|
|
16
|
+
if (context.kind === "block_deleted") {
|
|
17
|
+
return jsonError(`Cannot add recipient: package '${args.package_id}' has been ` +
|
|
18
|
+
`deleted (state ${context.state}). Inform the user that the ` +
|
|
19
|
+
"package no longer exists and recipients cannot be added.");
|
|
20
|
+
}
|
|
21
|
+
const recipient = await addRecipientWithSMS(client, args.package_id, args.email, secrets.keyCode, args.phone_number, args.country_code);
|
|
22
|
+
if (context.kind === "unfinalized_or_unknown") {
|
|
23
|
+
return jsonResult({
|
|
24
|
+
status: "success",
|
|
25
|
+
package_id: args.package_id,
|
|
26
|
+
recipient,
|
|
27
|
+
message: `Recipient ${args.email} added with SMS verification. ` +
|
|
28
|
+
"Recipients are notified when finalize_package runs.",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
const rolePrompt = context.kind === "active_workspace"
|
|
32
|
+
? await promptAndApplyWorkspaceRole(ctx, client, args.package_id, [{ recipient_id: recipient.recipientId, email: recipient.email }], `Collaborator ${args.email}`)
|
|
33
|
+
: undefined;
|
|
34
|
+
const secureLink = tryBuildKeyedLink(client, secrets.keyCode, secrets.packageCode);
|
|
35
|
+
if (!secureLink) {
|
|
36
|
+
const baseMessage = `Recipient ${args.email} added with SMS verification. ` +
|
|
37
|
+
"SendSafely will NOT auto-notify this recipient, but " +
|
|
38
|
+
"secure_link could not be reconstructed from the cache " +
|
|
39
|
+
"(see secure_link_unavailable).";
|
|
40
|
+
return jsonResult({
|
|
41
|
+
status: "success",
|
|
42
|
+
package_id: args.package_id,
|
|
43
|
+
recipient,
|
|
44
|
+
package_type: info.packageType,
|
|
45
|
+
package_state: info.state,
|
|
46
|
+
secure_link_unavailable: "Cache entry has no packageCode. Tell the user to fetch the " +
|
|
47
|
+
"keyed link via get_package_information_from_link or " +
|
|
48
|
+
"get_package_keycode and share it with the new recipient.",
|
|
49
|
+
...(rolePrompt ? { role_prompt: rolePrompt } : {}),
|
|
50
|
+
message: rolePrompt?.message
|
|
51
|
+
? `${baseMessage}\n\n${rolePrompt.message}`
|
|
52
|
+
: baseMessage,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const linkMessage = buildShareLinkMessage(context, `Recipient ${args.email} (SMS-verified)`, secureLink);
|
|
56
|
+
const message = rolePrompt?.message
|
|
57
|
+
? `${linkMessage}\n\n${rolePrompt.message}`
|
|
58
|
+
: linkMessage;
|
|
59
|
+
return jsonResult({
|
|
60
|
+
status: "success",
|
|
61
|
+
package_id: args.package_id,
|
|
62
|
+
recipient,
|
|
63
|
+
package_type: info.packageType,
|
|
64
|
+
package_state: info.state,
|
|
65
|
+
secure_link: secureLink,
|
|
66
|
+
...(rolePrompt ? { role_prompt: rolePrompt } : {}),
|
|
67
|
+
message,
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export function registerAddRecipientWithSms(mcp, ctx, cacheFor) {
|
|
72
|
+
mcp.registerTool("add_recipient_with_sms", {
|
|
73
|
+
title: "Add Recipient With SMS Verification",
|
|
74
|
+
description: "Add a recipient who must verify via SMS before retrieving the " +
|
|
75
|
+
"package. The package's secret material must be in the server-side " +
|
|
76
|
+
"cache (populated by create_package, get_package_information_from_link, " +
|
|
77
|
+
"or get_package_keycode via a registered Trusted Device). " +
|
|
78
|
+
"Same state/type-aware behavior as add_recipient: deleted packages " +
|
|
79
|
+
"are refused; workspaces and already-finalized Transfer/Dropzone " +
|
|
80
|
+
"packages return secure_link + a reminder telling the user to " +
|
|
81
|
+
"share the link with the new recipient (no auto-notification); " +
|
|
82
|
+
"expired packages return a warning that the package needs to be " +
|
|
83
|
+
"un-expired first; unfinalized packages proceed without a " +
|
|
84
|
+
"reminder since finalize_package will handle notifications. On a " +
|
|
85
|
+
"workspace add, the tool also prompts the user to pick the new " +
|
|
86
|
+
"collaborator's role (default VIEWER; alternatives CONTRIBUTOR or " +
|
|
87
|
+
"MANAGER) and applies it automatically via update_recipient_role.",
|
|
88
|
+
inputSchema: {
|
|
89
|
+
package_id: z.string().describe("The unique SendSafely package ID."),
|
|
90
|
+
email: z
|
|
91
|
+
.string()
|
|
92
|
+
.describe("Recipient's email address (e.g. 'alice@example.com')."),
|
|
93
|
+
phone_number: z
|
|
94
|
+
.string()
|
|
95
|
+
.describe("Recipient's mobile phone number, full-length for the country " +
|
|
96
|
+
"(e.g. '2025551234' for US — 10 digits including area code; " +
|
|
97
|
+
"'+12025551234' E.164 also accepted). SendSafely validates with " +
|
|
98
|
+
"Google's libphonenumber, so the digit count must match the " +
|
|
99
|
+
"country's real-number format. Short inputs like '5551234' " +
|
|
100
|
+
"will be rejected as invalid."),
|
|
101
|
+
country_code: z
|
|
102
|
+
.string()
|
|
103
|
+
.describe("Country dialing code OR ISO alpha-2 country code. " +
|
|
104
|
+
"Numeric examples: '1' (US/Canada), '44' (UK), '81' (Japan). " +
|
|
105
|
+
"Alpha-2 examples: 'US', 'GB', 'JP'. Both formats work — " +
|
|
106
|
+
"SendSafely converts numeric to alpha-2 internally."),
|
|
107
|
+
},
|
|
108
|
+
annotations: {
|
|
109
|
+
readOnlyHint: false,
|
|
110
|
+
destructiveHint: false,
|
|
111
|
+
idempotentHint: false,
|
|
112
|
+
openWorldHint: true,
|
|
113
|
+
},
|
|
114
|
+
}, safeHandler("add_recipient_with_sms", (args, extra) => handleAddRecipientWithSms(args, extra, ctx, cacheFor)));
|
|
115
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import type { ToolContext, ToolExtra } from "../../context.js";
|
|
4
|
+
import { type CacheFor } from "../../store/packageSecretCache.js";
|
|
5
|
+
export declare function handleAddRecipientsBulk(args: {
|
|
6
|
+
package_id: string;
|
|
7
|
+
emails: string[];
|
|
8
|
+
}, extra: ToolExtra, ctx: ToolContext, cacheFor: CacheFor): Promise<CallToolResult>;
|
|
9
|
+
export declare function registerAddRecipientsBulk(mcp: McpServer, ctx: ToolContext, cacheFor: CacheFor): void;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { jsonError, jsonResult } from "../../jsonResult.js";
|
|
3
|
+
import { MissingPackageSecretsError, } from "../../store/packageSecretCache.js";
|
|
4
|
+
import { buildShareLinkMessage, classifyRecipientAddContext, promptAndApplyWorkspaceRole, tryBuildKeyedLink, } from "../../recipientAddContext.js";
|
|
5
|
+
import { runTool } from "../../runTool.js";
|
|
6
|
+
import { safeHandler } from "../../safeHandler.js";
|
|
7
|
+
import { addRecipients, packageInformation } from "../../sdk/sdkPromise.js";
|
|
8
|
+
export async function handleAddRecipientsBulk(args, extra, ctx, cacheFor) {
|
|
9
|
+
return runTool("add_recipients_bulk", "Failed to add recipients", async () => {
|
|
10
|
+
const client = await ctx.getClient(extra);
|
|
11
|
+
const secrets = cacheFor(extra).get(args.package_id);
|
|
12
|
+
if (!secrets)
|
|
13
|
+
throw new MissingPackageSecretsError(args.package_id);
|
|
14
|
+
const info = await packageInformation(client, args.package_id);
|
|
15
|
+
const context = classifyRecipientAddContext(info);
|
|
16
|
+
if (context.kind === "block_deleted") {
|
|
17
|
+
return jsonError(`Cannot add recipients: package '${args.package_id}' has been ` +
|
|
18
|
+
`deleted (state ${context.state}). Inform the user that the ` +
|
|
19
|
+
"package no longer exists and recipients cannot be added.");
|
|
20
|
+
}
|
|
21
|
+
const result = await addRecipients(client, args.package_id, args.emails, secrets.keyCode);
|
|
22
|
+
const recipients = result.recipients ?? [];
|
|
23
|
+
if (context.kind === "unfinalized_or_unknown") {
|
|
24
|
+
return jsonResult({
|
|
25
|
+
status: "success",
|
|
26
|
+
package_id: args.package_id,
|
|
27
|
+
recipients,
|
|
28
|
+
message: `${args.emails.length} recipient(s) added. Recipients are ` +
|
|
29
|
+
"notified when finalize_package runs.",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const rolePrompt = context.kind === "active_workspace"
|
|
33
|
+
? await promptAndApplyWorkspaceRole(ctx, client, args.package_id, recipients
|
|
34
|
+
.filter((r) => typeof r.recipientId ===
|
|
35
|
+
"string")
|
|
36
|
+
.map((r) => ({
|
|
37
|
+
recipient_id: r.recipientId,
|
|
38
|
+
email: r.email,
|
|
39
|
+
})), `${recipients.length} new collaborator(s)`)
|
|
40
|
+
: undefined;
|
|
41
|
+
const secureLink = tryBuildKeyedLink(client, secrets.keyCode, secrets.packageCode);
|
|
42
|
+
if (!secureLink) {
|
|
43
|
+
const baseMessage = `${args.emails.length} recipient(s) added. SendSafely will NOT ` +
|
|
44
|
+
"auto-notify them, but secure_link could not be reconstructed " +
|
|
45
|
+
"from the cache (see secure_link_unavailable).";
|
|
46
|
+
return jsonResult({
|
|
47
|
+
status: "success",
|
|
48
|
+
package_id: args.package_id,
|
|
49
|
+
recipients,
|
|
50
|
+
package_type: info.packageType,
|
|
51
|
+
package_state: info.state,
|
|
52
|
+
secure_link_unavailable: "Cache entry has no packageCode. Tell the user to fetch the " +
|
|
53
|
+
"keyed link via get_package_information_from_link or " +
|
|
54
|
+
"get_package_keycode and share it with each new recipient.",
|
|
55
|
+
...(rolePrompt ? { role_prompt: rolePrompt } : {}),
|
|
56
|
+
message: rolePrompt?.message
|
|
57
|
+
? `${baseMessage}\n\n${rolePrompt.message}`
|
|
58
|
+
: baseMessage,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
const linkMessage = buildShareLinkMessage(context, `${args.emails.length} recipient(s) (${args.emails.join(", ")})`, secureLink);
|
|
62
|
+
const message = rolePrompt?.message
|
|
63
|
+
? `${linkMessage}\n\n${rolePrompt.message}`
|
|
64
|
+
: linkMessage;
|
|
65
|
+
return jsonResult({
|
|
66
|
+
status: "success",
|
|
67
|
+
package_id: args.package_id,
|
|
68
|
+
recipients,
|
|
69
|
+
package_type: info.packageType,
|
|
70
|
+
package_state: info.state,
|
|
71
|
+
secure_link: secureLink,
|
|
72
|
+
...(rolePrompt ? { role_prompt: rolePrompt } : {}),
|
|
73
|
+
message,
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
export function registerAddRecipientsBulk(mcp, ctx, cacheFor) {
|
|
78
|
+
mcp.registerTool("add_recipients_bulk", {
|
|
79
|
+
title: "Add Recipients (Bulk)",
|
|
80
|
+
description: "Add multiple recipients to a SendSafely package in a single call. " +
|
|
81
|
+
"The package's secret material must be in the server-side cache " +
|
|
82
|
+
"(populated by create_package / create_workspace, " +
|
|
83
|
+
"get_package_information_from_link, or get_package_keycode via a " +
|
|
84
|
+
"registered Trusted Device). " +
|
|
85
|
+
"Same state/type-aware behavior as add_recipient: deleted packages " +
|
|
86
|
+
"are refused; workspaces and already-finalized Transfer/Dropzone " +
|
|
87
|
+
"packages return secure_link + a reminder telling the user to " +
|
|
88
|
+
"share the link with each new recipient (no auto-notification); " +
|
|
89
|
+
"expired packages return a warning that the package needs to be " +
|
|
90
|
+
"un-expired first; unfinalized packages proceed without a " +
|
|
91
|
+
"reminder since finalize_package will handle notifications. On a " +
|
|
92
|
+
"workspace add, the tool also prompts the user ONCE to pick a role " +
|
|
93
|
+
"(default VIEWER; alternatives CONTRIBUTOR or MANAGER); the chosen " +
|
|
94
|
+
"role is applied to every added collaborator via " +
|
|
95
|
+
"update_recipient_role automatically.",
|
|
96
|
+
inputSchema: {
|
|
97
|
+
package_id: z.string().describe("The unique SendSafely package ID."),
|
|
98
|
+
emails: z
|
|
99
|
+
.array(z.string())
|
|
100
|
+
.min(1)
|
|
101
|
+
.describe("Email addresses of the recipients to add."),
|
|
102
|
+
},
|
|
103
|
+
annotations: {
|
|
104
|
+
readOnlyHint: false,
|
|
105
|
+
destructiveHint: false,
|
|
106
|
+
idempotentHint: false,
|
|
107
|
+
openWorldHint: true,
|
|
108
|
+
},
|
|
109
|
+
}, safeHandler("add_recipients_bulk", (args, extra) => handleAddRecipientsBulk(args, extra, ctx, cacheFor)));
|
|
110
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import type { ToolContext, ToolExtra } from "../../context.js";
|
|
4
|
+
import type { CacheFor } from "../../store/packageSecretCache.js";
|
|
5
|
+
export declare function handleCreatePackage(_args: Record<string, never>, extra: ToolExtra, ctx: ToolContext, cacheFor: CacheFor): Promise<CallToolResult>;
|
|
6
|
+
export declare function registerCreatePackage(mcp: McpServer, ctx: ToolContext, cacheFor: CacheFor): void;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsonResult } from "../../jsonResult.js";
|
|
2
|
+
import { buildKeyedLink } from "../../utils/packageLink.js";
|
|
3
|
+
import { runTool } from "../../runTool.js";
|
|
4
|
+
import { safeHandler } from "../../safeHandler.js";
|
|
5
|
+
import { createPackage } from "../../sdk/sdkPromise.js";
|
|
6
|
+
export async function handleCreatePackage(_args, extra, ctx, cacheFor) {
|
|
7
|
+
return runTool("create_package", "Failed to create package", async () => {
|
|
8
|
+
const client = await ctx.getClient(extra);
|
|
9
|
+
const created = await createPackage(client);
|
|
10
|
+
cacheFor(extra).set(created.packageId, {
|
|
11
|
+
keyCode: created.keyCode,
|
|
12
|
+
serverSecret: created.serverSecret,
|
|
13
|
+
packageCode: created.packageCode,
|
|
14
|
+
});
|
|
15
|
+
const approval = await ctx.requireUserApproval(`SendSafely package ${created.packageId} created. Show you the keyed ` +
|
|
16
|
+
"link (secure URL containing the keycode fragment) for this package? " +
|
|
17
|
+
"The link will not grant recipient access until you call " +
|
|
18
|
+
"finalize_package.");
|
|
19
|
+
const includeLink = approval.outcome === "approved";
|
|
20
|
+
const secureLink = includeLink
|
|
21
|
+
? buildKeyedLink(client, created.packageCode, created.keyCode)
|
|
22
|
+
: undefined;
|
|
23
|
+
const approvalErrored = approval.outcome === "error";
|
|
24
|
+
return jsonResult({
|
|
25
|
+
status: "success",
|
|
26
|
+
package_id: created.packageId,
|
|
27
|
+
...(secureLink ? { secure_link: secureLink } : {}),
|
|
28
|
+
...(approvalErrored ? { approval_error: approval.message } : {}),
|
|
29
|
+
message: "Empty package created. Add files with upload_file, recipients with " +
|
|
30
|
+
"add_recipient, and an optional message with add_package_message, " +
|
|
31
|
+
"then call finalize_package to send it." +
|
|
32
|
+
(secureLink
|
|
33
|
+
? " The keyed link above can be shared with the user as a reference."
|
|
34
|
+
: "") +
|
|
35
|
+
(approvalErrored
|
|
36
|
+
? ` The keyed-link approval prompt could not be shown (${approval.message}), ` +
|
|
37
|
+
"so no link is included here; it will be offered again by " +
|
|
38
|
+
"finalize_package or add_recipient."
|
|
39
|
+
: ""),
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
export function registerCreatePackage(mcp, ctx, cacheFor) {
|
|
44
|
+
mcp.registerTool("create_package", {
|
|
45
|
+
title: "Create Package",
|
|
46
|
+
description: "Create a new empty SendSafely package. Returns the package ID, " +
|
|
47
|
+
"and — when the user approves the prompt — the package's keyed " +
|
|
48
|
+
"link (a secure URL with the `#keyCode=` fragment) for the user's " +
|
|
49
|
+
"own reference. On clients without elicitation the link is " +
|
|
50
|
+
"withheld here and returned by finalize_package instead. " +
|
|
51
|
+
"The package is unfinalized: no email is sent and " +
|
|
52
|
+
"no recipient can access it until finalize_package runs, so the " +
|
|
53
|
+
"keyed link here is informational. Secret material (keyCode, " +
|
|
54
|
+
"serverSecret) is cached server-side for downstream send-flow " +
|
|
55
|
+
"tools so the caller does not need to thread it through every " +
|
|
56
|
+
"subsequent tool call.",
|
|
57
|
+
inputSchema: {},
|
|
58
|
+
annotations: {
|
|
59
|
+
readOnlyHint: false,
|
|
60
|
+
destructiveHint: false,
|
|
61
|
+
idempotentHint: false,
|
|
62
|
+
openWorldHint: true,
|
|
63
|
+
},
|
|
64
|
+
}, safeHandler("create_package", (args, extra) => handleCreatePackage(args, extra, ctx, cacheFor)));
|
|
65
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import type { ToolContext, ToolExtra } from "../../context.js";
|
|
4
|
+
import type { CacheFor } from "../../store/packageSecretCache.js";
|
|
5
|
+
interface CreateWorkspaceArgs {
|
|
6
|
+
workspace_name: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function handleCreateWorkspace(args: CreateWorkspaceArgs, extra: ToolExtra, ctx: ToolContext, cacheFor: CacheFor): Promise<CallToolResult>;
|
|
9
|
+
export declare function registerCreateWorkspace(mcp: McpServer, ctx: ToolContext, cacheFor: CacheFor): void;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { jsonResult } from "../../jsonResult.js";
|
|
3
|
+
import { createLinkValidationChecksum } from "../../utils/packageChecksum.js";
|
|
4
|
+
import { buildKeyedLink } from "../../utils/packageLink.js";
|
|
5
|
+
import { runTool } from "../../runTool.js";
|
|
6
|
+
import { safeHandler } from "../../safeHandler.js";
|
|
7
|
+
import { createWorkspace, updatePackage } from "../../sdk/sdkPromise.js";
|
|
8
|
+
export async function handleCreateWorkspace(args, extra, ctx, cacheFor) {
|
|
9
|
+
return runTool("create_workspace", "Failed to create workspace", async () => {
|
|
10
|
+
const client = await ctx.getClient(extra);
|
|
11
|
+
const created = await createWorkspace(client);
|
|
12
|
+
cacheFor(extra).set(created.packageId, {
|
|
13
|
+
keyCode: created.keyCode,
|
|
14
|
+
serverSecret: created.serverSecret,
|
|
15
|
+
packageCode: created.packageCode,
|
|
16
|
+
});
|
|
17
|
+
const checksum = createLinkValidationChecksum(created.keyCode, created.packageCode);
|
|
18
|
+
let workspaceNameSet = false;
|
|
19
|
+
let linkValidationSet = false;
|
|
20
|
+
let postCreateError;
|
|
21
|
+
try {
|
|
22
|
+
await updatePackage(client, created.packageId, {
|
|
23
|
+
label: args.workspace_name,
|
|
24
|
+
checksum,
|
|
25
|
+
});
|
|
26
|
+
workspaceNameSet = true;
|
|
27
|
+
linkValidationSet = true;
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
postCreateError = err instanceof Error ? err.message : String(err);
|
|
31
|
+
}
|
|
32
|
+
const secureLink = buildKeyedLink(client, created.packageCode, created.keyCode);
|
|
33
|
+
const baseMessage = `Workspace "${args.workspace_name}" created. The secure_link above ` +
|
|
34
|
+
"is the workspace's keyed link — surface it to the user. They will " +
|
|
35
|
+
"need to share this exact link with every collaborator they add, " +
|
|
36
|
+
"since SendSafely does NOT send automatic notifications for " +
|
|
37
|
+
"workspace activity. Use create_directory, upload_file, and " +
|
|
38
|
+
"add_recipient to populate the workspace; the keyed link does not " +
|
|
39
|
+
"change.";
|
|
40
|
+
const message = workspaceNameSet && linkValidationSet
|
|
41
|
+
? baseMessage
|
|
42
|
+
: `${baseMessage}\n\nWARNING: the post-create setup call to ` +
|
|
43
|
+
"update_package failed (post_create_error in this response). " +
|
|
44
|
+
(!workspaceNameSet
|
|
45
|
+
? "The workspace was created but its name was NOT set, so it " +
|
|
46
|
+
"will appear with a default label in the SendSafely UI. "
|
|
47
|
+
: "") +
|
|
48
|
+
(!linkValidationSet
|
|
49
|
+
? "The link-validation checksum was also NOT set, so uploads " +
|
|
50
|
+
"to the workspace may be rejected until you retry via " +
|
|
51
|
+
"update_package. "
|
|
52
|
+
: "") +
|
|
53
|
+
"Surface this to the user so they know.";
|
|
54
|
+
return jsonResult({
|
|
55
|
+
status: "success",
|
|
56
|
+
package_id: created.packageId,
|
|
57
|
+
workspace_name: args.workspace_name,
|
|
58
|
+
secure_link: secureLink,
|
|
59
|
+
workspace_name_set: workspaceNameSet,
|
|
60
|
+
link_validation_set: linkValidationSet,
|
|
61
|
+
...(postCreateError ? { post_create_error: postCreateError } : {}),
|
|
62
|
+
message,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export function registerCreateWorkspace(mcp, ctx, cacheFor) {
|
|
67
|
+
mcp.registerTool("create_workspace", {
|
|
68
|
+
title: "Create Workspace",
|
|
69
|
+
description: "Create a new SendSafely Workspace (virtual data room) with the " +
|
|
70
|
+
"given name. Workspaces are persistent, end-to-end encrypted data " +
|
|
71
|
+
"rooms that support directory hierarchies (use create_directory) " +
|
|
72
|
+
"in addition to root-level files. " +
|
|
73
|
+
"Implementation detail (so the agent can reason about failure " +
|
|
74
|
+
"modes correctly): the SDK's createWorkspace endpoint does NOT " +
|
|
75
|
+
"accept a name. After the SDK creates the empty workspace, this " +
|
|
76
|
+
"tool makes one follow-up update_package call that sets BOTH the " +
|
|
77
|
+
"user-supplied workspace name (as `label`) AND the link-" +
|
|
78
|
+
"validation checksum derived from keyCode + packageCode (required " +
|
|
79
|
+
"for SendSafely to accept uploads). " +
|
|
80
|
+
"Response always includes secure_link, the workspace's keyed link " +
|
|
81
|
+
"(`{host}/receive/?packageCode=…#keyCode=…`). Surface this link " +
|
|
82
|
+
"to the user — they will need to share it with every collaborator " +
|
|
83
|
+
"they add, because SendSafely does NOT auto-notify workspace " +
|
|
84
|
+
"collaborators. " +
|
|
85
|
+
"If the post-create update_package call fails, the workspace " +
|
|
86
|
+
"still exists, but workspace_name_set and/or link_validation_set " +
|
|
87
|
+
"will be false in the response and post_create_error will explain " +
|
|
88
|
+
"why. Surface that failure to the user.",
|
|
89
|
+
inputSchema: {
|
|
90
|
+
workspace_name: z
|
|
91
|
+
.string()
|
|
92
|
+
.min(1)
|
|
93
|
+
.max(255)
|
|
94
|
+
.describe("REQUIRED. Display name for the new workspace (1–255 " +
|
|
95
|
+
"characters). Shown to collaborators in the SendSafely UI. " +
|
|
96
|
+
"SendSafely validates the character set server-side. " +
|
|
97
|
+
"Always ask the user what the workspace should be called " +
|
|
98
|
+
"before invoking this tool — do not invent a default."),
|
|
99
|
+
},
|
|
100
|
+
annotations: {
|
|
101
|
+
readOnlyHint: false,
|
|
102
|
+
destructiveHint: false,
|
|
103
|
+
idempotentHint: false,
|
|
104
|
+
openWorldHint: true,
|
|
105
|
+
},
|
|
106
|
+
}, safeHandler("create_workspace", (args, extra) => handleCreateWorkspace(args, extra, ctx, cacheFor)));
|
|
107
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import type { ToolContext, ToolExtra } from "../../context.js";
|
|
4
|
+
import type { CacheFor } from "../../store/packageSecretCache.js";
|
|
5
|
+
export interface DeletePackageArgs {
|
|
6
|
+
package_id: string;
|
|
7
|
+
proceed_without_prompt?: boolean | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare function handleDeletePackage(args: DeletePackageArgs, extra: ToolExtra, ctx: ToolContext, cacheFor: CacheFor): Promise<CallToolResult>;
|
|
10
|
+
export declare function registerDeletePackage(mcp: McpServer, ctx: ToolContext, cacheFor: CacheFor): void;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { approvalGateError, CONSENT_FALLBACK_INSTRUCTIONS, proceedWithoutPromptSchema, } from "../../approval.js";
|
|
3
|
+
import { jsonResult } from "../../jsonResult.js";
|
|
4
|
+
import { runTool } from "../../runTool.js";
|
|
5
|
+
import { safeHandler } from "../../safeHandler.js";
|
|
6
|
+
import { deletePackage } from "../../sdk/sdkPromise.js";
|
|
7
|
+
export async function handleDeletePackage(args, extra, ctx, cacheFor) {
|
|
8
|
+
return runTool("delete_package", "Failed to delete package", async () => {
|
|
9
|
+
const client = await ctx.getClient(extra);
|
|
10
|
+
const approval = await ctx.requireUserApproval(`Delete SendSafely package ${args.package_id}? This cannot be undone.`);
|
|
11
|
+
const denied = approvalGateError(approval, "permanently delete this SendSafely package", {
|
|
12
|
+
proceedWithoutPrompt: args.proceed_without_prompt,
|
|
13
|
+
});
|
|
14
|
+
if (denied)
|
|
15
|
+
return denied;
|
|
16
|
+
await deletePackage(client, args.package_id);
|
|
17
|
+
cacheFor(extra).delete(args.package_id);
|
|
18
|
+
return jsonResult({ status: "success", package_id: args.package_id });
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export function registerDeletePackage(mcp, ctx, cacheFor) {
|
|
22
|
+
mcp.registerTool("delete_package", {
|
|
23
|
+
title: "Delete Package",
|
|
24
|
+
description: "Permanently delete a SendSafely package. Recipients lose access " +
|
|
25
|
+
"immediately. Requires user approval — this is irreversible. " +
|
|
26
|
+
"Approval is collected via MCP elicitation. " +
|
|
27
|
+
CONSENT_FALLBACK_INSTRUCTIONS,
|
|
28
|
+
inputSchema: {
|
|
29
|
+
package_id: z.string().describe("The unique SendSafely package ID."),
|
|
30
|
+
proceed_without_prompt: proceedWithoutPromptSchema,
|
|
31
|
+
},
|
|
32
|
+
annotations: {
|
|
33
|
+
readOnlyHint: false,
|
|
34
|
+
destructiveHint: true,
|
|
35
|
+
idempotentHint: true,
|
|
36
|
+
openWorldHint: true,
|
|
37
|
+
},
|
|
38
|
+
}, safeHandler("delete_package", (args, extra) => handleDeletePackage(args, extra, ctx, cacheFor)));
|
|
39
|
+
}
|
package/node_modules/@sendsafely/mcp-tools-core/dist/tools/stdio/downloadFileFromDirectory.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import type { ToolContext, ToolExtra } from "../../context.js";
|
|
4
|
+
import { type CacheFor } from "../../store/packageSecretCache.js";
|
|
5
|
+
export interface DownloadFileFromDirectoryArgs {
|
|
6
|
+
package_id: string;
|
|
7
|
+
directory_id: string;
|
|
8
|
+
file_id: string;
|
|
9
|
+
proceed_without_prompt?: boolean | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare function handleDownloadFileFromDirectory(args: DownloadFileFromDirectoryArgs, extra: ToolExtra, ctx: ToolContext, cacheFor: CacheFor): Promise<CallToolResult>;
|
|
12
|
+
export declare function registerDownloadFileFromDirectory(mcp: McpServer, ctx: ToolContext, cacheFor: CacheFor): void;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { approvalGateError, CONSENT_FALLBACK_INSTRUCTIONS, proceedWithoutPromptSchema, } from "../../approval.js";
|
|
4
|
+
import { jsonError, jsonResult } from "../../jsonResult.js";
|
|
5
|
+
import { MissingPackageSecretsError, } from "../../store/packageSecretCache.js";
|
|
6
|
+
import { runTool } from "../../runTool.js";
|
|
7
|
+
import { safeHandler } from "../../safeHandler.js";
|
|
8
|
+
import { assertSafePackageId, preparePackageDir } from "../../utils/packageDir.js";
|
|
9
|
+
import { sanitizeFilename } from "../../utils/sanitizeFilename.js";
|
|
10
|
+
import { downloadFileFromDirectoryToPath, getFileInformation } from "../../sdk/sdkPromise.js";
|
|
11
|
+
export async function handleDownloadFileFromDirectory(args, extra, ctx, cacheFor) {
|
|
12
|
+
return runTool("download_file_from_directory", "Failed to download file", async () => {
|
|
13
|
+
const client = await ctx.getClient(extra);
|
|
14
|
+
const secrets = cacheFor(extra).get(args.package_id);
|
|
15
|
+
if (!secrets)
|
|
16
|
+
throw new MissingPackageSecretsError(args.package_id);
|
|
17
|
+
const fileInfo = await getFileInformation(client, args.package_id, args.directory_id, args.file_id);
|
|
18
|
+
const rawName = String(fileInfo.fileName ?? args.file_id);
|
|
19
|
+
const safeName = sanitizeFilename(rawName);
|
|
20
|
+
const downloadDir = ctx.getDownloadDir(extra);
|
|
21
|
+
const packageDir = path.join(downloadDir, assertSafePackageId(args.package_id));
|
|
22
|
+
const approval = await ctx.requireUserApproval(`Download and decrypt "${safeName}" from SendSafely package ` +
|
|
23
|
+
`${args.package_id} to ${packageDir}?\n\n` +
|
|
24
|
+
"A decrypted copy will be written to the local download directory.");
|
|
25
|
+
const denied = approvalGateError(approval, "decrypt this file to the local download directory", {
|
|
26
|
+
proceedWithoutPrompt: args.proceed_without_prompt,
|
|
27
|
+
abortPrefix: "Download aborted",
|
|
28
|
+
});
|
|
29
|
+
if (denied)
|
|
30
|
+
return denied;
|
|
31
|
+
const realDir = await preparePackageDir(downloadDir, args.package_id);
|
|
32
|
+
const targetPath = path.resolve(realDir, safeName);
|
|
33
|
+
if (targetPath !== realDir && !targetPath.startsWith(realDir + path.sep)) {
|
|
34
|
+
process.stderr.write(`SECURITY: rejected file '${rawName}' (id=${args.file_id}) — ` +
|
|
35
|
+
`resolved path escapes package directory\n`);
|
|
36
|
+
return jsonError("File rejected: resolved path escapes the package download directory.", { file_name: rawName, file_id: args.file_id });
|
|
37
|
+
}
|
|
38
|
+
await downloadFileFromDirectoryToPath(client, args.package_id, args.directory_id, args.file_id, secrets.keyCode, { path: realDir, fileName: safeName });
|
|
39
|
+
return jsonResult({
|
|
40
|
+
status: "success",
|
|
41
|
+
package_id: args.package_id,
|
|
42
|
+
directory_id: args.directory_id,
|
|
43
|
+
file_id: args.file_id,
|
|
44
|
+
local_path: targetPath,
|
|
45
|
+
file_name: safeName,
|
|
46
|
+
original_file_name: rawName,
|
|
47
|
+
message: "File downloaded successfully. You MUST ask the user for explicit " +
|
|
48
|
+
"permission before reading the file contents.",
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export function registerDownloadFileFromDirectory(mcp, ctx, cacheFor) {
|
|
53
|
+
mcp.registerTool("download_file_from_directory", {
|
|
54
|
+
title: "Download File From Directory",
|
|
55
|
+
description: "Download and decrypt a single file from a workspace directory. " +
|
|
56
|
+
"The package's Keycode must be in the server-side cache — populated " +
|
|
57
|
+
"by get_package_information_from_link when a keyed link is " +
|
|
58
|
+
"available, or by get_package_keycode when a Trusted Device " +
|
|
59
|
+
"private key is registered for the user. " +
|
|
60
|
+
"(get_package_information by ID does not populate the cache.) " +
|
|
61
|
+
"Output is saved to <download_dir>/<package_id>/<file_name> with " +
|
|
62
|
+
"the same filename sanitization as download_package_files. " +
|
|
63
|
+
"ACCESSING CONTENTS: the returned local_path is a location in the " +
|
|
64
|
+
"SERVER's managed download directory. When this server runs in a " +
|
|
65
|
+
"sandbox or on a different host, that path is very likely NOT " +
|
|
66
|
+
"reachable by your own file-reading tools — do not assume you can " +
|
|
67
|
+
"open it directly, and do not report the download as unreadable if " +
|
|
68
|
+
"your file tools cannot find it. read_downloaded_file is the ONLY " +
|
|
69
|
+
"reliable way to access the decrypted contents (it can read the " +
|
|
70
|
+
"file even when the path is outside your sandbox). Always route " +
|
|
71
|
+
"reads through read_downloaded_file using this local_path. " +
|
|
72
|
+
"IMPORTANT: Before doing so, you MUST ask the user for explicit " +
|
|
73
|
+
"permission to read the file contents. Do not read files without " +
|
|
74
|
+
"user authorization. " +
|
|
75
|
+
"CONSENT: this tool writes a decrypted file to local disk, so it " +
|
|
76
|
+
"requires user approval, collected via MCP elicitation. " +
|
|
77
|
+
CONSENT_FALLBACK_INSTRUCTIONS,
|
|
78
|
+
inputSchema: {
|
|
79
|
+
package_id: z.string().describe("The unique SendSafely package ID."),
|
|
80
|
+
directory_id: z.string().describe("Workspace directory ID."),
|
|
81
|
+
file_id: z.string().describe("The unique file ID inside the directory."),
|
|
82
|
+
proceed_without_prompt: proceedWithoutPromptSchema,
|
|
83
|
+
},
|
|
84
|
+
annotations: {
|
|
85
|
+
readOnlyHint: false,
|
|
86
|
+
destructiveHint: true,
|
|
87
|
+
idempotentHint: true,
|
|
88
|
+
openWorldHint: true,
|
|
89
|
+
},
|
|
90
|
+
}, safeHandler("download_file_from_directory", (args, extra) => handleDownloadFileFromDirectory(args, extra, ctx, cacheFor)));
|
|
91
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import type { ToolContext, ToolExtra } from "../../context.js";
|
|
4
|
+
import { type CacheFor } from "../../store/packageSecretCache.js";
|
|
5
|
+
export declare function extractKeyCode(link: string): string | null;
|
|
6
|
+
export interface DownloadPackageFilesArgs {
|
|
7
|
+
link?: string | undefined;
|
|
8
|
+
package_id?: string | undefined;
|
|
9
|
+
proceed_without_prompt?: boolean | undefined;
|
|
10
|
+
}
|
|
11
|
+
export declare function handleDownloadPackageFiles(args: DownloadPackageFilesArgs, extra: ToolExtra, ctx: ToolContext, cacheFor?: CacheFor): Promise<CallToolResult>;
|
|
12
|
+
export declare function registerDownloadPackageFiles(mcp: McpServer, ctx: ToolContext, cacheFor?: CacheFor): void;
|