linkedin-relay-mcp 3.22.0 → 3.23.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/.claude/skills/linkedin-relay/SKILL.md +14 -1
- package/README.md +1 -0
- package/dist/cli.js +213 -0
- package/dist/cli.js.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-shim.js +217 -0
- package/dist/mcp-shim.js.map +1 -1
- package/package.json +1 -1
package/dist/mcp-shim.js
CHANGED
|
@@ -5748,6 +5748,15 @@ var COMMANDS = [
|
|
|
5748
5748
|
risk: "read",
|
|
5749
5749
|
implemented: true
|
|
5750
5750
|
},
|
|
5751
|
+
{
|
|
5752
|
+
name: "viewers",
|
|
5753
|
+
cost: "2 page calls",
|
|
5754
|
+
summary: "Who viewed your profile, as your profile-views page shows it: the total for the period, the viewers LinkedIn names (up to 3 on a free account), anonymous ones as LinkedIn describes them, and how many looked in private mode.",
|
|
5755
|
+
usage: "lnrelay viewers [--compact | --fields a,b,c]",
|
|
5756
|
+
audience: ["cli", "mcp"],
|
|
5757
|
+
risk: "read",
|
|
5758
|
+
implemented: true
|
|
5759
|
+
},
|
|
5751
5760
|
{
|
|
5752
5761
|
name: "network",
|
|
5753
5762
|
cost: "1 page call per 50 rows; the counts are 7 calls",
|
|
@@ -6539,6 +6548,208 @@ async function runSkills(quiet = false) {
|
|
|
6539
6548
|
});
|
|
6540
6549
|
}
|
|
6541
6550
|
|
|
6551
|
+
// src/engine/profile-views.ts
|
|
6552
|
+
var SERVER_REQUEST = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
|
|
6553
|
+
var VIEWERS_URL = `${SERVER_REQUEST}?sduiid=WvmpEntityList`;
|
|
6554
|
+
var VIEW_TOTALS_URL = `${SERVER_REQUEST}?sduiid=WvmpAnalytics`;
|
|
6555
|
+
var RANGE = "WvmpSearchFilterType_DATE_RANGE";
|
|
6556
|
+
var META = { $type: "proto.sdui.common.RequestMetadata" };
|
|
6557
|
+
function serverRequest(requestId, stateKey, payload) {
|
|
6558
|
+
const state = {
|
|
6559
|
+
key: stateKey,
|
|
6560
|
+
namespace: "MemoryNamespace",
|
|
6561
|
+
value: [],
|
|
6562
|
+
originalProtoCase: "stringListValue",
|
|
6563
|
+
protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id: stateKey } }
|
|
6564
|
+
};
|
|
6565
|
+
const requestedArguments = {
|
|
6566
|
+
$type: "proto.sdui.actions.requests.RequestedArguments",
|
|
6567
|
+
requestedStateKeys: [{ key: { value: { $case: "id", id: stateKey } } }],
|
|
6568
|
+
payload: {
|
|
6569
|
+
...payload,
|
|
6570
|
+
filterTypeList: [RANGE],
|
|
6571
|
+
dateRangeSelectionFilters: { key: stateKey, namespace: "MemoryNamespace" }
|
|
6572
|
+
},
|
|
6573
|
+
requestMetadata: META
|
|
6574
|
+
};
|
|
6575
|
+
return {
|
|
6576
|
+
requestId,
|
|
6577
|
+
serverRequest: {
|
|
6578
|
+
requestId,
|
|
6579
|
+
requestedArguments,
|
|
6580
|
+
isApfcEnabled: false,
|
|
6581
|
+
isStreaming: false,
|
|
6582
|
+
rumPageKey: ""
|
|
6583
|
+
},
|
|
6584
|
+
states: [state],
|
|
6585
|
+
requestedArguments: {
|
|
6586
|
+
...requestedArguments,
|
|
6587
|
+
states: [state],
|
|
6588
|
+
screenId: "com.linkedin.sdui.flagshipnav.home.Home",
|
|
6589
|
+
knownTemplateIds: []
|
|
6590
|
+
}
|
|
6591
|
+
};
|
|
6592
|
+
}
|
|
6593
|
+
function viewersBody() {
|
|
6594
|
+
return serverRequest("WvmpEntityList", `entityListQueryFilterPrefix${RANGE}`, {
|
|
6595
|
+
sortType: "ProfileViewSortType_TIME_DESCENDING"
|
|
6596
|
+
});
|
|
6597
|
+
}
|
|
6598
|
+
function viewTotalsBody() {
|
|
6599
|
+
return serverRequest("WvmpAnalytics", `analyticsFieldsFilterPrefix${RANGE}`, {
|
|
6600
|
+
highlightCardDimensions: [
|
|
6601
|
+
"DimensionType_LOCATION",
|
|
6602
|
+
"DimensionType_INDUSTRY",
|
|
6603
|
+
"DimensionType_ORGANIZATION"
|
|
6604
|
+
],
|
|
6605
|
+
detailsCardDimensions: ["DimensionType_ORGANIZATION"],
|
|
6606
|
+
highlightCardResultCount: 4,
|
|
6607
|
+
detailsCardResultCount: 23
|
|
6608
|
+
});
|
|
6609
|
+
}
|
|
6610
|
+
var drift10 = (message) => ({ ok: false, code: "SCHEMA_DRIFT", message });
|
|
6611
|
+
var unquote3 = (s) => JSON.parse(`"${s}"`);
|
|
6612
|
+
var STR = '((?:[^"\\\\]|\\\\.)+)';
|
|
6613
|
+
var ITEM = /"viewName":"viewer-list-item"(?:,"impressionThresholds":\[[^\]]*\])?[^{}]*"semanticPosition"/;
|
|
6614
|
+
var TEXT_PROPS = /"textProps":\{"fontFamily":"[^"]*","fontSize":"(\w+)","fontStyle":"[^"]*","fontWeight":"(\w+)","lineHeight":"[^"]*","textAlign":"[^"]*","children":/g;
|
|
6615
|
+
var OWN_TEXT = new RegExp(`^\\["${STR}"\\]`);
|
|
6616
|
+
var NESTED_TEXT = new RegExp(`\\[null,"${STR}"`);
|
|
6617
|
+
var LINK2 = new RegExp(`"urlValue":\\{"\\$case":"url","url":"${STR}"`);
|
|
6618
|
+
var PROFILE_ID2 = /ACoA[A-Za-z0-9_-]{10,}/;
|
|
6619
|
+
var PLAIN_TEXT = new RegExp(`"children":\\["${STR}"\\]`, "g");
|
|
6620
|
+
function textsOf(row) {
|
|
6621
|
+
return [...row.matchAll(TEXT_PROPS)].flatMap((m) => {
|
|
6622
|
+
const after = row.slice((m.index ?? 0) + m[0].length, (m.index ?? 0) + m[0].length + 600);
|
|
6623
|
+
const raw = after.match(OWN_TEXT)?.[1] ?? after.match(NESTED_TEXT)?.[1];
|
|
6624
|
+
if (raw === void 0) return [];
|
|
6625
|
+
const text6 = unquote3(raw).trim();
|
|
6626
|
+
return text6 === "" ? [] : [{ size: m[1], weight: m[2], text: text6 }];
|
|
6627
|
+
});
|
|
6628
|
+
}
|
|
6629
|
+
function viewerOf(row, id) {
|
|
6630
|
+
const texts3 = textsOf(row);
|
|
6631
|
+
const at = texts3.findIndex((t) => t.size === "medium" && t.weight === "bold");
|
|
6632
|
+
const first = texts3[at]?.text;
|
|
6633
|
+
if (first === void 0) return void 0;
|
|
6634
|
+
const rest = texts3.slice(at + 1).map((t) => t.text);
|
|
6635
|
+
const degreeText = rest.find((t) => t.startsWith("\u2022"));
|
|
6636
|
+
const lines = rest.filter((t) => t !== degreeText);
|
|
6637
|
+
const viewed = lines.at(-1);
|
|
6638
|
+
const link = row.match(LINK2)?.[1];
|
|
6639
|
+
const url = link === void 0 ? void 0 : unquote3(link);
|
|
6640
|
+
if (url === void 0 || !/linkedin\.com\/in\//.test(url)) {
|
|
6641
|
+
const v = { anonymous: true, description: first };
|
|
6642
|
+
if (viewed !== void 0) v.viewed = viewed;
|
|
6643
|
+
if (url !== void 0) v.searchUrl = url;
|
|
6644
|
+
return v;
|
|
6645
|
+
}
|
|
6646
|
+
const degree = degreeText?.replace(/^•\s*/, "");
|
|
6647
|
+
const headline = lines.length > 1 ? lines[0] : void 0;
|
|
6648
|
+
return {
|
|
6649
|
+
name: first,
|
|
6650
|
+
...id !== void 0 ? { id } : {},
|
|
6651
|
+
url,
|
|
6652
|
+
...degree !== void 0 ? { degree } : {},
|
|
6653
|
+
...headline !== void 0 ? { headline } : {},
|
|
6654
|
+
...viewed !== void 0 ? { viewed } : {}
|
|
6655
|
+
};
|
|
6656
|
+
}
|
|
6657
|
+
var REF = /"\$[LQ]?([0-9a-f]+)"/g;
|
|
6658
|
+
function idUnder(rows, ref, items) {
|
|
6659
|
+
const seen = /* @__PURE__ */ new Set([ref]);
|
|
6660
|
+
const queue = [ref];
|
|
6661
|
+
while (queue.length > 0 && seen.size < 200) {
|
|
6662
|
+
const row = rows.byId.get(queue.shift()) ?? "";
|
|
6663
|
+
const id = row.match(PROFILE_ID2)?.[0];
|
|
6664
|
+
if (id !== void 0) return id;
|
|
6665
|
+
for (const m of row.matchAll(REF)) {
|
|
6666
|
+
const next = m[1];
|
|
6667
|
+
if (!seen.has(next) && !items.has(next) && rows.byId.has(next)) {
|
|
6668
|
+
seen.add(next);
|
|
6669
|
+
queue.push(next);
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
}
|
|
6673
|
+
return void 0;
|
|
6674
|
+
}
|
|
6675
|
+
function idsByViewer(rows, items) {
|
|
6676
|
+
const ids = /* @__PURE__ */ new Map();
|
|
6677
|
+
for (const row of rows.byId.values()) {
|
|
6678
|
+
let current;
|
|
6679
|
+
for (const m of row.matchAll(REF)) {
|
|
6680
|
+
const ref = m[1];
|
|
6681
|
+
if (items.has(ref)) current = ref;
|
|
6682
|
+
else if (current !== void 0 && !ids.has(current)) {
|
|
6683
|
+
const id = idUnder(rows, ref, items);
|
|
6684
|
+
if (id !== void 0) ids.set(current, id);
|
|
6685
|
+
}
|
|
6686
|
+
}
|
|
6687
|
+
}
|
|
6688
|
+
return ids;
|
|
6689
|
+
}
|
|
6690
|
+
function parseViewers(stream) {
|
|
6691
|
+
if (!stream.includes('"viewName":"viewer-list"'))
|
|
6692
|
+
return drift10("the profile viewers answer was not the viewer list");
|
|
6693
|
+
const rows = new Rows(stream);
|
|
6694
|
+
const items = new Set([...rows.byId].filter(([, row]) => ITEM.test(row)).map(([id]) => id));
|
|
6695
|
+
const ids = idsByViewer(rows, items);
|
|
6696
|
+
const viewers = [...items].flatMap((id) => viewerOf(rows.byId.get(id) ?? "", ids.get(id)) ?? []);
|
|
6697
|
+
const shown = Math.max(items.size, (stream.match(new RegExp(ITEM, "g")) ?? []).length);
|
|
6698
|
+
if (shown > 0 && viewers.length === 0)
|
|
6699
|
+
return drift10(`${shown} profile viewers were shown but none could be read`);
|
|
6700
|
+
let privateViewers;
|
|
6701
|
+
for (const [id, row] of rows.byId) {
|
|
6702
|
+
if (items.has(id) || privateViewers !== void 0) continue;
|
|
6703
|
+
for (const m of row.matchAll(PLAIN_TEXT)) {
|
|
6704
|
+
const n = unquote3(m[1]).match(/^(\d[\d.,\s]*)\s+\D/)?.[1];
|
|
6705
|
+
if (n !== void 0) {
|
|
6706
|
+
privateViewers = Number(n.replace(/\D/g, ""));
|
|
6707
|
+
break;
|
|
6708
|
+
}
|
|
6709
|
+
}
|
|
6710
|
+
}
|
|
6711
|
+
return privateViewers === void 0 ? { ok: true, viewers } : { ok: true, viewers, privateViewers };
|
|
6712
|
+
}
|
|
6713
|
+
function parseViewTotals(stream) {
|
|
6714
|
+
const texts3 = [...stream.matchAll(PLAIN_TEXT)].map((m) => unquote3(m[1]).trim());
|
|
6715
|
+
const at = texts3.findIndex((t) => /^\d[\d.,\s]*$/.test(t));
|
|
6716
|
+
if (at === -1) return drift10("the profile view totals carried no number");
|
|
6717
|
+
const total = Number(texts3[at].replace(/\D/g, ""));
|
|
6718
|
+
const period = texts3[at + 1];
|
|
6719
|
+
return period === void 0 ? { ok: true, total } : { ok: true, total, period };
|
|
6720
|
+
}
|
|
6721
|
+
|
|
6722
|
+
// src/commands/viewers.ts
|
|
6723
|
+
function liveFetch9(quiet) {
|
|
6724
|
+
const session = loadSession();
|
|
6725
|
+
if (session.state !== "ok")
|
|
6726
|
+
return err("viewers", "AUTH_FAILED", "no LinkedIn session \u2014 run `lnrelay login`");
|
|
6727
|
+
const client = createLiveClient(session.session, void 0, quiet);
|
|
6728
|
+
return async (url, body, spendClass) => {
|
|
6729
|
+
const r = await client.request({ url, method: "POST", body, spendClass, operation: "viewers" });
|
|
6730
|
+
if (!r.ok) return r;
|
|
6731
|
+
return { ok: true, raw: r.classification.raw ?? "" };
|
|
6732
|
+
};
|
|
6733
|
+
}
|
|
6734
|
+
var compactViewer = (v) => "anonymous" in v ? line(["anonymous", v.description, v.viewed]) : line([v.name, v.degree, v.headline, v.viewed, v.url]);
|
|
6735
|
+
async function runViewers(opts = {}, fetch2) {
|
|
6736
|
+
const get = fetch2 ?? liveFetch9(opts.quiet === true);
|
|
6737
|
+
if (typeof get !== "function") return get;
|
|
6738
|
+
const totalsRes = await get(VIEW_TOTALS_URL, viewTotalsBody(), "page");
|
|
6739
|
+
const totals = totalsRes.ok ? parseViewTotals(totalsRes.raw) : totalsRes;
|
|
6740
|
+
const listRes = await get(VIEWERS_URL, viewersBody(), "page");
|
|
6741
|
+
const list = listRes.ok ? parseViewers(listRes.raw) : listRes;
|
|
6742
|
+
if (!list.ok) return err("viewers", list.code, list.message, list.hint);
|
|
6743
|
+
const shown = list.viewers.length;
|
|
6744
|
+
const state = !totals.ok ? "unknown" : totals.total > shown ? "partial" : "complete";
|
|
6745
|
+
return ok("viewers", {
|
|
6746
|
+
...totals.ok ? { total: totals.total, ...totals.period !== void 0 ? { period: totals.period } : {} } : { totalError: `${totals.code}: ${totals.message}` },
|
|
6747
|
+
...list.privateViewers !== void 0 ? { privateViewers: list.privateViewers } : {},
|
|
6748
|
+
items: shape(list.viewers, opts, compactViewer),
|
|
6749
|
+
meta: { state, operation: "viewers", returnedCount: shown }
|
|
6750
|
+
});
|
|
6751
|
+
}
|
|
6752
|
+
|
|
6542
6753
|
// src/entry.ts
|
|
6543
6754
|
import { realpathSync } from "fs";
|
|
6544
6755
|
import { basename as basename2 } from "path";
|
|
@@ -6912,6 +7123,12 @@ function buildServer() {
|
|
|
6912
7123
|
)
|
|
6913
7124
|
)
|
|
6914
7125
|
);
|
|
7126
|
+
server.tool(
|
|
7127
|
+
"viewers",
|
|
7128
|
+
"Who viewed the user's profile, as their profile-views page shows it: total (over period, LinkedIn's words), privateViewers (a count only), and items \u2014 named viewers {name, id, url, degree, headline, viewed} and anonymous ones {anonymous, description, viewed, searchUrl}. A free account is shown up to 3, so meta.state is partial when total is higher. Degree and times are in the user's language. 2 page calls. " + NO_RETRY,
|
|
7129
|
+
{ compact: z.boolean().optional().describe("one line a viewer") },
|
|
7130
|
+
async ({ compact: compact2 }) => reply(await runViewers(compact2 === true ? { compact: true } : {}))
|
|
7131
|
+
);
|
|
6915
7132
|
server.tool(
|
|
6916
7133
|
"events",
|
|
6917
7134
|
`The events page's own lists: events LinkedIn recommends to the user, and its Premium LinkedIn Live events. Rows: id, name, when (as shown, in the user's language), organizer, attendees, premium, url. 1 page call. To find events by topic use \`search\` with kind events; to read one in full use \`event\`. ${NO_RETRY}`,
|