@mambalabsdev/mcp-linkedin-company-presence-mapper 1.0.0 → 1.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.
Files changed (3) hide show
  1. package/README.md +14 -2
  2. package/build/index.js +138 -42
  3. package/package.json +6 -5
package/README.md CHANGED
@@ -31,8 +31,16 @@ Add this to your MCP client configuration:
31
31
  - Node.js 18 or newer
32
32
  - An Apify API token from [console.apify.com/account/integrations](https://console.apify.com/account/integrations)
33
33
 
34
- The actor is pay per event and consumes Apify credits per call. Pricing is on the
35
- [actor page](https://apify.com/mambalabs/linkedin-company-presence-mapper).
34
+ The actor is pay per event and consumes Apify credits per call. Prices from the live pricing record, read 2026-10-05:
35
+
36
+ | Event | Price per event (USD) | Fires when |
37
+ | --- | --- | --- |
38
+ | `apify-actor-start` | $0.00005 | Charged when the Actor starts running. Number of events charged depends on Actor memory (one event per GB, minimum one event). |
39
+ | `company-checked` | $0.004 on the Free plan, down to $0.0028 on higher Apify plans | Once per company for which the discovery cascade completed and a non degraded row was produced, whether or not a LinkedIn profile was found. Does not fire on a degraded row, because on a degraded row no discovery was performed. |
40
+ | `profile-resolved` | $0.003 on the Free plan, down to $0.0021 on higher Apify plans | Once per company whose candidate LinkedIn URL passed the identity gate. Fires on the validation work, not on a populated count. A candidate dropped as an impersonator does not charge: the work was done and the honest answer is that there is no such profile. |
41
+ | `follower-count-extracted` | $0.0025 on the Free plan, down to $0.00175 on higher Apify plans | Once per company where a numeric follower count was read off the public page. Does not fire on not_extractable, blocked, identity_mismatch or url only runs. |
42
+
43
+ This server starts the run at 512 MB, the actor's own default, so a run charges one `apify-actor-start` event. The [actor page](https://apify.com/mambalabs/linkedin-company-presence-mapper) carries the current prices.
36
44
 
37
45
  ## Example prompts
38
46
 
@@ -71,6 +79,10 @@ first. The vocabulary is the same across the whole Mamba Labs social family:
71
79
  answer is no. `null` means we could not look. If you filter for companies with no
72
80
  presence, filter on `false`, because `null` rows are unknown rather than absent.
73
81
 
82
+ ## How each call runs
83
+
84
+ Each call starts the actor run, polls it until it finishes, then reads the dataset. The run is allowed 1,800 seconds at 512 MB. If the run is still going when this call stops waiting, the call returns the run id and a console link instead of a timeout, so the result is never lost.
85
+
74
86
  ## Full actor documentation
75
87
 
76
88
  [apify.com/mambalabs/linkedin-company-presence-mapper](https://apify.com/mambalabs/linkedin-company-presence-mapper)
package/build/index.js CHANGED
@@ -9,7 +9,6 @@ const here = dirname(fileURLToPath(import.meta.url));
9
9
  const pkg = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8"));
10
10
  // Distinctive UA so Apify run meta.userAgent marks MCP-originated runs.
11
11
  const USER_AGENT = `mambalabs-mcp ${pkg.name}@${pkg.version}`;
12
- const APIFY_TOKEN = process.env.APIFY_TOKEN;
13
12
  // Drop undefined values so optional inputs are not sent to the actor at all.
14
13
  function compact(obj) {
15
14
  const out = {};
@@ -26,36 +25,45 @@ function compact(obj) {
26
25
  function boolToString(v) {
27
26
  return v === undefined ? undefined : v ? "true" : "false";
28
27
  }
29
- // actorPath is the actor's IMMUTABLE Apify actor id, not its slug, so a Store
30
- // rename never breaks these calls.
28
+ // How long the actor run itself is allowed to take, in seconds. One value for
29
+ // every Mamba Labs wrapper, set 2026-10-05: start and poll exists so a long run
30
+ // survives, and a shorter limit would end the long runs it was built for. Past
31
+ // this limit the run ends TIMED-OUT and the caller is told so, with the run id.
32
+ const ACTOR_RUN_TIMEOUT_SECS = 1800;
33
+ // How long this wrapper waits for that run, in milliseconds. The actor's own
34
+ // timeout plus two minutes, so the run's own TIMED-OUT status is what the
35
+ // caller sees rather than the wrapper giving up first and reporting nothing.
36
+ const WRAPPER_WAIT_MS = (ACTOR_RUN_TIMEOUT_SECS + 120) * 1000;
37
+ // MAMBA_MCP_POLL_INTERVAL_MS exists for the test suite, which drives the poll
38
+ // loop against a mocked Apify API. Callers never need to set it.
39
+ const POLL_INTERVAL_MS = Number(process.env.MAMBA_MCP_POLL_INTERVAL_MS) || 3000;
40
+ const TERMINAL = new Set(["SUCCEEDED", "FAILED", "TIMED-OUT", "ABORTED", "ABORTING"]);
41
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
42
+ // Shared caller. actorPath is the actor's immutable Apify actor ID (a stable key
43
+ // that survives Store renames). The /v2/acts/{id} endpoint accepts it directly,
44
+ // so a Store rename never breaks these calls.
45
+ //
46
+ // START AND POLL, NOT RUN-SYNC. Apify's synchronous endpoints carry a platform
47
+ // ceiling of 300 seconds on the HTTP wait itself and answer 408 past it whatever
48
+ // the timeout parameter says, so a long run read as a timeout while the actor
49
+ // went on to finish and bill. Starting the run, polling it to a terminal status
50
+ // and then reading the dataset waits exactly as long as the run takes, and a
51
+ // call that stops waiting returns the run id so the result is never lost.
52
+ //
53
+ // The token is read here rather than at module load, so the tool registers
54
+ // unconditionally and a server started without APIFY_TOKEN still advertises its
55
+ // capabilities instead of reporting none.
31
56
  async function runActor(actorPath, actorLabel, input) {
57
+ const APIFY_TOKEN = process.env.APIFY_TOKEN;
32
58
  if (!APIFY_TOKEN) {
33
59
  return { isError: true, content: [{ type: "text", text: "APIFY_TOKEN is not set. Create a token at https://console.apify.com/account/integrations and set it as the APIFY_TOKEN environment variable." }] };
34
60
  }
35
- // memory=512 is deliberate and matches the actor's declared
36
- // defaultRunOptions.memoryMbytes. run-sync-get-dataset-items runs at 2048 MB
37
- // unless told otherwise, and `apify-actor-start` bills once per GB with a
38
- // minimum of one, so leaving the default in place would charge the caller
39
- // more start events per run than the actor asks for. Keep this in step with
40
- // the actor's defaultRunOptions.
41
- const url = `https://api.apify.com/v2/acts/${actorPath}/run-sync-get-dataset-items?timeout=300&memory=512`;
42
- let response;
43
- try {
44
- response = await fetch(url, {
45
- method: "POST",
46
- headers: {
47
- Authorization: `Bearer ${APIFY_TOKEN}`,
48
- "Content-Type": "application/json",
49
- "User-Agent": USER_AGENT,
50
- },
51
- body: JSON.stringify(input),
52
- });
53
- }
54
- catch (err) {
55
- const message = err instanceof Error ? err.message : String(err);
56
- return { isError: true, content: [{ type: "text", text: `Could not reach the Apify API: ${message}` }] };
57
- }
58
- if (!response.ok) {
61
+ const headers = {
62
+ Authorization: `Bearer ${APIFY_TOKEN}`,
63
+ "Content-Type": "application/json",
64
+ "User-Agent": USER_AGENT,
65
+ };
66
+ const httpError = async (response) => {
59
67
  let detail = "";
60
68
  try {
61
69
  const body = (await response.json());
@@ -65,27 +73,115 @@ async function runActor(actorPath, actorLabel, input) {
65
73
  catch {
66
74
  detail = "";
67
75
  }
68
- let message;
69
76
  switch (response.status) {
77
+ case 400:
78
+ return `The ${actorLabel} run was rejected as invalid input.${detail}`;
70
79
  case 401:
71
- message = "Invalid Apify token. Check your APIFY_TOKEN environment variable.";
72
- break;
80
+ return "Invalid Apify token. Check your APIFY_TOKEN environment variable.";
73
81
  case 402:
74
- message = "Insufficient Apify credits. Check your account balance at https://console.apify.com/billing";
75
- break;
76
- case 408:
77
- message = `The ${actorLabel} run timed out after 300 seconds. Try again, or run the actor on Apify directly for longer jobs.`;
78
- break;
82
+ return "Insufficient Apify credits. Check your account balance at https://console.apify.com/billing";
79
83
  default:
80
- message = `Apify request to ${actorLabel} failed with status ${response.status}.${detail}`;
84
+ return `Apify request to ${actorLabel} failed with status ${response.status}.${detail}`;
85
+ }
86
+ };
87
+ // 1. Start the run.
88
+ //
89
+ // memory=512 is deliberate and matches the actor's declared
90
+ // defaultRunOptions.memoryMbytes. A run started without it runs at 2048 MB,
91
+ // and `apify-actor-start` bills once per GB with a minimum of one, so leaving
92
+ // the default in place would charge the caller more start events per run than
93
+ // the actor asks for. Keep this in step with the actor's defaultRunOptions.
94
+ let started;
95
+ try {
96
+ started = await fetch(`https://api.apify.com/v2/acts/${actorPath}/runs?timeout=${ACTOR_RUN_TIMEOUT_SECS}&memory=512`, { method: "POST", headers, body: JSON.stringify(input) });
97
+ }
98
+ catch (err) {
99
+ const message = err instanceof Error ? err.message : String(err);
100
+ return { isError: true, content: [{ type: "text", text: `Could not reach the Apify API: ${message}` }] };
101
+ }
102
+ if (!started.ok) {
103
+ return { isError: true, content: [{ type: "text", text: await httpError(started) }] };
104
+ }
105
+ let run;
106
+ try {
107
+ run = (await started.json()).data ?? {};
108
+ }
109
+ catch (err) {
110
+ const message = err instanceof Error ? err.message : String(err);
111
+ return { isError: true, content: [{ type: "text", text: `The ${actorLabel} run start returned a response that could not be parsed: ${message}` }] };
112
+ }
113
+ const runId = run.id;
114
+ if (!runId) {
115
+ return { isError: true, content: [{ type: "text", text: `The ${actorLabel} run start returned no run id, so there is nothing to wait for.` }] };
116
+ }
117
+ // 2. Poll to a terminal status.
118
+ const deadline = Date.now() + WRAPPER_WAIT_MS;
119
+ let status = run.status ?? "READY";
120
+ let datasetId = run.defaultDatasetId;
121
+ while (!TERMINAL.has(status)) {
122
+ if (Date.now() >= deadline) {
123
+ return {
124
+ isError: true,
125
+ content: [{ type: "text", text: `The ${actorLabel} run ${runId} was still ${status} after ${Math.round(WRAPPER_WAIT_MS / 1000)} seconds and this call stopped waiting. The run itself is still on Apify: read it at https://console.apify.com/actors/runs/${runId}` }],
126
+ };
127
+ }
128
+ await sleep(POLL_INTERVAL_MS);
129
+ let poll;
130
+ try {
131
+ poll = await fetch(`https://api.apify.com/v2/actor-runs/${runId}`, { headers });
132
+ }
133
+ catch (err) {
134
+ const message = err instanceof Error ? err.message : String(err);
135
+ return { isError: true, content: [{ type: "text", text: `Lost contact with the Apify API while waiting for ${actorLabel} run ${runId}: ${message}` }] };
81
136
  }
82
- return { isError: true, content: [{ type: "text", text: message }] };
137
+ if (!poll.ok) {
138
+ return { isError: true, content: [{ type: "text", text: await httpError(poll) }] };
139
+ }
140
+ const body = (await poll.json());
141
+ status = body.data?.status ?? status;
142
+ datasetId = body.data?.defaultDatasetId ?? datasetId;
143
+ }
144
+ // 3. A run that did not succeed is a failure the caller must see, never an
145
+ // empty success. Surfacing it here is what keeps a crashed run from reading
146
+ // as "no results found".
147
+ if (status !== "SUCCEEDED") {
148
+ return {
149
+ isError: true,
150
+ content: [{ type: "text", text: `The ${actorLabel} run did not succeed (run ID: ${runId}, status: ${status}).` }],
151
+ };
152
+ }
153
+ if (!datasetId) {
154
+ return { isError: true, content: [{ type: "text", text: `The ${actorLabel} run ${runId} succeeded but reported no dataset, so there is nothing to return.` }] };
155
+ }
156
+ // 4. Read the dataset.
157
+ let ds;
158
+ try {
159
+ ds = await fetch(`https://api.apify.com/v2/datasets/${datasetId}/items?format=json`, { headers });
160
+ }
161
+ catch (err) {
162
+ const message = err instanceof Error ? err.message : String(err);
163
+ return { isError: true, content: [{ type: "text", text: `Could not read the ${actorLabel} dataset: ${message}` }] };
164
+ }
165
+ if (!ds.ok) {
166
+ return { isError: true, content: [{ type: "text", text: await httpError(ds) }] };
167
+ }
168
+ let items;
169
+ try {
170
+ items = await ds.json();
171
+ }
172
+ catch (err) {
173
+ const message = err instanceof Error ? err.message : String(err);
174
+ return { isError: true, content: [{ type: "text", text: `The ${actorLabel} run returned a response that could not be parsed: ${message}` }] };
175
+ }
176
+ if (!Array.isArray(items)) {
177
+ const asObj = items;
178
+ const detail = asObj?.error?.message
179
+ ? `${asObj.error.message}`
180
+ : JSON.stringify(items);
181
+ return { isError: true, content: [{ type: "text", text: `The ${actorLabel} run did not return a dataset. ${detail}` }] };
83
182
  }
84
- // A 2xx normally carries the dataset array. Pass actor output through
85
- // unchanged: the wrapper must never reinterpret a status field, because
86
- // not_extractable, blocked and not_found are different answers and collapsing
87
- // them is exactly the defect the actor was built to avoid.
88
- const items = await response.json();
183
+ // Pass actor output through unchanged: the wrapper never reinterprets a
184
+ // status field.
89
185
  return { content: [{ type: "text", text: JSON.stringify(items, null, 2) }] };
90
186
  }
91
187
  const server = new McpServer({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mambalabsdev/mcp-linkedin-company-presence-mapper",
3
- "version": "1.0.0",
3
+ "version": "1.1.1",
4
4
  "description": "MCP server for the Mamba Labs LinkedIn Company Page Mapper actor on Apify. Resolve a company domain to its LinkedIn page with the exact follower count and public firmographics.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -14,6 +14,7 @@
14
14
  ],
15
15
  "scripts": {
16
16
  "build": "tsc && chmod +x build/index.js",
17
+ "test": "npm run build && node --test test/*.test.js",
17
18
  "prepublishOnly": "npm run build"
18
19
  },
19
20
  "keywords": [
@@ -37,12 +38,12 @@
37
38
  "node": ">=18"
38
39
  },
39
40
  "dependencies": {
40
- "@modelcontextprotocol/sdk": "^1.12.0",
41
- "zod": "^3.23.8"
41
+ "@modelcontextprotocol/sdk": "^1.32.0",
42
+ "zod": "^4.5.4"
42
43
  },
43
44
  "devDependencies": {
44
- "@types/node": "^20.14.0",
45
- "typescript": "^5.6.0"
45
+ "@types/node": "^26.4.1",
46
+ "typescript": "5.9.3"
46
47
  },
47
48
  "mcpName": "com.mambabuilt/mcp-linkedin-company-presence-mapper"
48
49
  }