@snokam/mcp-salesforce 1.124.0 → 1.125.0
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/dist/index.js +2 -302
- package/dist/salesforce-client.d.ts +1 -0
- package/dist/salesforce-client.js +44 -0
- package/dist/tools/accounts.d.ts +2 -0
- package/dist/tools/accounts.js +47 -0
- package/dist/tools/contacts.d.ts +2 -0
- package/dist/tools/contacts.js +133 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +8 -0
- package/dist/tools/pipeline.d.ts +2 -0
- package/dist/tools/pipeline.js +71 -0
- package/package.json +1 -1
- package/src/index.ts +2 -387
- package/src/salesforce-client.ts +60 -0
- package/src/tools/accounts.ts +60 -0
- package/src/tools/contacts.ts +175 -0
- package/src/tools/index.ts +10 -0
- package/src/tools/pipeline.ts +92 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { sfQuery } from "../salesforce-client.js";
|
|
4
|
+
|
|
5
|
+
export function registerPipelineTools(server: McpServer): void {
|
|
6
|
+
server.tool(
|
|
7
|
+
"search_leads",
|
|
8
|
+
"Search for leads in Salesforce",
|
|
9
|
+
{
|
|
10
|
+
query: z.string().describe("Search query"),
|
|
11
|
+
status: z
|
|
12
|
+
.string()
|
|
13
|
+
.optional()
|
|
14
|
+
.describe("Lead status filter (e.g., Open, Working, Closed)"),
|
|
15
|
+
limit: z.number().default(10).describe("Maximum number of results"),
|
|
16
|
+
},
|
|
17
|
+
async ({ query, status, limit }) => {
|
|
18
|
+
const escapedQuery = query.replace(/'/g, "\\'");
|
|
19
|
+
let whereClause = `Name LIKE '%${escapedQuery}%' OR Email LIKE '%${escapedQuery}%' OR Company LIKE '%${escapedQuery}%'`;
|
|
20
|
+
if (status) {
|
|
21
|
+
whereClause = `(${whereClause}) AND Status = '${status}'`;
|
|
22
|
+
}
|
|
23
|
+
const soql = `
|
|
24
|
+
SELECT Id, Name, Email, Phone, Company, Status, LeadSource, CreatedDate
|
|
25
|
+
FROM Lead
|
|
26
|
+
WHERE ${whereClause}
|
|
27
|
+
ORDER BY CreatedDate DESC
|
|
28
|
+
LIMIT ${limit}
|
|
29
|
+
`;
|
|
30
|
+
const records = await sfQuery(soql);
|
|
31
|
+
return {
|
|
32
|
+
content: [{ type: "text", text: JSON.stringify(records, null, 2) }],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
server.tool(
|
|
38
|
+
"get_opportunities",
|
|
39
|
+
"Get opportunities from Salesforce pipeline",
|
|
40
|
+
{
|
|
41
|
+
stage: z
|
|
42
|
+
.string()
|
|
43
|
+
.optional()
|
|
44
|
+
.describe(
|
|
45
|
+
"Filter by stage (e.g., Prospecting, Negotiation, Closed Won)"
|
|
46
|
+
),
|
|
47
|
+
accountId: z.string().optional().describe("Filter by account ID"),
|
|
48
|
+
limit: z.number().default(20).describe("Maximum number of results"),
|
|
49
|
+
},
|
|
50
|
+
async ({ stage, accountId, limit }) => {
|
|
51
|
+
const conditions: string[] = [];
|
|
52
|
+
if (stage) conditions.push(`StageName = '${stage}'`);
|
|
53
|
+
if (accountId) conditions.push(`AccountId = '${accountId}'`);
|
|
54
|
+
|
|
55
|
+
const whereClause =
|
|
56
|
+
conditions.length > 0 ? `WHERE ${conditions.join(" AND ")}` : "";
|
|
57
|
+
const soql = `
|
|
58
|
+
SELECT Id, Name, StageName, Amount, CloseDate, Account.Name, Owner.Name, Probability
|
|
59
|
+
FROM Opportunity
|
|
60
|
+
${whereClause}
|
|
61
|
+
ORDER BY CloseDate ASC
|
|
62
|
+
LIMIT ${limit}
|
|
63
|
+
`;
|
|
64
|
+
const records = await sfQuery(soql);
|
|
65
|
+
return {
|
|
66
|
+
content: [{ type: "text", text: JSON.stringify(records, null, 2) }],
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
server.tool(
|
|
72
|
+
"soql_query",
|
|
73
|
+
"Execute a custom SOQL query against Salesforce (read-only)",
|
|
74
|
+
{
|
|
75
|
+
query: z.string().describe("SOQL query to execute"),
|
|
76
|
+
},
|
|
77
|
+
async ({ query }) => {
|
|
78
|
+
if (!query.trim().toUpperCase().startsWith("SELECT")) {
|
|
79
|
+
return {
|
|
80
|
+
content: [
|
|
81
|
+
{ type: "text", text: "Error: Only SELECT queries are allowed" },
|
|
82
|
+
],
|
|
83
|
+
isError: true,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const records = await sfQuery(query);
|
|
87
|
+
return {
|
|
88
|
+
content: [{ type: "text", text: JSON.stringify(records, null, 2) }],
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
}
|