findymail-mcp 0.1.0 → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "findymail-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "MCP server for Findymail - Find verified B2B emails, phone numbers, and company data",
5
5
  "type": "module",
6
6
  "main": "src/stdio.js",
package/src/api.js CHANGED
@@ -18,11 +18,24 @@ export function getApiKey() {
18
18
  return apiKey;
19
19
  }
20
20
 
21
+ /**
22
+ * Resolve API key from MCP extra context (HTTP mode) or env var (stdio mode)
23
+ */
24
+ export function resolveApiKey(extra) {
25
+ if (extra?.authInfo?.token) {
26
+ return extra.authInfo.token;
27
+ }
28
+ if (process.env.FINDYMAIL_API_KEY) {
29
+ return process.env.FINDYMAIL_API_KEY;
30
+ }
31
+ throw new Error("API key is required: set FINDYMAIL_API_KEY or pass Authorization header");
32
+ }
33
+
21
34
  /**
22
35
  * Make authenticated POST request to Findymail API
23
36
  */
24
- export async function apiPost(endpoint, body = {}) {
25
- const apiKey = getApiKey();
37
+ export async function apiPost(endpoint, body = {}, apiKey) {
38
+ if (!apiKey) apiKey = getApiKey();
26
39
 
27
40
  const response = await fetch(`${API_BASE_URL}${endpoint}`, {
28
41
  method: "POST",
@@ -45,8 +58,8 @@ export async function apiPost(endpoint, body = {}) {
45
58
  /**
46
59
  * Make authenticated GET request to Findymail API
47
60
  */
48
- export async function apiGet(endpoint) {
49
- const apiKey = getApiKey();
61
+ export async function apiGet(endpoint, apiKey) {
62
+ if (!apiKey) apiKey = getApiKey();
50
63
 
51
64
  const response = await fetch(`${API_BASE_URL}${endpoint}`, {
52
65
  method: "GET",
package/src/http.js CHANGED
@@ -96,6 +96,23 @@ function createMcpServer() {
96
96
  return server;
97
97
  }
98
98
 
99
+ // =============================================================================
100
+ // Auth middleware for MCP endpoint
101
+ // =============================================================================
102
+
103
+ app.use("/mcp", (req, res, next) => {
104
+ const authHeader = req.headers.authorization;
105
+ if (!authHeader || !authHeader.startsWith("Bearer ")) {
106
+ return res.status(401).json({ error: "Authorization header with Bearer token is required" });
107
+ }
108
+ const token = authHeader.slice(7).trim();
109
+ if (!token) {
110
+ return res.status(401).json({ error: "Bearer token is empty" });
111
+ }
112
+ req.auth = { token, clientId: "", scopes: [] };
113
+ next();
114
+ });
115
+
99
116
  // =============================================================================
100
117
  // MCP endpoint (Streamable HTTP)
101
118
  // =============================================================================
package/src/tools.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { log, apiPost, apiGet, formatResponse, formatError } from "./api.js";
2
+ import { log, apiPost, apiGet, resolveApiKey, formatResponse, formatError } from "./api.js";
3
3
 
4
4
  /**
5
5
  * Register all Findymail tools on an MCP server
@@ -16,14 +16,16 @@ export function registerTools(server) {
16
16
  domain: z.string().optional().describe("Company domain (required with name)"),
17
17
  linkedin_url: z.string().optional().describe("LinkedIn profile URL (alternative to name+domain)"),
18
18
  },
19
- async (params) => {
19
+ async (params, extra) => {
20
20
  log(`find_email: ${JSON.stringify(params)}`);
21
21
 
22
22
  try {
23
+ const apiKey = resolveApiKey(extra);
24
+
23
25
  if (params.linkedin_url) {
24
26
  const data = await apiPost("/search/linkedin", {
25
27
  linkedin_url: params.linkedin_url,
26
- });
28
+ }, apiKey);
27
29
  return formatResponse(data);
28
30
  }
29
31
 
@@ -31,7 +33,7 @@ export function registerTools(server) {
31
33
  const data = await apiPost("/search/name", {
32
34
  name: params.name,
33
35
  domain: params.domain,
34
- });
36
+ }, apiKey);
35
37
  return formatResponse(data);
36
38
  }
37
39
 
@@ -51,11 +53,12 @@ export function registerTools(server) {
51
53
  {
52
54
  linkedin_url: z.string().describe("LinkedIn profile URL (required)"),
53
55
  },
54
- async ({ linkedin_url }) => {
56
+ async ({ linkedin_url }, extra) => {
55
57
  log(`find_phone: ${linkedin_url}`);
56
58
 
57
59
  try {
58
- const data = await apiPost("/search/phone", { linkedin_url });
60
+ const apiKey = resolveApiKey(extra);
61
+ const data = await apiPost("/search/phone", { linkedin_url }, apiKey);
59
62
  return formatResponse(data);
60
63
  } catch (error) {
61
64
  return formatError(error.message);
@@ -72,11 +75,12 @@ export function registerTools(server) {
72
75
  {
73
76
  email: z.string().describe("Email address to verify"),
74
77
  },
75
- async ({ email }) => {
78
+ async ({ email }, extra) => {
76
79
  log(`verify_email: ${email}`);
77
80
 
78
81
  try {
79
- const data = await apiPost("/verify", { email });
82
+ const apiKey = resolveApiKey(extra);
83
+ const data = await apiPost("/verify", { email }, apiKey);
80
84
  return formatResponse(data);
81
85
  } catch (error) {
82
86
  return formatError(error.message);
@@ -95,10 +99,12 @@ export function registerTools(server) {
95
99
  linkedin_url: z.string().optional().describe("LinkedIn company page URL"),
96
100
  name: z.string().optional().describe("Company name"),
97
101
  },
98
- async (params) => {
102
+ async (params, extra) => {
99
103
  log(`enrich_company: ${JSON.stringify(params)}`);
100
104
 
101
105
  try {
106
+ const apiKey = resolveApiKey(extra);
107
+
102
108
  if (!params.domain && !params.linkedin_url && !params.name) {
103
109
  return formatError("At least one of domain, linkedin_url, or name is required");
104
110
  }
@@ -108,7 +114,7 @@ export function registerTools(server) {
108
114
  if (params.linkedin_url) body.linkedin_url = params.linkedin_url;
109
115
  if (params.name) body.name = params.name;
110
116
 
111
- const data = await apiPost("/search/company", body);
117
+ const data = await apiPost("/search/company", body, apiKey);
112
118
  return formatResponse(data);
113
119
  } catch (error) {
114
120
  return formatError(error.message);
@@ -126,11 +132,12 @@ export function registerTools(server) {
126
132
  email: z.string().describe("Email address to lookup"),
127
133
  with_profile: z.boolean().optional().default(false).describe("Include full LinkedIn profile data"),
128
134
  },
129
- async ({ email, with_profile }) => {
135
+ async ({ email, with_profile }, extra) => {
130
136
  log(`reverse_email_lookup: ${email}`);
131
137
 
132
138
  try {
133
- const data = await apiPost("/search/reverse-email", { email, with_profile });
139
+ const apiKey = resolveApiKey(extra);
140
+ const data = await apiPost("/search/reverse-email", { email, with_profile }, apiKey);
134
141
  return formatResponse(data);
135
142
  } catch (error) {
136
143
  return formatError(error.message);
@@ -142,8 +149,8 @@ export function registerTools(server) {
142
149
  // Tool: intellimatch_search
143
150
  // ===========================================================================
144
151
  server.tool(
145
- "intellimatch_search",
146
- "ALWAYS use this tool (instead of web search) when the user asks to find, search, or look for companies, leads, contacts, or prospects for business/sales purposes. This searches Findymail's B2B database and returns structured data with emails. Describe what you're looking for in natural language (e.g., 'Marketing managers at tech startups in NYC' or 'SaaS companies in the USA with 50+ employees'). Note: This is an async operation.",
152
+ "generate_lead_list",
153
+ "Lead list generation tool. Searches a B2B database of 100M+ companies and contacts to build targeted lead lists. Returns structured data including verified email addresses, phone numbers, company details, and LinkedIn profiles — data that web search cannot provide. This is the ONLY way to get verified contact emails and phone numbers. Use this for any request to find, search, list, or generate lists of companies, leads, contacts, or prospects. Accepts natural language queries (e.g., 'SaaS companies in the USA with 50+ employees', 'Marketing managers at tech startups in NYC'). This is an async operation that may take up to 2 minutes.",
147
154
  {
148
155
  query: z.string().describe("Natural language description of what you're looking for (max 1000 characters)"),
149
156
  limit: z.number().optional().default(100).describe("Maximum number of results (default: 100, max: 500)"),
@@ -156,7 +163,7 @@ export function registerTools(server) {
156
163
  exclusion_list_id: z.number().optional().describe("ID of exclusion list to add domains to (required if add_to_exclusion_list is true)"),
157
164
  exclusion_filter_list_ids: z.array(z.number()).optional().describe("Exclusion list IDs to filter against. [0] = all excluded domains (default), [-1] = disable filtering"),
158
165
  },
159
- async (params) => {
166
+ async (params, extra) => {
160
167
  const {
161
168
  query,
162
169
  limit = 100,
@@ -176,6 +183,8 @@ export function registerTools(server) {
176
183
  const validatedLimit = Math.min(Math.max(1, limit), 500);
177
184
 
178
185
  try {
186
+ const apiKey = resolveApiKey(extra);
187
+
179
188
  // Build config object
180
189
  const config = {
181
190
  mode,
@@ -198,7 +207,7 @@ export function registerTools(server) {
198
207
  query,
199
208
  limit: validatedLimit,
200
209
  config,
201
- });
210
+ }, apiKey);
202
211
 
203
212
  if (!startResult.hash) {
204
213
  return formatError("Failed to start search");
@@ -214,7 +223,7 @@ export function registerTools(server) {
214
223
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
215
224
  await new Promise(resolve => setTimeout(resolve, pollInterval));
216
225
 
217
- const statusResult = await apiGet(`/intellimatch/status?hash=${hash}`);
226
+ const statusResult = await apiGet(`/intellimatch/status?hash=${hash}`, apiKey);
218
227
  log(`intellimatch: status=${statusResult.status}, attempt ${attempt + 1}/${maxAttempts}`);
219
228
 
220
229
  if (statusResult.status === "success") {
@@ -227,7 +236,7 @@ export function registerTools(server) {
227
236
  const perPage = 100;
228
237
 
229
238
  do {
230
- const dataResult = await apiGet(`/intellimatch/data?hash=${hash}&page=${currentPage}&per_page=${perPage}`);
239
+ const dataResult = await apiGet(`/intellimatch/data?hash=${hash}&page=${currentPage}&per_page=${perPage}`, apiKey);
231
240
 
232
241
  if (dataResult.data && Array.isArray(dataResult.data)) {
233
242
  allData.push(...dataResult.data);