findymail-mcp 0.1.14 → 0.1.16
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 +31 -3
- package/package.json +1 -1
- package/src/api.js +146 -4
- package/src/http.js +201 -17
- package/src/tools.js +290 -64
package/README.md
CHANGED
|
@@ -15,13 +15,39 @@ This MCP server exposes the following tools:
|
|
|
15
15
|
| `enrich_company` | Get company data from domain, LinkedIn URL, or name |
|
|
16
16
|
| `reverse_email_lookup` | Find person info from an email |
|
|
17
17
|
| `lookalike_search` | Find similar companies from a seed domain using vector similarity |
|
|
18
|
-
| `generate_lead_list` | AI-powered
|
|
18
|
+
| `generate_lead_list` | AI-powered company discovery from a natural language description of your ideal customer |
|
|
19
19
|
| `get_lead_list_results` | Retrieve results from a previously generated lead list |
|
|
20
|
+
| `list_exclusion_lists` | List the exclusion lists you own or that are shared with your team |
|
|
21
|
+
| `create_exclusion_list` | Create a new exclusion list |
|
|
22
|
+
| `list_exclusion_domains` | List the domains held by an exclusion list, with their ids |
|
|
23
|
+
| `add_exclusion_domains` | Add domains to an exclusion list (or to your global exclusions) |
|
|
24
|
+
| `remove_exclusion_domains` | Remove domains from an exclusion list, by domain id |
|
|
25
|
+
|
|
26
|
+
### Exclusion lists
|
|
27
|
+
|
|
28
|
+
An exclusion list holds company domains that should never show up in search results — competitors, existing
|
|
29
|
+
customers, companies you already contacted. `generate_lead_list` and `lookalike_search` both accept
|
|
30
|
+
`exclusion_list_ids` to filter them out, and `generate_lead_list` additionally accepts
|
|
31
|
+
`add_to_exclusion_list_id` to automatically add every exported domain to a list, so a later search never
|
|
32
|
+
returns the same companies twice.
|
|
33
|
+
|
|
34
|
+
For `exclusion_list_ids`:
|
|
35
|
+
|
|
36
|
+
| Value | Behaviour |
|
|
37
|
+
|-------|-----------|
|
|
38
|
+
| *(omitted)* | Every exclusion source you can reach is applied — this is the default |
|
|
39
|
+
| `[0]` | Same as omitting it: your global exclusions **plus every list you own or share**, not just the global one |
|
|
40
|
+
| `[-1]` or `[]` | Exclusion filtering is disabled |
|
|
41
|
+
| `[12, 15]` | Only those lists are applied |
|
|
42
|
+
| mixed | Don't: `[0, 12]` ignores `12` and filters on everything, `[-1, 12]` disables filtering entirely |
|
|
43
|
+
|
|
44
|
+
`lookalike_search` takes a parameter with the same name but **not** the same semantics: it has no
|
|
45
|
+
`[0]`/`[-1]` markers, and an empty value means no filtering at all.
|
|
20
46
|
|
|
21
47
|
## Prerequisites
|
|
22
48
|
|
|
23
49
|
- Node.js 18+
|
|
24
|
-
- A Findymail API key ([get one here](https://app.findymail.com/
|
|
50
|
+
- A Findymail API key ([get one here](https://app.findymail.com/user/api-tokens))
|
|
25
51
|
|
|
26
52
|
## Installation
|
|
27
53
|
|
|
@@ -115,10 +141,12 @@ Once configured, you can ask your AI assistant:
|
|
|
115
141
|
- "Get company information for stripe.com"
|
|
116
142
|
- "Find me 10 marketing managers at SaaS companies in San Francisco"
|
|
117
143
|
- "Find companies similar to stripe.com in the same country"
|
|
144
|
+
- "Create an exclusion list called Competitors and add stripe.com and brex.com to it"
|
|
145
|
+
- "Find 50 fintech companies in Europe, excluding my Competitors list, and add the results to it so I don't get them again"
|
|
118
146
|
|
|
119
147
|
## API Key
|
|
120
148
|
|
|
121
|
-
Get your API key from [Findymail Settings](https://app.findymail.com/
|
|
149
|
+
Get your API key from [Findymail Settings](https://app.findymail.com/user/api-tokens).
|
|
122
150
|
|
|
123
151
|
Each API call consumes credits from your Findymail account.
|
|
124
152
|
|
package/package.json
CHANGED
package/src/api.js
CHANGED
|
@@ -31,6 +31,127 @@ export function resolveApiKey(extra) {
|
|
|
31
31
|
throw new Error("API key is required: set FINDYMAIL_API_KEY or pass Authorization header");
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
// Laravel's abort(403) and abort(404) send an empty `message`, so a failure can
|
|
35
|
+
// carry no reason at all. Give the agent something actionable per status code.
|
|
36
|
+
const STATUS_REASONS = {
|
|
37
|
+
400: "Bad request — the API could not process the parameters as sent",
|
|
38
|
+
401: "Unauthorized — the API key is missing, invalid or expired. Keys are managed at https://app.findymail.com/user/api-tokens",
|
|
39
|
+
402: "Out of credits — your Findymail account has no credits left for this call",
|
|
40
|
+
403: "Forbidden — none of the resources you targeted belong to you, or your account may not edit them",
|
|
41
|
+
404: "Not found — the resource does not exist",
|
|
42
|
+
422: "Invalid parameters — the API rejected the request payload",
|
|
43
|
+
429: "Too many requests — rate limit reached",
|
|
44
|
+
500: "Findymail server error — the call never completed, retry it",
|
|
45
|
+
502: "Findymail is unreachable — retry in a few seconds",
|
|
46
|
+
503: "Findymail is temporarily unavailable — retry in a few seconds",
|
|
47
|
+
504: "Findymail timed out — retry in a few seconds",
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// Running out mid-run is the failure an agent is most likely to hit, and the
|
|
51
|
+
// one it can least afford to read as a generic error: say which pool is empty
|
|
52
|
+
// and where to refill it, so the caller stops instead of retrying the loop.
|
|
53
|
+
const CREDIT_GUIDANCE =
|
|
54
|
+
"Finder credits (email, phone, company, employee and lead-list lookups) and verifier credits (`verify_email`) are separate pools, so one being empty leaves the other usable. Top up or change plan at https://app.findymail.com/subscription.";
|
|
55
|
+
|
|
56
|
+
function isCreditFailure(status, reason) {
|
|
57
|
+
return status === 402 || /\bcredits?\b|\bquota\b/i.test(reason ?? "");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// The messages under a field are usually an array of strings, but nested rules
|
|
61
|
+
// answer with an object keyed by sub-field — flatten whatever shape arrives
|
|
62
|
+
// rather than letting it stringify to [object Object].
|
|
63
|
+
function flatten(value) {
|
|
64
|
+
if (Array.isArray(value)) return value.flatMap(flatten);
|
|
65
|
+
if (value && typeof value === "object") return Object.values(value).flatMap(flatten);
|
|
66
|
+
return value === undefined || value === null || value === "" ? [] : [String(value)];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Laravel validation answers with {"message": "...", "errors": {field: [...]}},
|
|
70
|
+
// and the field list is the only part that says what to change.
|
|
71
|
+
function validationDetail(payload) {
|
|
72
|
+
const errors = payload.errors;
|
|
73
|
+
if (!errors || typeof errors !== "object") return "";
|
|
74
|
+
|
|
75
|
+
const fields = Object.entries(errors)
|
|
76
|
+
.map(([field, messages]) => `${field}: ${flatten(messages).join(" ")}`)
|
|
77
|
+
.filter(Boolean)
|
|
78
|
+
.join("; ");
|
|
79
|
+
|
|
80
|
+
return fields ? ` Rejected parameters — ${fields}` : "";
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// RFC 7231 allows Retry-After to be either delay-seconds or an HTTP-date, and
|
|
84
|
+
// pasting the date form straight in produced "Retry after Wed, 21 Oct 2015
|
|
85
|
+
// 07:28:00 GMTs". Normalise both to seconds from now.
|
|
86
|
+
function retryDetail(response) {
|
|
87
|
+
if (response.status !== 429) return "";
|
|
88
|
+
|
|
89
|
+
const retryAfter = response.headers.get("retry-after")?.trim();
|
|
90
|
+
if (!retryAfter) return " Back off before retrying.";
|
|
91
|
+
|
|
92
|
+
if (/^\d+$/.test(retryAfter)) return ` Retry after ${retryAfter}s.`;
|
|
93
|
+
|
|
94
|
+
const at = Date.parse(retryAfter);
|
|
95
|
+
if (Number.isNaN(at)) return ` Retry after ${retryAfter}.`;
|
|
96
|
+
|
|
97
|
+
return ` Retry after ${Math.max(0, Math.round((at - Date.now()) / 1000))}s.`;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// A gateway, a WAF or a PHP fatal answers with HTML rather than JSON, and a
|
|
101
|
+
// JSON body can carry its reason under a key we do not know. Either way the
|
|
102
|
+
// body is the only clue left, so pass it through instead of the bare status.
|
|
103
|
+
function bodyDetail(raw) {
|
|
104
|
+
const text = raw.replace(/<[^>]*>/g, " ").replace(/\s+/g, " ").trim();
|
|
105
|
+
if (!text) return "";
|
|
106
|
+
return ` Response body: ${text.length > 300 ? `${text.slice(0, 300)}…` : text}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Turn a failed response into an Error carrying the best reason available.
|
|
111
|
+
* The status is attached so callers can add their own context.
|
|
112
|
+
*/
|
|
113
|
+
// Echoing the body is only worth it when we could not read a reason out of it:
|
|
114
|
+
// a JSON error that simply carried an empty `message` adds nothing.
|
|
115
|
+
function showBody(reason, parsedAsJson, payload) {
|
|
116
|
+
if (reason) return false;
|
|
117
|
+
if (!parsedAsJson) return true;
|
|
118
|
+
return Object.keys(payload).some(key => !["message", "error", "errors"].includes(key));
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function apiError(response) {
|
|
122
|
+
const raw = await response.text().catch(() => "");
|
|
123
|
+
|
|
124
|
+
let payload = {};
|
|
125
|
+
let parsedAsJson = false;
|
|
126
|
+
try {
|
|
127
|
+
const parsed = raw ? JSON.parse(raw) : {};
|
|
128
|
+
if (parsed && typeof parsed === "object") {
|
|
129
|
+
payload = parsed;
|
|
130
|
+
parsedAsJson = true;
|
|
131
|
+
}
|
|
132
|
+
} catch {
|
|
133
|
+
// Not JSON — bodyDetail below surfaces it verbatim.
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Some endpoints report the reason under `error` rather than `message`, and
|
|
137
|
+
// an aborted request reports an empty string under both.
|
|
138
|
+
const reason = [payload.message, payload.error]
|
|
139
|
+
.find(value => typeof value === "string" && value.trim() !== "")
|
|
140
|
+
?.trim();
|
|
141
|
+
|
|
142
|
+
const message = [
|
|
143
|
+
`${reason || STATUS_REASONS[response.status] || "API error"} (HTTP ${response.status})`,
|
|
144
|
+
response.status === 422 ? validationDetail(payload) : "",
|
|
145
|
+
isCreditFailure(response.status, reason) ? ` ${CREDIT_GUIDANCE}` : "",
|
|
146
|
+
retryDetail(response),
|
|
147
|
+
showBody(reason, parsedAsJson, payload) ? bodyDetail(raw) : "",
|
|
148
|
+
].join("");
|
|
149
|
+
|
|
150
|
+
const error = new Error(message);
|
|
151
|
+
error.status = response.status;
|
|
152
|
+
return error;
|
|
153
|
+
}
|
|
154
|
+
|
|
34
155
|
/**
|
|
35
156
|
* Make authenticated POST request to Findymail API
|
|
36
157
|
*/
|
|
@@ -48,8 +169,7 @@ export async function apiPost(endpoint, body = {}, apiKey) {
|
|
|
48
169
|
});
|
|
49
170
|
|
|
50
171
|
if (!response.ok) {
|
|
51
|
-
|
|
52
|
-
throw new Error(error.message || `API error: ${response.status}`);
|
|
172
|
+
throw await apiError(response);
|
|
53
173
|
}
|
|
54
174
|
|
|
55
175
|
return response.json();
|
|
@@ -70,8 +190,30 @@ export async function apiGet(endpoint, apiKey) {
|
|
|
70
190
|
});
|
|
71
191
|
|
|
72
192
|
if (!response.ok) {
|
|
73
|
-
|
|
74
|
-
|
|
193
|
+
throw await apiError(response);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return response.json();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Make authenticated DELETE request to Findymail API
|
|
201
|
+
*/
|
|
202
|
+
export async function apiDelete(endpoint, body = {}, apiKey) {
|
|
203
|
+
if (!apiKey) apiKey = getApiKey();
|
|
204
|
+
|
|
205
|
+
const response = await fetch(`${API_BASE_URL}${endpoint}`, {
|
|
206
|
+
method: "DELETE",
|
|
207
|
+
headers: {
|
|
208
|
+
"Authorization": `Bearer ${apiKey}`,
|
|
209
|
+
"Content-Type": "application/json",
|
|
210
|
+
"Accept": "application/json",
|
|
211
|
+
},
|
|
212
|
+
body: JSON.stringify(body),
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
if (!response.ok) {
|
|
216
|
+
throw await apiError(response);
|
|
75
217
|
}
|
|
76
218
|
|
|
77
219
|
return response.json();
|
package/src/http.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
3
4
|
import { createRequire } from "node:module";
|
|
4
5
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
6
|
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
7
|
+
import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
6
8
|
import { log } from "./api.js";
|
|
7
9
|
import { registerTools } from "./tools.js";
|
|
8
10
|
|
|
@@ -25,8 +27,80 @@ const AUTH_SERVER = process.env.AUTH_SERVER || "https://app.findymail.com";
|
|
|
25
27
|
|
|
26
28
|
const app = express();
|
|
27
29
|
|
|
28
|
-
// Store active transports by session
|
|
29
|
-
|
|
30
|
+
// Store active transports by session. A session pins a transport *and* a full
|
|
31
|
+
// MCP server, so it must be reclaimed on all three paths: the client closes it,
|
|
32
|
+
// it goes idle, or we hit the ceiling.
|
|
33
|
+
const SESSION_TTL_MS = Number(process.env.MCP_SESSION_TTL_MS) || 30 * 60 * 1000;
|
|
34
|
+
const MAX_SESSIONS = Number(process.env.MCP_MAX_SESSIONS) || 300;
|
|
35
|
+
const SWEEP_INTERVAL_MS = Number(process.env.MCP_SESSION_SWEEP_MS) || 60 * 1000;
|
|
36
|
+
const MAX_BODY_BYTES = Number(process.env.MCP_MAX_BODY_BYTES) || 4 * 1024 * 1024;
|
|
37
|
+
|
|
38
|
+
// A Map, not an object: iteration order is insertion order and touchSession
|
|
39
|
+
// re-inserts on every hit, so the first entry is always least recently used.
|
|
40
|
+
const sessions = new Map();
|
|
41
|
+
|
|
42
|
+
function touchSession(sessionId) {
|
|
43
|
+
const session = sessions.get(sessionId);
|
|
44
|
+
if (!session) return undefined;
|
|
45
|
+
session.lastSeen = Date.now();
|
|
46
|
+
sessions.delete(sessionId);
|
|
47
|
+
sessions.set(sessionId, session);
|
|
48
|
+
return session;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Only a request that is being answered protects a session from reclaim, and
|
|
52
|
+
// the standalone GET stream is not one: a well-behaved Streamable HTTP client
|
|
53
|
+
// holds it open for the life of the session, so counting it would exempt every
|
|
54
|
+
// normal client from the sweep and turn MAX_SESSIONS into a wall with no
|
|
55
|
+
// reclaim path. A quiet stream is cut once the session passes its TTL — clients
|
|
56
|
+
// recover through the 404 path below by re-initializing.
|
|
57
|
+
function trackRequest(session, req, res) {
|
|
58
|
+
if (req.method === "GET") return;
|
|
59
|
+
session.pending += 1;
|
|
60
|
+
res.once("close", () => {
|
|
61
|
+
session.pending -= 1;
|
|
62
|
+
session.lastSeen = Date.now();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function dropSession(sessionId, reason) {
|
|
67
|
+
const session = sessions.get(sessionId);
|
|
68
|
+
if (!session) return;
|
|
69
|
+
sessions.delete(sessionId);
|
|
70
|
+
log(`Session closed (${reason}): ${sessionId} — ${sessions.size} live`);
|
|
71
|
+
session.server.close().catch(error => log(`Close error: ${error.message}`));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Is there room, or at least one session we could reclaim to make room? Asked
|
|
75
|
+
// before the handshake so a full server refuses early, and answered without
|
|
76
|
+
// evicting anyone: a handshake the SDK goes on to reject must not cost a live
|
|
77
|
+
// client its session.
|
|
78
|
+
function canMakeRoom() {
|
|
79
|
+
if (sessions.size < MAX_SESSIONS) return true;
|
|
80
|
+
for (const session of sessions.values()) {
|
|
81
|
+
if (session.pending === 0) return true;
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Evict least-recently-used idle sessions. Called only once a handshake has
|
|
87
|
+
// actually succeeded. Never cuts a client mid-request.
|
|
88
|
+
function makeRoom() {
|
|
89
|
+
for (const [sessionId, session] of sessions) {
|
|
90
|
+
if (sessions.size < MAX_SESSIONS) return;
|
|
91
|
+
if (session.pending === 0) dropSession(sessionId, "capacity");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const sweeper = setInterval(() => {
|
|
96
|
+
const cutoff = Date.now() - SESSION_TTL_MS;
|
|
97
|
+
for (const [sessionId, session] of sessions) {
|
|
98
|
+
if (session.pending === 0 && session.lastSeen < cutoff) {
|
|
99
|
+
dropSession(sessionId, "idle");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}, SWEEP_INTERVAL_MS);
|
|
103
|
+
sweeper.unref();
|
|
30
104
|
|
|
31
105
|
// JSON parsing only for non-MCP routes (MCP transport handles its own parsing)
|
|
32
106
|
app.use((req, res, next) => {
|
|
@@ -105,25 +179,125 @@ app.use("/mcp", (req, res, next) => {
|
|
|
105
179
|
app.all("/mcp", async (req, res) => {
|
|
106
180
|
log(`MCP request: ${req.method}`);
|
|
107
181
|
|
|
108
|
-
const sessionId = req.headers["mcp-session-id"]
|
|
109
|
-
log(`Session: ${sessionId}`);
|
|
182
|
+
const sessionId = req.headers["mcp-session-id"];
|
|
110
183
|
|
|
111
|
-
|
|
184
|
+
if (sessionId) {
|
|
185
|
+
const session = touchSession(sessionId);
|
|
186
|
+
if (!session) {
|
|
187
|
+
// 404 is the one answer MCP clients know how to recover from: they drop
|
|
188
|
+
// the session and re-initialize. Minting a blank transport under an id we
|
|
189
|
+
// never issued got a permanent 400 "Server not initialized" instead, and
|
|
190
|
+
// the phantom transport stayed in memory for good.
|
|
191
|
+
log(`Unknown session: ${sessionId}`);
|
|
192
|
+
return res.status(404).json({
|
|
193
|
+
jsonrpc: "2.0",
|
|
194
|
+
error: { code: -32001, message: "Session not found" },
|
|
195
|
+
id: null,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
log(`Session: ${sessionId}`);
|
|
199
|
+
trackRequest(session, req, res);
|
|
200
|
+
return handOff(session.transport, req, res);
|
|
201
|
+
}
|
|
112
202
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
203
|
+
// Everything below builds a session. Only an initialize handshake may do
|
|
204
|
+
// that: any other session-less request used to reach makeRoom() and evict a
|
|
205
|
+
// healthy session per call — an authenticated caller, or a client that simply
|
|
206
|
+
// dropped the header on a retry, could clear out other people's sessions —
|
|
207
|
+
// before spawning a server the SDK then rejected. Read the body here and
|
|
208
|
+
// hand it to the transport, which cannot re-read a consumed stream.
|
|
209
|
+
const body = await readJsonBody(req);
|
|
210
|
+
|
|
211
|
+
if (!isInitializeRequest(body)) {
|
|
212
|
+
log(`Session-less ${req.method} that is not an initialize — rejected`);
|
|
213
|
+
return res.status(400).json({
|
|
214
|
+
jsonrpc: "2.0",
|
|
215
|
+
error: { code: -32000, message: "Bad Request: Mcp-Session-Id header is required" },
|
|
216
|
+
id: null,
|
|
118
217
|
});
|
|
119
|
-
|
|
218
|
+
}
|
|
120
219
|
|
|
121
|
-
|
|
122
|
-
log(
|
|
220
|
+
if (!canMakeRoom()) {
|
|
221
|
+
log(`Refusing new session: ${sessions.size} sessions, all busy`);
|
|
222
|
+
return res.status(503).json({
|
|
223
|
+
jsonrpc: "2.0",
|
|
224
|
+
error: { code: -32000, message: "Server busy: too many active sessions" },
|
|
225
|
+
id: null,
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
log("Creating new transport and server...");
|
|
230
|
+
const server = createMcpServer();
|
|
231
|
+
|
|
232
|
+
const transport = new StreamableHTTPServerTransport({
|
|
233
|
+
// Server-generated and unguessable. The id used to be `session_${Date.now()}`
|
|
234
|
+
// taken from the client header, so it was both predictable and pickable by
|
|
235
|
+
// whoever asked.
|
|
236
|
+
sessionIdGenerator: () => randomUUID(),
|
|
237
|
+
|
|
238
|
+
// Only a handshake the SDK actually accepted gets registered, and only here
|
|
239
|
+
// do we spend another client's session to make room for it.
|
|
240
|
+
onsessioninitialized: (newSessionId) => {
|
|
241
|
+
makeRoom();
|
|
242
|
+
const session = { transport, server, lastSeen: Date.now(), pending: 0 };
|
|
243
|
+
sessions.set(newSessionId, session);
|
|
244
|
+
trackRequest(session, req, res);
|
|
245
|
+
log(`Session opened: ${newSessionId} — ${sessions.size} live`);
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
// Must be assigned before connect(): Protocol.connect() chains onto whatever
|
|
250
|
+
// handler is already in place, so setting it afterwards would replace the
|
|
251
|
+
// SDK's own teardown instead of adding to it.
|
|
252
|
+
transport.onclose = () => {
|
|
253
|
+
const openId = transport.sessionId;
|
|
254
|
+
if (openId && sessions.delete(openId)) {
|
|
255
|
+
log(`Session closed (transport): ${openId} — ${sessions.size} live`);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
await server.connect(transport);
|
|
260
|
+
log("Server connected");
|
|
261
|
+
await handOff(transport, req, res, body);
|
|
262
|
+
|
|
263
|
+
// connect() already ran, so a handshake the SDK rejected leaves a live server
|
|
264
|
+
// holding a live transport. Leaving those to the garbage collector is the
|
|
265
|
+
// very thing this file set out to stop, so close what never became a session.
|
|
266
|
+
if (!transport.sessionId || !sessions.has(transport.sessionId)) {
|
|
267
|
+
log("Handshake rejected — closing the orphaned server");
|
|
268
|
+
await server.close().catch(error => log(`Close error: ${error.message}`));
|
|
123
269
|
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// The transport parses the body itself, but it cannot do that once we have read
|
|
273
|
+
// the stream to find out whether this is an initialize — so parse it here and
|
|
274
|
+
// pass it down through handleRequest's parsedBody argument.
|
|
275
|
+
function readJsonBody(req) {
|
|
276
|
+
return new Promise(resolve => {
|
|
277
|
+
let raw = "";
|
|
278
|
+
req.setEncoding("utf8");
|
|
279
|
+
req.on("data", chunk => {
|
|
280
|
+
raw += chunk;
|
|
281
|
+
if (raw.length > MAX_BODY_BYTES) {
|
|
282
|
+
raw = "";
|
|
283
|
+
req.destroy();
|
|
284
|
+
resolve(undefined);
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
req.on("end", () => {
|
|
288
|
+
try {
|
|
289
|
+
resolve(raw ? JSON.parse(raw) : undefined);
|
|
290
|
+
} catch {
|
|
291
|
+
resolve(undefined);
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
req.on("error", () => resolve(undefined));
|
|
295
|
+
});
|
|
296
|
+
}
|
|
124
297
|
|
|
298
|
+
async function handOff(transport, req, res, parsedBody) {
|
|
125
299
|
try {
|
|
126
|
-
await transport.handleRequest(req, res);
|
|
300
|
+
await transport.handleRequest(req, res, parsedBody);
|
|
127
301
|
log("Request handled");
|
|
128
302
|
} catch (error) {
|
|
129
303
|
log(`Error: ${error.message}`);
|
|
@@ -131,7 +305,7 @@ app.all("/mcp", async (req, res) => {
|
|
|
131
305
|
res.status(500).json({ error: error.message });
|
|
132
306
|
}
|
|
133
307
|
}
|
|
134
|
-
}
|
|
308
|
+
}
|
|
135
309
|
|
|
136
310
|
// =============================================================================
|
|
137
311
|
// Health check
|
|
@@ -149,8 +323,18 @@ app.get("/health", (req, res) => {
|
|
|
149
323
|
// Start server
|
|
150
324
|
// =============================================================================
|
|
151
325
|
|
|
152
|
-
app.listen(PORT, () => {
|
|
326
|
+
const server = app.listen(PORT, () => {
|
|
153
327
|
log(`MCP Server listening on ${BASE_URL}`);
|
|
154
328
|
log(`MCP endpoint: ${BASE_URL}/mcp`);
|
|
155
329
|
log(`Health check: ${BASE_URL}/health`);
|
|
156
|
-
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
// A client that vanishes without closing its TCP connection — a laptop going to
|
|
333
|
+
// sleep, a NAT dropping the mapping — leaves its SSE stream open forever. No
|
|
334
|
+
// "close" event fires, so activeRequests never drops back to zero and the
|
|
335
|
+
// session escapes both the idle sweep and the capacity eviction: enough of them
|
|
336
|
+
// and every new session is refused for good. Node cuts nothing on its own here
|
|
337
|
+
// (`server.timeout` is 0 by default and applies to the request, not the stream),
|
|
338
|
+
// so lean on TCP keepalive to notice the dead peer.
|
|
339
|
+
const KEEPALIVE_MS = Number(process.env.MCP_TCP_KEEPALIVE_MS) || 60 * 1000;
|
|
340
|
+
server.on("connection", socket => socket.setKeepAlive(true, KEEPALIVE_MS));
|
package/src/tools.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { log, apiPost, apiGet, resolveApiKey, formatResponse, formatError } from "./api.js";
|
|
2
|
+
import { log, apiPost, apiGet, apiDelete, resolveApiKey, formatResponse, formatError } from "./api.js";
|
|
3
|
+
|
|
4
|
+
// Every tool reaches the Findymail API over the network, so `openWorldHint` is
|
|
5
|
+
// true throughout. The lookups below are marked `readOnlyHint: false` even
|
|
6
|
+
// though they touch nothing in the user's account: `readOnlyHint` is what lets
|
|
7
|
+
// a client auto-approve a call, and a model looping a finder over a few hundred
|
|
8
|
+
// rows would spend real credits with no confirmation. Only the calls that cost
|
|
9
|
+
// nothing are read-only.
|
|
10
|
+
const READS = { readOnlyHint: true, openWorldHint: true };
|
|
11
|
+
const LOOKUP = { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true };
|
|
12
|
+
|
|
13
|
+
// `title` became a top-level field on Tool in the 2025-06-18 spec, but clients
|
|
14
|
+
// and review tooling written against the earlier shape still read it out of
|
|
15
|
+
// `annotations` — declare it in both places from the one source.
|
|
16
|
+
function toolConfig({ title, description, inputSchema = {}, annotations }) {
|
|
17
|
+
return { title, description, inputSchema, annotations: { title, ...annotations } };
|
|
18
|
+
}
|
|
3
19
|
|
|
4
20
|
/**
|
|
5
21
|
* Register all Findymail tools on an MCP server
|
|
@@ -8,14 +24,18 @@ export function registerTools(server) {
|
|
|
8
24
|
// ===========================================================================
|
|
9
25
|
// Tool: find_email
|
|
10
26
|
// ===========================================================================
|
|
11
|
-
server.
|
|
27
|
+
server.registerTool(
|
|
12
28
|
"find_email",
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
29
|
+
toolConfig({
|
|
30
|
+
title: "Find Email",
|
|
31
|
+
description: "Find a verified B2B email address for one person. Identify them either by full name plus company domain, or by LinkedIn profile URL — one of those two combinations is required, and the LinkedIn URL takes precedence when both are supplied. Returns the contact with the email address, the person's name and the company domain. Addresses are verified before being returned, so a person whose address cannot be verified comes back as not found rather than as a guess. Use it when you need one specific person's email, and chain it after `find_employees` (passing the returned name + domain, or the returned LinkedIn URL) to put emails on a list of contacts. Costs 1 finder credit per email found; a lookup that finds nothing is not charged.",
|
|
32
|
+
inputSchema: {
|
|
33
|
+
name: z.string().optional().describe("Person's full name (required with domain)"),
|
|
34
|
+
domain: z.string().optional().describe("Company domain (required with name)"),
|
|
35
|
+
linkedin_url: z.string().optional().describe("LinkedIn profile URL (alternative to name+domain)"),
|
|
36
|
+
},
|
|
37
|
+
annotations: LOOKUP,
|
|
38
|
+
}),
|
|
19
39
|
async (params, extra) => {
|
|
20
40
|
log(`find_email: ${JSON.stringify(params)}`);
|
|
21
41
|
|
|
@@ -47,14 +67,18 @@ export function registerTools(server) {
|
|
|
47
67
|
// ===========================================================================
|
|
48
68
|
// Tool: find_employees
|
|
49
69
|
// ===========================================================================
|
|
50
|
-
server.
|
|
70
|
+
server.registerTool(
|
|
51
71
|
"find_employees",
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
72
|
+
toolConfig({
|
|
73
|
+
title: "Find Employees",
|
|
74
|
+
description: "Find employees at a company by job title. Given a company website or domain and a list of target job titles, returns matching contacts with name, job title, company and LinkedIn URL. Email addresses are not part of the response: to get a verified email for a contact, pass the returned name and domain — or the returned LinkedIn URL — to `find_email`. Use it to build a shortlist of people to reach at a known company; to discover the companies themselves, use `generate_lead_list` or `lookalike_search` first. Costs 1 finder credit per contact returned.",
|
|
75
|
+
inputSchema: {
|
|
76
|
+
website: z.string().describe("Company website or domain (e.g., \"findymail.com\")"),
|
|
77
|
+
job_titles: z.array(z.string()).describe("Target job titles (max 10, each max 50 characters, e.g., [\"CTO\", \"VP Engineering\"])"),
|
|
78
|
+
count: z.number().optional().default(1).describe("Number of contacts to return (min: 1, max: 5, default: 1)"),
|
|
79
|
+
},
|
|
80
|
+
annotations: LOOKUP,
|
|
81
|
+
}),
|
|
58
82
|
async ({ website, job_titles, count = 1 }, extra) => {
|
|
59
83
|
log(`find_employees: website="${website}" job_titles=${JSON.stringify(job_titles)} count=${count}`);
|
|
60
84
|
|
|
@@ -79,12 +103,16 @@ export function registerTools(server) {
|
|
|
79
103
|
// ===========================================================================
|
|
80
104
|
// Tool: find_phone
|
|
81
105
|
// ===========================================================================
|
|
82
|
-
server.
|
|
106
|
+
server.registerTool(
|
|
83
107
|
"find_phone",
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
108
|
+
toolConfig({
|
|
109
|
+
title: "Find Phone Number",
|
|
110
|
+
description: "Find the phone number(s) of a contact, identified by their LinkedIn profile URL. Use it once you already have a LinkedIn URL for the person — returned by `find_employees` or `reverse_email_lookup`, or supplied by the user — and need to reach them by phone; a phone number cannot be looked up from a name or an email address. Returns the contact with the mobile and direct-dial numbers found, or an empty result when no number is available. Costs 10 finder credits per phone number found; a lookup that finds nothing is not charged.",
|
|
111
|
+
inputSchema: {
|
|
112
|
+
linkedin_url: z.string().describe("LinkedIn profile URL (required)"),
|
|
113
|
+
},
|
|
114
|
+
annotations: LOOKUP,
|
|
115
|
+
}),
|
|
88
116
|
async ({ linkedin_url }, extra) => {
|
|
89
117
|
log(`find_phone: ${linkedin_url}`);
|
|
90
118
|
|
|
@@ -101,12 +129,16 @@ export function registerTools(server) {
|
|
|
101
129
|
// ===========================================================================
|
|
102
130
|
// Tool: verify_email
|
|
103
131
|
// ===========================================================================
|
|
104
|
-
server.
|
|
132
|
+
server.registerTool(
|
|
105
133
|
"verify_email",
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
134
|
+
toolConfig({
|
|
135
|
+
title: "Verify Email",
|
|
136
|
+
description: "Check whether an email address is deliverable, without sending anything to it. Use it on addresses that came from elsewhere (a CRM export, a spreadsheet, the user) before adding them to an outreach sequence. Addresses returned by `find_email` and `generate_lead_list` are already verified and do not need a second pass. Costs 1 verifier credit per address checked — verifier credits are a separate pool from the finder credits the lookup tools spend.",
|
|
137
|
+
inputSchema: {
|
|
138
|
+
email: z.string().describe("Email address to verify"),
|
|
139
|
+
},
|
|
140
|
+
annotations: LOOKUP,
|
|
141
|
+
}),
|
|
110
142
|
async ({ email }, extra) => {
|
|
111
143
|
log(`verify_email: ${email}`);
|
|
112
144
|
|
|
@@ -123,14 +155,18 @@ export function registerTools(server) {
|
|
|
123
155
|
// ===========================================================================
|
|
124
156
|
// Tool: enrich_company
|
|
125
157
|
// ===========================================================================
|
|
126
|
-
server.
|
|
158
|
+
server.registerTool(
|
|
127
159
|
"enrich_company",
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
160
|
+
toolConfig({
|
|
161
|
+
title: "Enrich Company",
|
|
162
|
+
description: "Look up firmographic data for one company. Identify it by domain, by LinkedIn company page URL, or by name — at least one is required, and the domain is used first when several are given, since company names are ambiguous. Returns the company profile: name, domain, description, industry, employee-count range, location and social profiles. Use it to qualify a single company before prospecting it, or to fill in a company whose domain came out of `find_employees` or `reverse_email_lookup`. To find many companies at once, use `lookalike_search` or `generate_lead_list` instead. Costs 1 finder credit per company returned.",
|
|
163
|
+
inputSchema: {
|
|
164
|
+
domain: z.string().optional().describe("Company domain (e.g., findymail.com)"),
|
|
165
|
+
linkedin_url: z.string().optional().describe("LinkedIn company page URL"),
|
|
166
|
+
name: z.string().optional().describe("Company name"),
|
|
167
|
+
},
|
|
168
|
+
annotations: LOOKUP,
|
|
169
|
+
}),
|
|
134
170
|
async (params, extra) => {
|
|
135
171
|
log(`enrich_company: ${JSON.stringify(params)}`);
|
|
136
172
|
|
|
@@ -157,13 +193,17 @@ export function registerTools(server) {
|
|
|
157
193
|
// ===========================================================================
|
|
158
194
|
// Tool: reverse_email_lookup
|
|
159
195
|
// ===========================================================================
|
|
160
|
-
server.
|
|
196
|
+
server.registerTool(
|
|
161
197
|
"reverse_email_lookup",
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
198
|
+
toolConfig({
|
|
199
|
+
title: "Reverse Email Lookup",
|
|
200
|
+
description: "Identify the person behind an email address. Returns their LinkedIn profile URL; set with_profile to also return the full LinkedIn profile (name, job title, company etc.). Use it to put a name and a company on an address that arrived without context — an inbound reply, a CRM row, an imported list — and chain the returned LinkedIn URL into `find_phone` when you need to reach them by phone. It says nothing about deliverability: use `verify_email` for that. Costs 1 finder credit per contact found, or 2 finder credits when with_profile returns complete profile data; an address that matches nobody is not charged.",
|
|
201
|
+
inputSchema: {
|
|
202
|
+
email: z.string().describe("Email address to lookup"),
|
|
203
|
+
with_profile: z.boolean().optional().default(false).describe("Include full LinkedIn profile data"),
|
|
204
|
+
},
|
|
205
|
+
annotations: LOOKUP,
|
|
206
|
+
}),
|
|
167
207
|
async ({ email, with_profile }, extra) => {
|
|
168
208
|
log(`reverse_email_lookup: ${email}`);
|
|
169
209
|
|
|
@@ -180,16 +220,20 @@ export function registerTools(server) {
|
|
|
180
220
|
// ===========================================================================
|
|
181
221
|
// Tool: lookalike_search
|
|
182
222
|
// ===========================================================================
|
|
183
|
-
server.
|
|
223
|
+
server.registerTool(
|
|
184
224
|
"lookalike_search",
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
225
|
+
toolConfig({
|
|
226
|
+
title: "Find Lookalike Companies",
|
|
227
|
+
description: "Find companies similar to a given seed company. Given a company domain (e.g. \"stripe.com\"), returns a list of lookalike companies that share similar business characteristics using semantic similarity. Results can be filtered by same country and/or same company size. Exclusion lists can be provided to remove already-known companies from results. Costs 1 finder credit per 10 results returned.",
|
|
228
|
+
inputSchema: {
|
|
229
|
+
seed: z.string().describe("The domain or URL of the seed company to find lookalikes for (e.g. \"stripe.com\" or \"https://www.stripe.com/pricing\"). URLs are automatically resolved to their root domain."),
|
|
230
|
+
same_country: z.boolean().optional().default(false).describe("When true, only return companies located in the same country as the seed company"),
|
|
231
|
+
same_size: z.boolean().optional().default(false).describe("When true, only return companies with a similar employee count range as the seed company"),
|
|
232
|
+
limit: z.number().optional().default(100).describe("Maximum number of results to return (min: 1, max: 10,000)"),
|
|
233
|
+
exclusion_list_ids: z.array(z.number()).optional().default([]).describe("IDs of exclusion lists whose domains should be removed from results. Unlike `generate_lead_list`, this parameter does NOT accept the [0] / [-1] markers — pass real list IDs only (from `list_exclusion_lists`), or leave it empty for no filtering."),
|
|
234
|
+
},
|
|
235
|
+
annotations: LOOKUP,
|
|
236
|
+
}),
|
|
193
237
|
async (params, extra) => {
|
|
194
238
|
const {
|
|
195
239
|
seed,
|
|
@@ -224,18 +268,26 @@ export function registerTools(server) {
|
|
|
224
268
|
// ===========================================================================
|
|
225
269
|
// Tool: generate_lead_list
|
|
226
270
|
// ===========================================================================
|
|
227
|
-
server.
|
|
271
|
+
server.registerTool(
|
|
228
272
|
"generate_lead_list",
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
273
|
+
toolConfig({
|
|
274
|
+
title: "Generate Lead List",
|
|
275
|
+
description: "Start a company discovery run from a natural language description of an ideal customer profile. This is a semantic search, not a database lookup, so describe the kind of company you are looking for rather than listing exact filter values (e.g. \"SaaS companies in the USA with 50+ employees\", \"tech startups offering insurance services in NYC\"). Use 'targeted' mode to return only companies strictly matching the description (narrower) or `broad` mode to return companies loosely matching the description (broader). Matching companies can be enriched with contacts, verified email addresses and phone numbers. The run is asynchronous and this call returns only a hash: pass that hash to `get_lead_list_results` to follow progress and retrieve the results. Credit cost depends on the options chosen — 1 finder credit per 10 companies in 'broad' mode or 1 per company in 'targeted' mode, plus 1 per contact found, 1 per email found and 10 per phone number found.",
|
|
276
|
+
inputSchema: {
|
|
277
|
+
query: z.string().describe("Natural language description of what you're looking for (max 1000 characters)"),
|
|
278
|
+
limit: z.number().optional().default(100).describe("Maximum number of results (default: 100, max: 5000)"),
|
|
279
|
+
mode: z.enum(["broad", "targeted"]).optional().default("broad").describe("'broad' = fast export (1 credit/10 companies), 'targeted' = AI-qualified results (1 credit/company)"),
|
|
280
|
+
find_contact: z.boolean().optional().default(true).describe("Search for contacts at each company (+1 credit/contact found)"),
|
|
281
|
+
target_job_titles: z.array(z.string()).optional().default(["CEO"]).describe("Job titles to target when find_contact is true (e.g., ['CEO', 'CTO', 'VP Sales'])"),
|
|
282
|
+
find_email: z.boolean().optional().default(true).describe("Enrich contacts with email (+1 credit/email found). Requires find_contact: true"),
|
|
283
|
+
find_phone: z.boolean().optional().default(false).describe("Enrich contacts with phone (+10 credits/phone found). Requires find_contact: true"),
|
|
284
|
+
exclusion_list_ids: z.array(z.number()).optional().describe("IDs of exclusion lists whose domains must be filtered out of the results. Omit this parameter to keep the default behaviour. [0] means \"every exclusion source you can reach\" (your global exclusions plus every list you own or share) — NOT just the global one. [-1] disables exclusion filtering entirely, and so does an empty array. Never mix these markers with real list IDs: [0, 12] silently ignores 12 and filters on everything, and [-1, 12] silently disables filtering altogether. Pass either exactly [0], exactly [-1], or real list IDs — never a mixture. Get them from `list_exclusion_lists`."),
|
|
285
|
+
add_to_exclusion_list_id: z.number().optional().describe("ID of an exclusion list to automatically add every exported company domain to, so later searches never return them again. The domains are written once, at the very end of the export: nothing is added if the export fails, and if that final write itself fails the export is still reported as successful — check with `list_exclusion_domains` when it matters. Only pass an ID returned by `list_exclusion_lists`, or create one with `create_exclusion_list`."),
|
|
286
|
+
},
|
|
287
|
+
// Each call starts a new run and spends credits again, so it is not
|
|
288
|
+
// idempotent: an identical query is a second export, not a replay.
|
|
289
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
290
|
+
}),
|
|
239
291
|
async (params, extra) => {
|
|
240
292
|
const {
|
|
241
293
|
query,
|
|
@@ -245,6 +297,8 @@ export function registerTools(server) {
|
|
|
245
297
|
target_job_titles = ["CEO"],
|
|
246
298
|
find_email = true,
|
|
247
299
|
find_phone = false,
|
|
300
|
+
exclusion_list_ids,
|
|
301
|
+
add_to_exclusion_list_id,
|
|
248
302
|
} = params;
|
|
249
303
|
|
|
250
304
|
log(`generate_lead_list: "${query}" (limit: ${limit}, mode: ${mode})`);
|
|
@@ -262,6 +316,18 @@ export function registerTools(server) {
|
|
|
262
316
|
find_phone,
|
|
263
317
|
};
|
|
264
318
|
|
|
319
|
+
// Only send the key when the caller asked for it: an absent key means
|
|
320
|
+
// "filter on the global exclusion list" server-side, while an empty
|
|
321
|
+
// array would disable exclusion filtering altogether.
|
|
322
|
+
if (exclusion_list_ids !== undefined) {
|
|
323
|
+
config.exclusion_filter_list_ids = exclusion_list_ids;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (add_to_exclusion_list_id !== undefined) {
|
|
327
|
+
config.add_to_exclusion_list = true;
|
|
328
|
+
config.exclusion_list_id = add_to_exclusion_list_id;
|
|
329
|
+
}
|
|
330
|
+
|
|
265
331
|
const startResult = await apiPost("/intellimatch/search", {
|
|
266
332
|
query,
|
|
267
333
|
limit: validatedLimit,
|
|
@@ -288,12 +354,16 @@ export function registerTools(server) {
|
|
|
288
354
|
// ===========================================================================
|
|
289
355
|
// Tool: get_lead_list_results
|
|
290
356
|
// ===========================================================================
|
|
291
|
-
server.
|
|
357
|
+
server.registerTool(
|
|
292
358
|
"get_lead_list_results",
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
359
|
+
toolConfig({
|
|
360
|
+
title: "Get Lead List Results",
|
|
361
|
+
description: "Retrieve results from a lead list search started with `generate_lead_list`. Takes the hash returned by `generate_lead_list`. Polls the search status for up to 60 seconds. If the search completes within that time, returns the full data. If still processing after 60s, returns the current progress — call again to continue waiting. Consumes no credits: the run itself was charged by `generate_lead_list`.",
|
|
362
|
+
inputSchema: {
|
|
363
|
+
hash: z.string().describe("The hash returned by generate_lead_list"),
|
|
364
|
+
},
|
|
365
|
+
annotations: READS,
|
|
366
|
+
}),
|
|
297
367
|
async ({ hash }, extra) => {
|
|
298
368
|
log(`get_lead_list_results: hash=${hash}`);
|
|
299
369
|
|
|
@@ -384,4 +454,160 @@ export function registerTools(server) {
|
|
|
384
454
|
}
|
|
385
455
|
}
|
|
386
456
|
);
|
|
387
|
-
|
|
457
|
+
|
|
458
|
+
// ===========================================================================
|
|
459
|
+
// Tool: list_exclusion_lists
|
|
460
|
+
// ===========================================================================
|
|
461
|
+
server.registerTool(
|
|
462
|
+
"list_exclusion_lists",
|
|
463
|
+
toolConfig({
|
|
464
|
+
title: "List Exclusion Lists",
|
|
465
|
+
description: "List the exclusion lists you can use (lists you own plus lists shared with your team). An exclusion list holds company domains that should never show up in search results. Returns each list's id, name, owner and sharing status — use those ids with `generate_lead_list` (exclusion_list_ids / add_to_exclusion_list_id), with `lookalike_search`, or with the other exclusion tools. Consumes no credits.",
|
|
466
|
+
inputSchema: {},
|
|
467
|
+
annotations: READS,
|
|
468
|
+
}),
|
|
469
|
+
async (params, extra) => {
|
|
470
|
+
log("list_exclusion_lists");
|
|
471
|
+
|
|
472
|
+
try {
|
|
473
|
+
const apiKey = resolveApiKey(extra);
|
|
474
|
+
const data = await apiGet("/intellimatch/exclusion-lists", apiKey);
|
|
475
|
+
return formatResponse(data);
|
|
476
|
+
} catch (error) {
|
|
477
|
+
return formatError(error.message);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
);
|
|
481
|
+
|
|
482
|
+
// ===========================================================================
|
|
483
|
+
// Tool: create_exclusion_list
|
|
484
|
+
// ===========================================================================
|
|
485
|
+
server.registerTool(
|
|
486
|
+
"create_exclusion_list",
|
|
487
|
+
toolConfig({
|
|
488
|
+
title: "Create Exclusion List",
|
|
489
|
+
description: "Create a new, empty exclusion list and return its id. Add domains to it with `add_exclusion_domains`, or let a search fill it automatically via `generate_lead_list`'s add_to_exclusion_list_id. List names must be unique per user. If is_shared is true and you do not belong to a team, the list is still created but the call returns an error — do not retry with the same name, it would then fail as a duplicate. Call `list_exclusion_lists` to check before retrying. Consumes no credits.",
|
|
490
|
+
inputSchema: {
|
|
491
|
+
name: z.string().describe("Name of the list (max 255 characters, must be unique among your lists, e.g. \"Competitors\")"),
|
|
492
|
+
is_shared: z.boolean().optional().default(false).describe("Share the list with your current team. Fails if you do not belong to a team."),
|
|
493
|
+
},
|
|
494
|
+
// Names are unique per user, so a repeated call fails as a duplicate
|
|
495
|
+
// rather than returning the list it already created.
|
|
496
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
497
|
+
}),
|
|
498
|
+
async ({ name, is_shared = false }, extra) => {
|
|
499
|
+
log(`create_exclusion_list: name="${name}" is_shared=${is_shared}`);
|
|
500
|
+
|
|
501
|
+
try {
|
|
502
|
+
const apiKey = resolveApiKey(extra);
|
|
503
|
+
const data = await apiPost("/intellimatch/exclusion-lists", { name, is_shared }, apiKey);
|
|
504
|
+
return formatResponse(data);
|
|
505
|
+
} catch (error) {
|
|
506
|
+
return formatError(error.message);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
);
|
|
510
|
+
|
|
511
|
+
// ===========================================================================
|
|
512
|
+
// Tool: list_exclusion_domains
|
|
513
|
+
// ===========================================================================
|
|
514
|
+
server.registerTool(
|
|
515
|
+
"list_exclusion_domains",
|
|
516
|
+
toolConfig({
|
|
517
|
+
title: "List Excluded Domains",
|
|
518
|
+
description: "List the domains held by an exclusion list, paginated. Each domain is returned with its own id — those ids are what `remove_exclusion_domains` needs, so call this first when you want to remove domains. Omitting list_id does NOT return only your global exclusions: it returns EVERY domain you can reach — your global ones, every list you own, AND every list shared with your team. To act on the global exclusions only, keep the entries whose `excluded_domain_list_id` is null. Always pass an explicit list_id before deleting anything. Results are ordered by domain name alone, so an entry can move between pages — re-read the page before using an id. Consumes no credits.",
|
|
519
|
+
inputSchema: {
|
|
520
|
+
list_id: z.number().optional().describe("Exclusion list to read. Must be >= 1 — passing 0 returns a 422 error. Omit the parameter to list every domain you can reach (see the tool description). Get ids from `list_exclusion_lists`."),
|
|
521
|
+
query: z.string().optional().describe("Filter domains containing this text (max 100 characters, e.g. \"competitor\")"),
|
|
522
|
+
page: z.number().optional().default(1).describe("Page number (default: 1)"),
|
|
523
|
+
per_page: z.number().optional().default(15).describe("Domains per page (default: 15, max: 100)"),
|
|
524
|
+
},
|
|
525
|
+
annotations: READS,
|
|
526
|
+
}),
|
|
527
|
+
async ({ list_id, query, page = 1, per_page = 15 }, extra) => {
|
|
528
|
+
log(`list_exclusion_domains: list_id=${list_id ?? "global"} query=${query ?? "-"} page=${page}`);
|
|
529
|
+
|
|
530
|
+
try {
|
|
531
|
+
const apiKey = resolveApiKey(extra);
|
|
532
|
+
|
|
533
|
+
const searchParams = new URLSearchParams({
|
|
534
|
+
page: String(Math.max(1, page)),
|
|
535
|
+
per_page: String(Math.min(Math.max(1, per_page), 100)),
|
|
536
|
+
});
|
|
537
|
+
if (list_id !== undefined) searchParams.set("list_id", String(list_id));
|
|
538
|
+
if (query) searchParams.set("query", query);
|
|
539
|
+
|
|
540
|
+
const data = await apiGet(`/intellimatch/domains?${searchParams.toString()}`, apiKey);
|
|
541
|
+
return formatResponse(data);
|
|
542
|
+
} catch (error) {
|
|
543
|
+
return formatError(error.message);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
);
|
|
547
|
+
|
|
548
|
+
// ===========================================================================
|
|
549
|
+
// Tool: add_exclusion_domains
|
|
550
|
+
// ===========================================================================
|
|
551
|
+
server.registerTool(
|
|
552
|
+
"add_exclusion_domains",
|
|
553
|
+
toolConfig({
|
|
554
|
+
title: "Add Excluded Domains",
|
|
555
|
+
description: "Add company domains to an exclusion list so they stop appearing in search results. Omit list_id to add them to your global exclusions instead. Domains are reduced to their registrable form before storage: protocol, path and ALL subdomains are stripped, so \"careers.acme.com\" and \"https://www.acme.com/jobs\" both become \"acme.com\" and exclude the whole company. Entries that cannot be parsed as a domain are dropped silently and are not reported back. The response counters do NOT reflect what was stored: `total` and `processed_immediately` count the entries you sent, dropped ones included, so `total: 4` can mean 3 domains excluded — read the list back with `list_exclusion_domains` to know what landed. Large batches are accepted (max 10,000): the first 50 domains are applied immediately and the rest are queued in the background, so a search started right away will only account for the first 50. Consumes no credits.",
|
|
556
|
+
inputSchema: {
|
|
557
|
+
domains: z.array(z.string()).describe("Company domains to exclude (max 10,000, each max 255 characters, e.g. [\"competitor.com\", \"blocked.io\"])"),
|
|
558
|
+
list_id: z.number().optional().describe("Exclusion list to add the domains to. Omit to add them as global exclusions — 0 does the same here, unlike `list_exclusion_domains` where 0 is rejected with a 422. Get ids from `list_exclusion_lists`."),
|
|
559
|
+
},
|
|
560
|
+
// Re-adding a domain that is already on the list leaves the same state.
|
|
561
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
562
|
+
}),
|
|
563
|
+
async ({ domains, list_id }, extra) => {
|
|
564
|
+
log(`add_exclusion_domains: ${domains.length} domain(s) to list_id=${list_id ?? "global"}`);
|
|
565
|
+
|
|
566
|
+
try {
|
|
567
|
+
const apiKey = resolveApiKey(extra);
|
|
568
|
+
|
|
569
|
+
const body = { domains };
|
|
570
|
+
if (list_id !== undefined) body.list_id = list_id;
|
|
571
|
+
|
|
572
|
+
const data = await apiPost("/intellimatch/domains", body, apiKey);
|
|
573
|
+
return formatResponse(data);
|
|
574
|
+
} catch (error) {
|
|
575
|
+
return formatError(error.message);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
);
|
|
579
|
+
|
|
580
|
+
// ===========================================================================
|
|
581
|
+
// Tool: remove_exclusion_domains
|
|
582
|
+
// ===========================================================================
|
|
583
|
+
server.registerTool(
|
|
584
|
+
"remove_exclusion_domains",
|
|
585
|
+
toolConfig({
|
|
586
|
+
title: "Remove Excluded Domains",
|
|
587
|
+
description: "Remove domains from an exclusion list, making them eligible for search results again. Takes domain ids, NOT domain names — call `list_exclusion_domains` first to resolve names into ids. Deletion is permanent: there is no undo and no soft delete. If none of the ids are yours to delete the call fails with a 403 rather than reporting a count of zero; if only some are, the others are dropped silently and the response does not say which. On a team-shared list you are allowed to delete domains added by teammates, so check the list before deleting. Ids obtained right after a large `add_exclusion_domains` may be stale. Consumes no credits.",
|
|
588
|
+
inputSchema: {
|
|
589
|
+
ids: z.array(z.number()).describe("Ids of the domains to remove (max 1000), as returned by `list_exclusion_domains`"),
|
|
590
|
+
},
|
|
591
|
+
// Permanent deletion, and a repeated call fails with a 403 once the ids
|
|
592
|
+
// are gone rather than succeeding as a no-op.
|
|
593
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true },
|
|
594
|
+
}),
|
|
595
|
+
async ({ ids }, extra) => {
|
|
596
|
+
log(`remove_exclusion_domains: ${ids.length} id(s)`);
|
|
597
|
+
|
|
598
|
+
try {
|
|
599
|
+
const apiKey = resolveApiKey(extra);
|
|
600
|
+
const data = await apiDelete("/intellimatch/domains", { ids }, apiKey);
|
|
601
|
+
return formatResponse(data);
|
|
602
|
+
} catch (error) {
|
|
603
|
+
// abort(403) carries no reason of its own — say what it means here
|
|
604
|
+
if (error.status === 403) {
|
|
605
|
+
return formatError(
|
|
606
|
+
`${error.message}. None of the ids you passed belong to you or to a list you may edit, so nothing was deleted. Re-read the ids with \`list_exclusion_domains\` on an explicit list_id.`
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
return formatError(error.message);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
);
|
|
613
|
+
}
|