findymail-mcp 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Findymail
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # Findymail MCP Server
2
+
3
+ MCP (Model Context Protocol) server for [Findymail](https://findymail.com) - enabling AI assistants to find verified B2B emails, phone numbers, and company data.
4
+
5
+ ## Features
6
+
7
+ This MCP server exposes the following tools:
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+ | `find_email` | Find verified B2B email from name + domain or LinkedIn URL |
12
+ | `find_phone` | Find phone number(s) from LinkedIn URL |
13
+ | `verify_email` | Verify if an email is deliverable |
14
+ | `enrich_company` | Get company data from domain, LinkedIn URL, or name |
15
+ | `reverse_email_lookup` | Find person info from an email |
16
+ | `intellimatch_search` | AI-powered lead search with natural language |
17
+
18
+ ## Prerequisites
19
+
20
+ - Node.js 18+
21
+ - A Findymail API key ([get one here](https://app.findymail.com/settings/api))
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ npm install -g findymail-mcp
27
+ ```
28
+
29
+ Or use directly with npx:
30
+
31
+ ```bash
32
+ npx findymail-mcp
33
+ ```
34
+
35
+ ## Configuration
36
+
37
+ ### Claude Code
38
+
39
+ ```bash
40
+ claude mcp add findymail -e FINDYMAIL_API_KEY=your-api-key -- npx findymail-mcp
41
+ ```
42
+
43
+ Or manually edit `~/.claude.json`:
44
+
45
+ ```json
46
+ {
47
+ "mcpServers": {
48
+ "findymail": {
49
+ "command": "npx",
50
+ "args": ["findymail-mcp"],
51
+ "env": {
52
+ "FINDYMAIL_API_KEY": "your-api-key"
53
+ }
54
+ }
55
+ }
56
+ }
57
+ ```
58
+
59
+ ### Claude Desktop
60
+
61
+ Edit your Claude Desktop config file:
62
+
63
+ - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
64
+ - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
65
+
66
+ ```json
67
+ {
68
+ "mcpServers": {
69
+ "findymail": {
70
+ "command": "npx",
71
+ "args": ["findymail-mcp"],
72
+ "env": {
73
+ "FINDYMAIL_API_KEY": "your-api-key"
74
+ }
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ ## Usage Examples
81
+
82
+ Once configured, you can ask your AI assistant:
83
+
84
+ - "Find the email for John Smith at Acme Corp"
85
+ - "What's the phone number for the CEO of findymail.com?"
86
+ - "Verify if john@example.com is a valid email"
87
+ - "Get company information for stripe.com"
88
+ - "Find me 10 marketing managers at SaaS companies in San Francisco"
89
+
90
+ ## API Key
91
+
92
+ Get your API key from [Findymail Settings](https://app.findymail.com/settings/api).
93
+
94
+ Each API call consumes credits from your Findymail account.
95
+
96
+ ## Development
97
+
98
+ ```bash
99
+ # Clone the repo
100
+ git clone https://github.com/Findymail/findymail-mcp.git
101
+ cd findymail-mcp
102
+
103
+ # Install dependencies
104
+ npm install
105
+
106
+ # Run locally
107
+ FINDYMAIL_API_KEY=your-key npm start
108
+ ```
109
+
110
+ ## License
111
+
112
+ MIT
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "findymail-mcp",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for Findymail - Find verified B2B emails, phone numbers, and company data",
5
+ "type": "module",
6
+ "main": "src/stdio.js",
7
+ "bin": {
8
+ "findymail-mcp": "./src/stdio.js"
9
+ },
10
+ "files": [
11
+ "src/"
12
+ ],
13
+ "scripts": {
14
+ "start": "node src/stdio.js",
15
+ "start:http": "node src/http.js"
16
+ },
17
+ "keywords": [
18
+ "mcp",
19
+ "findymail",
20
+ "email-finder",
21
+ "b2b",
22
+ "lead-generation",
23
+ "claude",
24
+ "anthropic"
25
+ ],
26
+ "author": "Findymail <support@findymail.com>",
27
+ "license": "MIT",
28
+ "homepage": "https://github.com/Findymail/findymail-mcp",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/Findymail/findymail-mcp.git"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/Findymail/findymail-mcp/issues"
35
+ },
36
+ "engines": {
37
+ "node": ">=18.0.0"
38
+ },
39
+ "dependencies": {
40
+ "@modelcontextprotocol/sdk": "^1.0.0",
41
+ "zod": "^3.24.0"
42
+ },
43
+ "optionalDependencies": {
44
+ "express": "^5.0.0"
45
+ }
46
+ }
package/src/api.js ADDED
@@ -0,0 +1,90 @@
1
+ const API_BASE_URL = "https://app.findymail.com/api";
2
+
3
+ /**
4
+ * Log to stderr (stdout is reserved for MCP protocol in stdio mode)
5
+ */
6
+ export function log(message) {
7
+ console.error(`[findymail-mcp] ${message}`);
8
+ }
9
+
10
+ /**
11
+ * Get API key from environment
12
+ */
13
+ export function getApiKey() {
14
+ const apiKey = process.env.FINDYMAIL_API_KEY;
15
+ if (!apiKey) {
16
+ throw new Error("FINDYMAIL_API_KEY environment variable is required");
17
+ }
18
+ return apiKey;
19
+ }
20
+
21
+ /**
22
+ * Make authenticated POST request to Findymail API
23
+ */
24
+ export async function apiPost(endpoint, body = {}) {
25
+ const apiKey = getApiKey();
26
+
27
+ const response = await fetch(`${API_BASE_URL}${endpoint}`, {
28
+ method: "POST",
29
+ headers: {
30
+ "Authorization": `Bearer ${apiKey}`,
31
+ "Content-Type": "application/json",
32
+ "Accept": "application/json",
33
+ },
34
+ body: JSON.stringify(body),
35
+ });
36
+
37
+ if (!response.ok) {
38
+ const error = await response.json().catch(() => ({}));
39
+ throw new Error(error.message || `API error: ${response.status}`);
40
+ }
41
+
42
+ return response.json();
43
+ }
44
+
45
+ /**
46
+ * Make authenticated GET request to Findymail API
47
+ */
48
+ export async function apiGet(endpoint) {
49
+ const apiKey = getApiKey();
50
+
51
+ const response = await fetch(`${API_BASE_URL}${endpoint}`, {
52
+ method: "GET",
53
+ headers: {
54
+ "Authorization": `Bearer ${apiKey}`,
55
+ "Accept": "application/json",
56
+ },
57
+ });
58
+
59
+ if (!response.ok) {
60
+ const error = await response.json().catch(() => ({}));
61
+ throw new Error(error.message || `API error: ${response.status}`);
62
+ }
63
+
64
+ return response.json();
65
+ }
66
+
67
+ /**
68
+ * Format API response for MCP
69
+ */
70
+ export function formatResponse(data) {
71
+ return {
72
+ content: [{
73
+ type: "text",
74
+ text: JSON.stringify(data, null, 2),
75
+ }],
76
+ };
77
+ }
78
+
79
+ /**
80
+ * Format error response for MCP
81
+ */
82
+ export function formatError(message) {
83
+ return {
84
+ content: [{
85
+ type: "text",
86
+ text: JSON.stringify({ error: message }, null, 2),
87
+ }],
88
+ isError: true,
89
+ };
90
+ }
package/src/http.js ADDED
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
5
+ import { log } from "./api.js";
6
+ import { registerTools } from "./tools.js";
7
+
8
+ // Express is an optional dependency for HTTP mode
9
+ let express;
10
+ try {
11
+ express = (await import("express")).default;
12
+ } catch {
13
+ console.error("Error: express is required for HTTP mode.");
14
+ console.error("Install it with: npm install express");
15
+ process.exit(1);
16
+ }
17
+
18
+ const PORT = process.env.PORT || 3456;
19
+ const BASE_URL = process.env.BASE_URL || `http://localhost:${PORT}`;
20
+
21
+ const app = express();
22
+
23
+ // Store active transports by session
24
+ const transports = {};
25
+
26
+ // JSON parsing only for non-MCP routes (MCP transport handles its own parsing)
27
+ app.use((req, res, next) => {
28
+ if (req.path === "/mcp") {
29
+ next();
30
+ } else {
31
+ express.json()(req, res, next);
32
+ }
33
+ });
34
+
35
+ // =============================================================================
36
+ // OAuth 2.0 endpoints (required for HTTP transport)
37
+ // =============================================================================
38
+
39
+ app.get("/.well-known/oauth-authorization-server", (req, res) => {
40
+ log("OAuth metadata requested");
41
+ res.json({
42
+ issuer: BASE_URL,
43
+ authorization_endpoint: `${BASE_URL}/authorize`,
44
+ token_endpoint: `${BASE_URL}/token`,
45
+ registration_endpoint: `${BASE_URL}/register`,
46
+ response_types_supported: ["code"],
47
+ grant_types_supported: ["authorization_code", "refresh_token"],
48
+ code_challenge_methods_supported: ["S256"],
49
+ token_endpoint_auth_methods_supported: ["none"],
50
+ });
51
+ });
52
+
53
+ app.post("/register", (req, res) => {
54
+ log("Client registration");
55
+ const clientId = `client_${Date.now()}`;
56
+ res.status(201).json({
57
+ client_id: clientId,
58
+ client_id_issued_at: Math.floor(Date.now() / 1000),
59
+ redirect_uris: req.body?.redirect_uris || [],
60
+ });
61
+ });
62
+
63
+ app.get("/authorize", (req, res) => {
64
+ log(`Authorization requested for client: ${req.query.client_id}`);
65
+ const code = `code_${Date.now()}`;
66
+ const redirectUri = new URL(req.query.redirect_uri);
67
+ redirectUri.searchParams.set("code", code);
68
+ if (req.query.state) {
69
+ redirectUri.searchParams.set("state", req.query.state);
70
+ }
71
+ log("Auto-approving authorization");
72
+ res.redirect(redirectUri.toString());
73
+ });
74
+
75
+ app.post("/token", (req, res) => {
76
+ log("Token exchange");
77
+ res.json({
78
+ access_token: `access_${Date.now()}`,
79
+ token_type: "Bearer",
80
+ expires_in: 3600,
81
+ });
82
+ });
83
+
84
+ // =============================================================================
85
+ // MCP Server Factory
86
+ // =============================================================================
87
+
88
+ function createMcpServer() {
89
+ const server = new McpServer({
90
+ name: "findymail-mcp",
91
+ version: "0.1.0",
92
+ });
93
+
94
+ registerTools(server);
95
+
96
+ return server;
97
+ }
98
+
99
+ // =============================================================================
100
+ // MCP endpoint (Streamable HTTP)
101
+ // =============================================================================
102
+
103
+ app.all("/mcp", async (req, res) => {
104
+ log(`MCP request: ${req.method}`);
105
+
106
+ const sessionId = req.headers["mcp-session-id"] || `session_${Date.now()}`;
107
+ log(`Session: ${sessionId}`);
108
+
109
+ let transport = transports[sessionId];
110
+
111
+ if (!transport) {
112
+ log("Creating new transport and server...");
113
+ const server = createMcpServer();
114
+ transport = new StreamableHTTPServerTransport({
115
+ sessionIdGenerator: () => sessionId,
116
+ });
117
+ transports[sessionId] = transport;
118
+
119
+ await server.connect(transport);
120
+ log("Server connected");
121
+ }
122
+
123
+ try {
124
+ await transport.handleRequest(req, res);
125
+ log("Request handled");
126
+ } catch (error) {
127
+ log(`Error: ${error.message}`);
128
+ if (!res.headersSent) {
129
+ res.status(500).json({ error: error.message });
130
+ }
131
+ }
132
+ });
133
+
134
+ // =============================================================================
135
+ // Health check
136
+ // =============================================================================
137
+
138
+ app.get("/health", (req, res) => {
139
+ res.json({
140
+ status: "ok",
141
+ server: "findymail-mcp",
142
+ transport: "streamable-http",
143
+ });
144
+ });
145
+
146
+ // =============================================================================
147
+ // Start server
148
+ // =============================================================================
149
+
150
+ app.listen(PORT, () => {
151
+ log(`MCP Server listening on ${BASE_URL}`);
152
+ log(`MCP endpoint: ${BASE_URL}/mcp`);
153
+ log(`Health check: ${BASE_URL}/health`);
154
+ });
package/src/stdio.js ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5
+ import { log } from "./api.js";
6
+ import { registerTools } from "./tools.js";
7
+
8
+ const server = new McpServer({
9
+ name: "findymail-mcp",
10
+ version: "0.1.0",
11
+ });
12
+
13
+ registerTools(server);
14
+
15
+ async function main() {
16
+ log("Starting server (stdio mode)...");
17
+
18
+ const transport = new StdioServerTransport();
19
+ await server.connect(transport);
20
+
21
+ log("Server connected and ready");
22
+ }
23
+
24
+ main().catch((error) => {
25
+ console.error("Fatal error:", error);
26
+ process.exit(1);
27
+ });
package/src/tools.js ADDED
@@ -0,0 +1,272 @@
1
+ import { z } from "zod";
2
+ import { log, apiPost, apiGet, formatResponse, formatError } from "./api.js";
3
+
4
+ /**
5
+ * Register all Findymail tools on an MCP server
6
+ */
7
+ export function registerTools(server) {
8
+ // ===========================================================================
9
+ // Tool: find_email
10
+ // ===========================================================================
11
+ server.tool(
12
+ "find_email",
13
+ "Find a verified B2B email address. Use either name+domain OR linkedin_url.",
14
+ {
15
+ name: z.string().optional().describe("Person's full name (required with domain)"),
16
+ domain: z.string().optional().describe("Company domain (required with name)"),
17
+ linkedin_url: z.string().optional().describe("LinkedIn profile URL (alternative to name+domain)"),
18
+ },
19
+ async (params) => {
20
+ log(`find_email: ${JSON.stringify(params)}`);
21
+
22
+ try {
23
+ if (params.linkedin_url) {
24
+ const data = await apiPost("/search/linkedin", {
25
+ linkedin_url: params.linkedin_url,
26
+ });
27
+ return formatResponse(data);
28
+ }
29
+
30
+ if (params.name && params.domain) {
31
+ const data = await apiPost("/search/name", {
32
+ name: params.name,
33
+ domain: params.domain,
34
+ });
35
+ return formatResponse(data);
36
+ }
37
+
38
+ return formatError("Either linkedin_url OR both name and domain are required");
39
+ } catch (error) {
40
+ return formatError(error.message);
41
+ }
42
+ }
43
+ );
44
+
45
+ // ===========================================================================
46
+ // Tool: find_phone
47
+ // ===========================================================================
48
+ server.tool(
49
+ "find_phone",
50
+ "Find phone number(s) for a contact using their LinkedIn profile URL.",
51
+ {
52
+ linkedin_url: z.string().describe("LinkedIn profile URL (required)"),
53
+ },
54
+ async ({ linkedin_url }) => {
55
+ log(`find_phone: ${linkedin_url}`);
56
+
57
+ try {
58
+ const data = await apiPost("/search/phone", { linkedin_url });
59
+ return formatResponse(data);
60
+ } catch (error) {
61
+ return formatError(error.message);
62
+ }
63
+ }
64
+ );
65
+
66
+ // ===========================================================================
67
+ // Tool: verify_email
68
+ // ===========================================================================
69
+ server.tool(
70
+ "verify_email",
71
+ "Verify if an email address is deliverable. Returns verification status and details.",
72
+ {
73
+ email: z.string().describe("Email address to verify"),
74
+ },
75
+ async ({ email }) => {
76
+ log(`verify_email: ${email}`);
77
+
78
+ try {
79
+ const data = await apiPost("/verify", { email });
80
+ return formatResponse(data);
81
+ } catch (error) {
82
+ return formatError(error.message);
83
+ }
84
+ }
85
+ );
86
+
87
+ // ===========================================================================
88
+ // Tool: enrich_company
89
+ // ===========================================================================
90
+ server.tool(
91
+ "enrich_company",
92
+ "Get company data. Use domain, linkedin_url, or company name.",
93
+ {
94
+ domain: z.string().optional().describe("Company domain (e.g., findymail.com)"),
95
+ linkedin_url: z.string().optional().describe("LinkedIn company page URL"),
96
+ name: z.string().optional().describe("Company name"),
97
+ },
98
+ async (params) => {
99
+ log(`enrich_company: ${JSON.stringify(params)}`);
100
+
101
+ try {
102
+ if (!params.domain && !params.linkedin_url && !params.name) {
103
+ return formatError("At least one of domain, linkedin_url, or name is required");
104
+ }
105
+
106
+ const body = {};
107
+ if (params.domain) body.domain = params.domain;
108
+ if (params.linkedin_url) body.linkedin_url = params.linkedin_url;
109
+ if (params.name) body.name = params.name;
110
+
111
+ const data = await apiPost("/search/company", body);
112
+ return formatResponse(data);
113
+ } catch (error) {
114
+ return formatError(error.message);
115
+ }
116
+ }
117
+ );
118
+
119
+ // ===========================================================================
120
+ // Tool: reverse_email_lookup
121
+ // ===========================================================================
122
+ server.tool(
123
+ "reverse_email_lookup",
124
+ "Find person information from an email address. Returns name, company, title, LinkedIn URL.",
125
+ {
126
+ email: z.string().describe("Email address to lookup"),
127
+ with_profile: z.boolean().optional().default(false).describe("Include full LinkedIn profile data"),
128
+ },
129
+ async ({ email, with_profile }) => {
130
+ log(`reverse_email_lookup: ${email}`);
131
+
132
+ try {
133
+ const data = await apiPost("/search/reverse-email", { email, with_profile });
134
+ return formatResponse(data);
135
+ } catch (error) {
136
+ return formatError(error.message);
137
+ }
138
+ }
139
+ );
140
+
141
+ // ===========================================================================
142
+ // Tool: intellimatch_search
143
+ // ===========================================================================
144
+ 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.",
147
+ {
148
+ query: z.string().describe("Natural language description of what you're looking for (max 1000 characters)"),
149
+ limit: z.number().optional().default(100).describe("Maximum number of results (default: 100, max: 500)"),
150
+ mode: z.enum(["broad", "targeted"]).optional().default("broad").describe("'broad' = fast export (1 credit/10 companies), 'targeted' = AI-qualified results (1 credit/company)"),
151
+ find_contact: z.boolean().optional().default(true).describe("Search for contacts at each company (+1 credit/contact found)"),
152
+ 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'])"),
153
+ find_email: z.boolean().optional().default(true).describe("Enrich contacts with email (+1 credit/email found). Requires find_contact: true"),
154
+ find_phone: z.boolean().optional().default(false).describe("Enrich contacts with phone (+10 credits/phone found). Requires find_contact: true"),
155
+ add_to_exclusion_list: z.boolean().optional().default(false).describe("Add exported domains to an exclusion list"),
156
+ exclusion_list_id: z.number().optional().describe("ID of exclusion list to add domains to (required if add_to_exclusion_list is true)"),
157
+ 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
+ },
159
+ async (params) => {
160
+ const {
161
+ query,
162
+ limit = 100,
163
+ mode = "broad",
164
+ find_contact = true,
165
+ target_job_titles = ["CEO"],
166
+ find_email = true,
167
+ find_phone = false,
168
+ add_to_exclusion_list = false,
169
+ exclusion_list_id,
170
+ exclusion_filter_list_ids,
171
+ } = params;
172
+
173
+ log(`intellimatch_search: "${query}" (limit: ${limit}, mode: ${mode})`);
174
+
175
+ // Validate limit
176
+ const validatedLimit = Math.min(Math.max(1, limit), 500);
177
+
178
+ try {
179
+ // Build config object
180
+ const config = {
181
+ mode,
182
+ find_contact,
183
+ target_job_titles,
184
+ find_email,
185
+ find_phone,
186
+ add_to_exclusion_list,
187
+ };
188
+
189
+ if (exclusion_list_id !== undefined) {
190
+ config.exclusion_list_id = exclusion_list_id;
191
+ }
192
+ if (exclusion_filter_list_ids !== undefined) {
193
+ config.exclusion_filter_list_ids = exclusion_filter_list_ids;
194
+ }
195
+
196
+ // 1. Start the search
197
+ const startResult = await apiPost("/intellimatch/search", {
198
+ query,
199
+ limit: validatedLimit,
200
+ config,
201
+ });
202
+
203
+ if (!startResult.hash) {
204
+ return formatError("Failed to start search");
205
+ }
206
+
207
+ const hash = startResult.hash;
208
+ log(`intellimatch: search started with hash ${hash}`);
209
+
210
+ // 2. Poll STATUS endpoint
211
+ const maxAttempts = 60; // 2 minutes max
212
+ const pollInterval = 2000; // 2 seconds
213
+
214
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
215
+ await new Promise(resolve => setTimeout(resolve, pollInterval));
216
+
217
+ const statusResult = await apiGet(`/intellimatch/status?hash=${hash}`);
218
+ log(`intellimatch: status=${statusResult.status}, attempt ${attempt + 1}/${maxAttempts}`);
219
+
220
+ if (statusResult.status === "success") {
221
+ // 3. Export ready, fetch all data with pagination
222
+ log(`intellimatch: completed, fetching data...`);
223
+
224
+ const allData = [];
225
+ let currentPage = 1;
226
+ let lastPage = 1;
227
+ const perPage = 100;
228
+
229
+ do {
230
+ const dataResult = await apiGet(`/intellimatch/data?hash=${hash}&page=${currentPage}&per_page=${perPage}`);
231
+
232
+ if (dataResult.data && Array.isArray(dataResult.data)) {
233
+ allData.push(...dataResult.data);
234
+ }
235
+
236
+ if (dataResult.meta) {
237
+ lastPage = dataResult.meta.last_page || 1;
238
+ }
239
+
240
+ currentPage++;
241
+ } while (currentPage <= lastPage);
242
+
243
+ log(`intellimatch: fetched ${allData.length} results`);
244
+ return formatResponse({ data: allData, total: allData.length });
245
+ }
246
+
247
+ if (statusResult.status === "failed") {
248
+ return formatError(statusResult.message || "Search failed");
249
+ }
250
+
251
+ if (statusResult.status === "cancelled") {
252
+ return formatError("Search was cancelled");
253
+ }
254
+
255
+ // Log progress if available
256
+ if (statusResult.progress !== undefined) {
257
+ log(`intellimatch: progress ${statusResult.progress}%`);
258
+ }
259
+ }
260
+
261
+ // Timeout - return hash for manual check
262
+ return formatResponse({
263
+ status: "timeout",
264
+ hash,
265
+ message: "Search is still processing after 2 minutes. Use the hash to check status later.",
266
+ });
267
+ } catch (error) {
268
+ return formatError(error.message);
269
+ }
270
+ }
271
+ );
272
+ }