@loopops/mcp-server 3.8.0 → 3.9.1
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.
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper for tools that accept "either CSV content as text, or a path to
|
|
3
|
+
* a CSV file." The MCP server runs locally as a subprocess on the user's
|
|
4
|
+
* machine, so file IO is available; this lets operators say "process the
|
|
5
|
+
* file at ~/Downloads/foo.csv" without a separate Read step in chat.
|
|
6
|
+
*
|
|
7
|
+
* Both `import_accounts_csv` and `process_approvals_csv` use this. The
|
|
8
|
+
* tRPC procedures behind them still take CSV content — this is purely
|
|
9
|
+
* a wrapper convenience.
|
|
10
|
+
*/
|
|
11
|
+
export type CsvInput = {
|
|
12
|
+
/** CSV content as a string (when operator pastes it inline). */
|
|
13
|
+
csv?: string;
|
|
14
|
+
/** Filesystem path (absolute, ~-prefixed, or relative to cwd). */
|
|
15
|
+
csvPath?: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Resolve to CSV content. Throws with operator-friendly messages on
|
|
19
|
+
* misuse (both unset, both set, file missing, file empty).
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveCsvInput(input: CsvInput): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Common Zod-friendly description for the csvPath field. Tool authors
|
|
24
|
+
* pass this as the `.describe()` argument so the wording stays
|
|
25
|
+
* consistent across tools.
|
|
26
|
+
*/
|
|
27
|
+
export declare const CSV_PATH_DESCRIPTION = "Path to a CSV file on the operator's machine. Absolute, ~-prefixed (e.g. `~/Downloads/foo.csv`), or relative to the MCP subprocess's working directory. Either `csv` or `csvPath` is required (not both).";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper for tools that accept "either CSV content as text, or a path to
|
|
3
|
+
* a CSV file." The MCP server runs locally as a subprocess on the user's
|
|
4
|
+
* machine, so file IO is available; this lets operators say "process the
|
|
5
|
+
* file at ~/Downloads/foo.csv" without a separate Read step in chat.
|
|
6
|
+
*
|
|
7
|
+
* Both `import_accounts_csv` and `process_approvals_csv` use this. The
|
|
8
|
+
* tRPC procedures behind them still take CSV content — this is purely
|
|
9
|
+
* a wrapper convenience.
|
|
10
|
+
*/
|
|
11
|
+
import { readFile } from "node:fs/promises";
|
|
12
|
+
import { homedir } from "node:os";
|
|
13
|
+
import { isAbsolute, resolve } from "node:path";
|
|
14
|
+
/**
|
|
15
|
+
* Resolve to CSV content. Throws with operator-friendly messages on
|
|
16
|
+
* misuse (both unset, both set, file missing, file empty).
|
|
17
|
+
*/
|
|
18
|
+
export async function resolveCsvInput(input) {
|
|
19
|
+
const hasContent = input.csv !== undefined && input.csv.length > 0;
|
|
20
|
+
const hasPath = input.csvPath !== undefined && input.csvPath.length > 0;
|
|
21
|
+
if (!hasContent && !hasPath) {
|
|
22
|
+
throw new Error("Provide either `csv` (the CSV content as text) or `csvPath` (a path to a CSV file).");
|
|
23
|
+
}
|
|
24
|
+
if (hasContent && hasPath) {
|
|
25
|
+
throw new Error("Provide either `csv` or `csvPath`, not both. Pick one — content for paste-in, path for an on-disk file.");
|
|
26
|
+
}
|
|
27
|
+
if (hasContent)
|
|
28
|
+
return input.csv;
|
|
29
|
+
// Path branch. Expand `~` to $HOME, resolve relative paths from
|
|
30
|
+
// the current working directory of the MCP subprocess.
|
|
31
|
+
let path = input.csvPath;
|
|
32
|
+
if (path.startsWith("~/")) {
|
|
33
|
+
path = resolve(homedir(), path.slice(2));
|
|
34
|
+
}
|
|
35
|
+
else if (!isAbsolute(path)) {
|
|
36
|
+
path = resolve(process.cwd(), path);
|
|
37
|
+
}
|
|
38
|
+
let content;
|
|
39
|
+
try {
|
|
40
|
+
content = await readFile(path, "utf-8");
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
44
|
+
throw new Error(`Could not read CSV file at \`${path}\`: ${reason}`);
|
|
45
|
+
}
|
|
46
|
+
if (content.length === 0) {
|
|
47
|
+
throw new Error(`File at \`${path}\` is empty.`);
|
|
48
|
+
}
|
|
49
|
+
return content;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Common Zod-friendly description for the csvPath field. Tool authors
|
|
53
|
+
* pass this as the `.describe()` argument so the wording stays
|
|
54
|
+
* consistent across tools.
|
|
55
|
+
*/
|
|
56
|
+
export const CSV_PATH_DESCRIPTION = "Path to a CSV file on the operator's machine. Absolute, ~-prefixed (e.g. `~/Downloads/foo.csv`), or relative to the MCP subprocess's working directory. Either `csv` or `csvPath` is required (not both).";
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { z } from "zod";
|
|
18
18
|
import { trpcMutation, trpcQuery } from "../api-client.js";
|
|
19
|
+
import { CSV_PATH_DESCRIPTION, resolveCsvInput } from "./_csv-input.js";
|
|
19
20
|
import { safeTool } from "./_helpers.js";
|
|
20
21
|
export function registerAccountMasterTools(server, allowed) {
|
|
21
22
|
if (allowed.has("account_lookup")) {
|
|
@@ -82,8 +83,9 @@ export function registerAccountMasterTools(server, allowed) {
|
|
|
82
83
|
].join(" "), {
|
|
83
84
|
csv: z
|
|
84
85
|
.string()
|
|
85
|
-
.
|
|
86
|
-
.describe("CSV content as text. First row must be the header. Accepts the same header aliases as the account-master-csv-import.mjs script."),
|
|
86
|
+
.optional()
|
|
87
|
+
.describe("CSV content as text. First row must be the header. Accepts the same header aliases as the account-master-csv-import.mjs script. Provide this OR csvPath, not both."),
|
|
88
|
+
csvPath: z.string().optional().describe(CSV_PATH_DESCRIPTION),
|
|
87
89
|
source: z
|
|
88
90
|
.string()
|
|
89
91
|
.min(1)
|
|
@@ -99,7 +101,12 @@ export function registerAccountMasterTools(server, allowed) {
|
|
|
99
101
|
.boolean()
|
|
100
102
|
.optional()
|
|
101
103
|
.describe("If true, drain the queue via the matcher immediately after insert."),
|
|
102
|
-
}, safeTool(async (input) =>
|
|
104
|
+
}, safeTool(async (input) => {
|
|
105
|
+
const csv = await resolveCsvInput(input);
|
|
106
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
107
|
+
const { csv: _csv, csvPath: _csvPath, ...rest } = input;
|
|
108
|
+
return trpcMutation("mcp.importAccountsCsv", { csv, ...rest });
|
|
109
|
+
}));
|
|
103
110
|
}
|
|
104
111
|
if (allowed.has("override_account_attribute")) {
|
|
105
112
|
server.tool("override_account_attribute", [
|
package/dist/tools/sfdc-sync.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
import { trpcMutation, trpcQuery } from "../api-client.js";
|
|
14
|
+
import { CSV_PATH_DESCRIPTION, resolveCsvInput } from "./_csv-input.js";
|
|
14
15
|
import { safeTool } from "./_helpers.js";
|
|
15
16
|
const accountIdentifierShape = {
|
|
16
17
|
accountId: z
|
|
@@ -57,6 +58,62 @@ export function registerSfdcSyncTools(server, allowed) {
|
|
|
57
58
|
.describe("Why this account is being approved (e.g. 'Tier-1 strategic prospect', 'Existing customer expansion target', 'Q3 ABM list'). Stored in the lifecycle event payload for audit."),
|
|
58
59
|
}, safeTool(async (input) => trpcMutation("mcp.approveInitialDeployment", input)));
|
|
59
60
|
}
|
|
61
|
+
if (allowed.has("export_pending_approvals")) {
|
|
62
|
+
server.tool("export_pending_approvals", [
|
|
63
|
+
"Export the pending_initial_deployment_review queue as CSV text. Each row carries the",
|
|
64
|
+
"account_id (required for round-trip), key context fields (name, domain, country, segment,",
|
|
65
|
+
"score, band, queued_since), and two empty operator-input columns: `approve` and `reason`.",
|
|
66
|
+
"",
|
|
67
|
+
"Workflow:",
|
|
68
|
+
" 1. Run this tool — copy the CSV text from the response",
|
|
69
|
+
" 2. Paste into Excel / Google Sheets / Numbers, edit the approve + reason columns",
|
|
70
|
+
" 3. Set approve=yes (or y/true) on rows you want to push to SF; leave others blank or =no",
|
|
71
|
+
" 4. Add a reason on each approve=yes row (audit log; required, ≥3 chars)",
|
|
72
|
+
" 5. Run `process_approvals_csv` with the edited CSV content",
|
|
73
|
+
"",
|
|
74
|
+
"See docs/csv-templates/pending-approvals.csv for the canonical shape.",
|
|
75
|
+
].join("\n"), {
|
|
76
|
+
limit: z
|
|
77
|
+
.number()
|
|
78
|
+
.int()
|
|
79
|
+
.positive()
|
|
80
|
+
.max(1000)
|
|
81
|
+
.optional()
|
|
82
|
+
.describe("Max accounts in the export (1-1000). Default: 200."),
|
|
83
|
+
}, safeTool(async (input) => trpcQuery("mcp.exportPendingApprovals", input)));
|
|
84
|
+
}
|
|
85
|
+
if (allowed.has("process_approvals_csv")) {
|
|
86
|
+
server.tool("process_approvals_csv", [
|
|
87
|
+
"Bulk-approve accounts from a CSV exported via `export_pending_approvals`. For each row",
|
|
88
|
+
"where `approve = yes/y/true`, calls approveInitialDeployment with the row's reason —",
|
|
89
|
+
"writes the same lifecycle event (with reason + snapshot payload) as a single-account",
|
|
90
|
+
"approval would.",
|
|
91
|
+
"",
|
|
92
|
+
"Provide EITHER `csv` (paste content inline) OR `csvPath` (path to a file on the",
|
|
93
|
+
"operator's machine; absolute or `~/`-prefixed). The MCP subprocess reads files locally,",
|
|
94
|
+
"so `csvPath` works for both Claude Code and Claude Desktop.",
|
|
95
|
+
"",
|
|
96
|
+
"Validation:",
|
|
97
|
+
" - account_id must currently be in pending_initial_deployment_review (else row fails)",
|
|
98
|
+
" - reason must be ≥3 chars on approve=yes rows (else row fails)",
|
|
99
|
+
" - approve != yes → row is skipped (account stays in the queue)",
|
|
100
|
+
"",
|
|
101
|
+
"Failures don't abort the batch — they're collected and surfaced in the response. Re-run",
|
|
102
|
+
"the corrected CSV any time; already-approved accounts return 'not_in_review' and are",
|
|
103
|
+
"reported as failures (idempotent — no double-approval).",
|
|
104
|
+
"",
|
|
105
|
+
"See docs/csv-templates/pending-approvals.csv for the canonical shape.",
|
|
106
|
+
].join("\n"), {
|
|
107
|
+
csv: z
|
|
108
|
+
.string()
|
|
109
|
+
.optional()
|
|
110
|
+
.describe("CSV content (header row + data rows). Required headers: account_id, approve, reason. Other columns from export_pending_approvals are tolerated. Provide this OR csvPath, not both."),
|
|
111
|
+
csvPath: z.string().optional().describe(CSV_PATH_DESCRIPTION),
|
|
112
|
+
}, safeTool(async (input) => {
|
|
113
|
+
const csv = await resolveCsvInput(input);
|
|
114
|
+
return trpcMutation("mcp.processApprovalsCsv", { csv });
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
60
117
|
if (allowed.has("deployment_status")) {
|
|
61
118
|
server.tool("deployment_status", "Top-line counts of accounts in each deployment lifecycle state (pending review, pending update, deployed, deployment_failed, sync_drift). Includes a sample of the initial-review queue so ops can spot-check what's waiting for approval.", {
|
|
62
119
|
sampleSize: z
|