linkedin-relay-mcp 3.4.0 → 3.5.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.
@@ -187,10 +187,10 @@ Writes are **not on the MCP surface**. They exist only as CLI commands:
187
187
 
188
188
  | command | does |
189
189
  |---|---|
190
- | `lnrelay share "<text>" [--image <path> ... [--alt "…" ...] \| --video <path> \| --document <pdf> --title "…"] [--at "YYYY-MM-DD HH:MM"]` | post to their own feed — up to 20 images, one video, or one PDF; `--at` schedules it and LinkedIn publishes it then |
190
+ | `lnrelay share "<text>" [--image <path> ... [--alt "…" ...] \| --video <path> \| --document <pdf> --title "…"] [--at "YYYY-MM-DD HH:MM"] [--poll "…" --option "…" --option "…" [--duration 1w]]` | post to their own feed — up to 20 images, one video, or one PDF; `--at` schedules it and LinkedIn publishes it then |
191
191
  | `lnrelay comment <activity-urn> "<text>"` | comment on a post |
192
192
  | `lnrelay reply <comment-urn> "<text>"` | reply, nested under that comment |
193
- | `lnrelay edit <comment-urn> "<text>"` | change the text of their own comment |
193
+ | `lnrelay edit <comment-urn \| share-urn \| ugcPost-urn> "<text>"` | change the text of their own comment or post |
194
194
  | `lnrelay react <urn> [--type X] [--remove]` | react to a post or comment |
195
195
  | `lnrelay delete <activity-urn \| comment-urn>` | delete their post or comment |
196
196
 
@@ -225,6 +225,9 @@ Things worth telling a user who asks:
225
225
  needed at all: `docs/DECISION-writes.md`.
226
226
  - `--image` / `--video` upload over the private API only; `--via oauth` with media is refused. A
227
227
  video post comes back as a `urn:li:ugcPost:` rather than `urn:li:share:`.
228
+ - Editing a post replaces its whole text and LinkedIn marks it edited; pass the urn `share` printed
229
+ (or `shareUrn` from `my-posts`), not the activity urn. An @mention in the old text is not kept.
230
+ - A poll takes 2–4 options and runs 1d/3d/1w/2w; it cannot be scheduled yet.
228
231
  - A scheduled post gets its urn immediately; `lnrelay delete <urn>` cancels it before it publishes.
229
232
  `--at` without an offset is the machine's local time — say the time back to the user in the
230
233
  preview's own words, which name the timezone.
package/dist/cli.js CHANGED
@@ -1330,6 +1330,17 @@ var CONTRACTS = {
1330
1330
  // KNOWN INCOMPLETE (2026-08-13): with the namespace fixed this returns the
1331
1331
  // owner's posts, but a post created minutes earlier did not appear here, nor
1332
1332
  // in `feed`, over ~1.5 hours. Whether that is an indexing lag or a coverage
1333
+ // A WRITE contract: creates a poll object that a post then references. The
1334
+ // queryId is from mguttmann/linkedin-internal-api (docs/24) and returned a
1335
+ // pollSummary urn on this machine on the date below.
1336
+ createPoll: {
1337
+ name: "createPoll",
1338
+ transport: "voyager-graphql",
1339
+ path: `${VOYAGER}/graphql`,
1340
+ queryId: "voyagerFeedDashPollsPollSummary.f8ad99cf791d833d37dddb373d06fb3a",
1341
+ provenance: "verified",
1342
+ capturedAt: "2026-10-13"
1343
+ },
1333
1344
  // limit of this projection is UNRESOLVED — do not treat this endpoint as an
1334
1345
  // authoritative "all my posts" until it is settled.
1335
1346
  myPosts: {
@@ -2234,6 +2245,7 @@ async function uploadMedia(file, client) {
2234
2245
  var VOYAGER2 = "https://www.linkedin.com/voyager/api";
2235
2246
  var SHARE_URL = `${VOYAGER2}/contentcreation/normShares`;
2236
2247
  var CATEGORY = {
2248
+ POLL: "URN_REFERENCE",
2237
2249
  IMAGE: "IMAGE",
2238
2250
  VIDEO: "VIDEO",
2239
2251
  DOCUMENT: "NATIVE_DOCUMENT"
@@ -2306,6 +2318,12 @@ async function share(confirmed, client, bytes) {
2306
2318
  }
2307
2319
  }
2308
2320
  const media = [];
2321
+ const { poll } = confirmed.payload;
2322
+ if (poll !== void 0) {
2323
+ const created = await createPoll(poll, client);
2324
+ if (!created.ok) return created;
2325
+ media.push({ category: "POLL", urn: created.urn });
2326
+ }
2309
2327
  for (const [i, a] of approved.entries()) {
2310
2328
  const uploaded = await uploadMedia(
2311
2329
  {
@@ -2349,6 +2367,85 @@ async function share(confirmed, client, bytes) {
2349
2367
  note: "LinkedIn accepted the post but the response carried no recognisable urn. Run `lnrelay sync my-posts && lnrelay my-posts` to confirm what actually landed \u2014 and do NOT re-run this command on the assumption it failed, or you will post twice."
2350
2368
  } : { ok: true, id };
2351
2369
  }
2370
+ function editPostBody(text2) {
2371
+ return { patch: { $set: { commentaryV2: { text: text2, attributes: [] } } } };
2372
+ }
2373
+ async function editPost(confirmed, client) {
2374
+ const { urn, text: text2 } = confirmed.payload;
2375
+ const result = await client.request({
2376
+ url: deleteUrl(urn),
2377
+ method: "POST",
2378
+ body: editPostBody(text2),
2379
+ spendClass: "write",
2380
+ operation: "edit-post"
2381
+ });
2382
+ if (!result.ok) {
2383
+ const out = { ok: false, code: result.code, message: result.message };
2384
+ if (result.hint !== void 0) out.hint = result.hint;
2385
+ return out;
2386
+ }
2387
+ const held = result.json?.data?.commentary?.text;
2388
+ if (held !== text2) {
2389
+ return {
2390
+ ok: false,
2391
+ code: "SCHEMA_DRIFT",
2392
+ message: "LinkedIn answered, but the post does not hold the text that was sent",
2393
+ hint: `Look at the post before trying again: \`lnrelay post\` or the browser. ${urn}`
2394
+ };
2395
+ }
2396
+ return { ok: true, id: urn };
2397
+ }
2398
+ var DURATIONS = {
2399
+ "1d": "ONE_DAY",
2400
+ "3d": "THREE_DAYS",
2401
+ "1w": "ONE_WEEK",
2402
+ "2w": "TWO_WEEKS"
2403
+ };
2404
+ function pollDuration(shorthand) {
2405
+ return DURATIONS[shorthand] ?? null;
2406
+ }
2407
+ function gqlError(json) {
2408
+ const j = json;
2409
+ const errors = j?.errors ?? j?.data?.errors;
2410
+ return errors !== void 0 && errors.length > 0 ? errors[0]?.message ?? "GraphQL error" : null;
2411
+ }
2412
+ function pollUrnOf(json) {
2413
+ if (gqlError(json) !== null) return null;
2414
+ return JSON.stringify(json ?? null).match(/urn:li:fsd_pollSummary:\d+/)?.[0] ?? null;
2415
+ }
2416
+ async function createPoll(poll, client) {
2417
+ const contract = contractFor("createPoll");
2418
+ if (contract?.queryId === void 0) {
2419
+ return { ok: false, code: "NOT_IMPLEMENTED", message: "no verified poll contract" };
2420
+ }
2421
+ const result = await client.request({
2422
+ url: `${contract.path}?action=execute&queryId=${contract.queryId}`,
2423
+ method: "POST",
2424
+ body: { variables: { poll }, queryId: contract.queryId, includeWebMetadata: true },
2425
+ spendClass: "write",
2426
+ operation: "create-poll"
2427
+ });
2428
+ if (!result.ok)
2429
+ return { ok: false, code: result.code, message: `${result.message}; nothing was posted` };
2430
+ const error = gqlError(result.json);
2431
+ if (error !== null) {
2432
+ return {
2433
+ ok: false,
2434
+ code: "INVALID_INPUT",
2435
+ message: `LinkedIn refused the poll: ${error}; nothing was posted`
2436
+ };
2437
+ }
2438
+ const urn = pollUrnOf(result.json);
2439
+ if (urn === null) {
2440
+ return {
2441
+ ok: false,
2442
+ code: "SCHEMA_DRIFT",
2443
+ message: "the poll mutation answered without a poll urn; nothing was posted",
2444
+ hint: "The queryId may have rotated \u2014 recapture it (docs/ENGINE-RESEARCH.md)."
2445
+ };
2446
+ }
2447
+ return { ok: true, urn };
2448
+ }
2352
2449
 
2353
2450
  // src/commands/gate.ts
2354
2451
  import { createInterface } from "readline/promises";
@@ -3341,7 +3438,7 @@ var COMMANDS = [
3341
3438
  name: "share",
3342
3439
  cost: "1 call \u2014 write",
3343
3440
  summary: "Post to your own feed. Prefers LinkedIn's official OAuth scope, falls back to the private API when no token exists \u2014 the prompt always names which.",
3344
- usage: 'lnrelay share "<text>" [--image <path> ... [--alt "<text>" ...] | --video <path>\n | --document <pdf> --title "<title>"] [--at "YYYY-MM-DD HH:MM"]\n [--visibility public|connections] [--via oauth|voyager] [--plan | --confirm <token>]\n Approval follows `lnrelay approval`: --plan previews and returns a token without\n sending; --confirm <token> sends it in agent mode. In interactive mode it asks at a\n terminal. --image repeats for up to 20, --alt pairs with it by position (--alt ""\n skips one). --at schedules it (local time, or ISO 8601 with an offset; at least 10\n minutes out); LinkedIn publishes it then, and `lnrelay delete <urn>` cancels it.\n Files, documents and scheduling go over the private API only.',
3441
+ usage: 'lnrelay share "<text>" [--image <path> ... [--alt "<text>" ...] | --video <path>\n | --document <pdf> --title "<title>"] [--at "YYYY-MM-DD HH:MM"]\n [--poll "<question>" --option "<a>" --option "<b>" ... [--duration 1d|3d|1w|2w]]\n [--visibility public|connections] [--via oauth|voyager] [--plan | --confirm <token>]\n Approval follows `lnrelay approval`: --plan previews and returns a token without\n sending; --confirm <token> sends it in agent mode. In interactive mode it asks at a\n terminal. --image repeats for up to 20, --alt pairs with it by position (--alt ""\n skips one). --at schedules it (local time, or ISO 8601 with an offset; at least 10\n minutes out); LinkedIn publishes it then, and `lnrelay delete <urn>` cancels it.\n --poll takes 2-4 --option and cannot be scheduled yet. Files, documents, polls and\n scheduling go over the private API only.',
3345
3442
  audience: ["cli"],
3346
3443
  risk: "write",
3347
3444
  implemented: true
@@ -3376,8 +3473,8 @@ var COMMANDS = [
3376
3473
  {
3377
3474
  name: "edit",
3378
3475
  cost: "1 read + 1 write",
3379
- summary: "Change the text of a comment you wrote. Its own verb, so a comment urn can never be mistaken for something to comment ON.",
3380
- usage: 'lnrelay edit <comment-urn> "<text>"',
3476
+ summary: "Change the text of a comment or post you wrote. Its own verb, so a comment urn can never be mistaken for something to comment ON.",
3477
+ usage: 'lnrelay edit <comment-urn | share-urn | ugcPost-urn> "<text>"\n A post is edited by the urn it was created as (`share` prints it; `my-posts` lists\n it as shareUrn), not its activity urn. The whole text is replaced.',
3381
3478
  audience: ["cli"],
3382
3479
  risk: "write",
3383
3480
  implemented: true
@@ -4114,6 +4211,63 @@ function mediaFrom(media, via2) {
4114
4211
  }
4115
4212
  return loaded;
4116
4213
  }
4214
+ function sharePlan(p) {
4215
+ const payload = { text: p.text, visibility: p.visibility };
4216
+ if (p.media !== void 0) payload.media = p.media;
4217
+ if (p.scheduledAt !== void 0) payload.scheduledAt = p.scheduledAt;
4218
+ if (p.poll !== void 0) payload.poll = p.poll;
4219
+ const scheduled = p.scheduledAt !== void 0;
4220
+ return {
4221
+ action: scheduled ? "schedule a post" : "post to your feed",
4222
+ payload,
4223
+ summary: [
4224
+ p.author,
4225
+ `content "${p.text}"`,
4226
+ `audience ${p.visibility}`,
4227
+ ...p.scheduledAt === void 0 ? [] : [whenLine(p.scheduledAt, p.now)],
4228
+ ...p.poll === void 0 ? [] : pollLines(p.poll),
4229
+ ...p.media === void 0 ? [] : mediaLines(p.media)
4230
+ ],
4231
+ reversibility: scheduled ? "cancel any time before it publishes with `lnrelay delete <urn>`; after that it is public under your name like any post" : "deletable with `lnrelay delete <urn>`, but it is public under your name the moment it lands and anyone who saw it cannot un-see it",
4232
+ transport: p.transport
4233
+ };
4234
+ }
4235
+ function pollLines(poll) {
4236
+ return [
4237
+ `poll "${poll.question}"`,
4238
+ ...poll.options.map((o, i) => ` ${i + 1}. ${o}`),
4239
+ ` runs ${poll.duration}`
4240
+ ];
4241
+ }
4242
+ function pollFrom(poll, ctx) {
4243
+ if (poll === void 0) return void 0;
4244
+ const refuse2 = (message, hint) => err("share", "INVALID_INPUT", message, hint);
4245
+ if (poll.question.trim() === "") return refuse2("a poll needs a question");
4246
+ const options = poll.options.map((o) => o.trim());
4247
+ if (options.length < 2 || options.length > 4 || options.some((o) => o === "")) {
4248
+ return refuse2("a poll needs 2 to 4 non-empty options", 'repeat --option "<text>" for each');
4249
+ }
4250
+ const duration = pollDuration(poll.duration ?? "1w");
4251
+ if (duration === null) {
4252
+ return refuse2(`unknown --duration '${poll.duration}'`, "one of: 1d, 3d, 1w, 2w");
4253
+ }
4254
+ if (ctx.hasMedia) return refuse2("a post carries a poll or files, not both");
4255
+ if (ctx.scheduled) {
4256
+ return refuse2(
4257
+ "a poll cannot be scheduled yet \u2014 its clock may start when it is created, not published",
4258
+ "post the poll now, or schedule a text post that asks the question"
4259
+ );
4260
+ }
4261
+ if (ctx.via === "oauth") {
4262
+ return err(
4263
+ "share",
4264
+ "NOT_IMPLEMENTED",
4265
+ "polls are only implemented over the private API",
4266
+ "drop --via oauth, or pass --via voyager"
4267
+ );
4268
+ }
4269
+ return { question: poll.question.trim(), options, duration };
4270
+ }
4117
4271
  function scheduleFrom(at, now, via2) {
4118
4272
  if (at === void 0) return void 0;
4119
4273
  const t = parseScheduleTime(at);
@@ -4158,7 +4312,7 @@ function whenLine(at, now) {
4158
4312
  const away = hours < 48 ? `in ${hours} h` : `in ${Math.round(hours / 24)} days`;
4159
4313
  return `when ${local} (${zone}) \u2014 ${away}`;
4160
4314
  }
4161
- async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps(), via2, media, at) {
4315
+ async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps(), via2, media, at, poll) {
4162
4316
  if (text2 === void 0 || text2.trim() === "") {
4163
4317
  return err("share", "INVALID_INPUT", "text is required", 'lnrelay share "<text>"');
4164
4318
  }
@@ -4168,29 +4322,30 @@ async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps
4168
4322
  const scheduledAt = scheduled;
4169
4323
  const loaded = mediaFrom(media, via2);
4170
4324
  if (loaded !== void 0 && "ok" in loaded) return loaded;
4171
- const voyagerOnly = loaded !== void 0 || scheduledAt !== void 0;
4325
+ const pollSpec = pollFrom(poll, {
4326
+ hasMedia: loaded !== void 0,
4327
+ scheduled: scheduledAt !== void 0,
4328
+ via: via2
4329
+ });
4330
+ if (pollSpec !== void 0 && "ok" in pollSpec) return pollSpec;
4331
+ const voyagerOnly = loaded !== void 0 || scheduledAt !== void 0 || pollSpec !== void 0;
4172
4332
  const ctx = prepare(
4173
4333
  "share",
4174
4334
  now,
4175
4335
  voyagerOnly ? "voyager" : via2,
4176
- 2 * (loaded?.approved.length ?? 0) + 1
4336
+ 2 * (loaded?.approved.length ?? 0) + (pollSpec === void 0 ? 0 : 1) + 1
4177
4337
  );
4178
4338
  if ("ok" in ctx) return ctx;
4179
- const payload = { text: text2, visibility: vis };
4180
- if (scheduledAt !== void 0) payload.scheduledAt = scheduledAt;
4181
- const summary = [authorLine(ctx.transport), `content "${text2}"`, `audience ${vis}`];
4182
- if (scheduledAt !== void 0) summary.push(whenLine(scheduledAt, now));
4183
- if (loaded !== void 0) {
4184
- payload.media = loaded.approved;
4185
- summary.push(...mediaLines(loaded.approved));
4186
- }
4187
- const plan = {
4188
- action: scheduledAt === void 0 ? "post to your feed" : "schedule a post",
4189
- payload,
4190
- summary,
4191
- reversibility: scheduledAt === void 0 ? "deletable with `lnrelay delete <urn>`, but it is public under your name the moment it lands and anyone who saw it cannot un-see it" : "cancel any time before it publishes with `lnrelay delete <urn>`; after that it is public under your name like any post",
4192
- transport: ctx.transport.kind
4193
- };
4339
+ const plan = sharePlan({
4340
+ author: authorLine(ctx.transport),
4341
+ transport: ctx.transport.kind,
4342
+ text: text2,
4343
+ visibility: vis,
4344
+ media: loaded?.approved,
4345
+ scheduledAt,
4346
+ poll: pollSpec,
4347
+ now
4348
+ });
4194
4349
  const gated = await gate("share", plan, ctx, deps);
4195
4350
  if ("ok" in gated) return gated;
4196
4351
  const result = ctx.transport.kind === "oauth" ? await share2(gated.confirmed, ctx.transport.token, {
@@ -4206,6 +4361,36 @@ async function runShare(text2, visibility, now = Date.now(), deps = terminalDeps
4206
4361
  note: "note" in result ? result.note : ctx.note
4207
4362
  });
4208
4363
  }
4364
+ async function runEditPost(urn, text2, now, deps) {
4365
+ const unapprovable = refuseUnapprovable("edit", "editing", deps);
4366
+ if (unapprovable !== null) return unapprovable;
4367
+ const ctx = prepare("edit", now, "voyager");
4368
+ if ("ok" in ctx) return ctx;
4369
+ if (ctx.transport.kind !== "voyager") {
4370
+ return err(
4371
+ "edit",
4372
+ "NOT_IMPLEMENTED",
4373
+ "editing a post is only implemented over the private API"
4374
+ );
4375
+ }
4376
+ const before = await lookup(urn, true);
4377
+ const plan = {
4378
+ action: "edit your post",
4379
+ payload: { urn, text: text2 },
4380
+ summary: [
4381
+ authorLine(ctx.transport),
4382
+ `post ${urn}`,
4383
+ ...previewLines2(before).map((l) => l.replace(/^content /, "was ")),
4384
+ `new text "${text2}"`
4385
+ ],
4386
+ reversibility: "editable again, but the previous text is NOT kept here, LinkedIn marks the post as edited, and an @mention in the old text is not carried over",
4387
+ transport: "voyager"
4388
+ };
4389
+ const gated = await gate("edit", plan, ctx, deps);
4390
+ if ("ok" in gated) return gated;
4391
+ const result = await editPost(gated.confirmed, createLiveClient(ctx.transport.session));
4392
+ return result.ok ? ok("edit", { edited: urn }) : err("edit", result.code, result.message, result.hint);
4393
+ }
4209
4394
  function activityIdOf(urn) {
4210
4395
  return /^urn:li:(?:activity|ugcPost|share):(\d+)$/.exec(urn)?.[1] ?? null;
4211
4396
  }
@@ -4300,11 +4485,14 @@ async function runEdit(commentUrn, text2, now = Date.now(), deps = terminalDeps(
4300
4485
  }
4301
4486
  const ref = parseCommentUrn(commentUrn);
4302
4487
  if (ref === null) {
4488
+ if (/^urn:li:(share|ugcPost):\d+$/.test(commentUrn)) {
4489
+ return runEditPost(commentUrn, text2, now, deps);
4490
+ }
4303
4491
  return err(
4304
4492
  "edit",
4305
4493
  "INVALID_INPUT",
4306
- `'${commentUrn}' is not a comment urn`,
4307
- "Only comments can be edited here \u2014 a published post cannot. Get the urn from `lnrelay post <activity-urn>`."
4494
+ `'${commentUrn}' is neither a comment urn nor a post's share/ugcPost urn`,
4495
+ /^urn:li:activity:/.test(commentUrn) ? "A post is edited by the urn it was created as, not its activity urn. `lnrelay share` prints it, and `lnrelay my-posts` lists it as shareUrn." : "Pass a comment urn (from `lnrelay post <activity-urn>`) or a post urn (urn:li:share:\u2026 / urn:li:ugcPost:\u2026)."
4308
4496
  );
4309
4497
  }
4310
4498
  const unapprovable = refuseUnapprovable("edit", "editing", deps);
@@ -4640,7 +4828,17 @@ function share3(args, now, deps) {
4640
4828
  "one of: oauth, voyager. Omit it to prefer OAuth and fall back to Voyager."
4641
4829
  );
4642
4830
  }
4643
- for (const flag of ["image", "video", "document", "alt", "title", "at"]) {
4831
+ for (const flag of [
4832
+ "image",
4833
+ "video",
4834
+ "document",
4835
+ "alt",
4836
+ "title",
4837
+ "at",
4838
+ "poll",
4839
+ "option",
4840
+ "duration"
4841
+ ]) {
4644
4842
  if (args.flags[flag] === true) {
4645
4843
  return err("share", "INVALID_INPUT", `--${flag} needs a value`);
4646
4844
  }
@@ -4668,6 +4866,17 @@ function share3(args, now, deps) {
4668
4866
  "--alt and --title describe an attached file, and none was given"
4669
4867
  );
4670
4868
  }
4869
+ const question = str(args, "poll");
4870
+ const options = list(args, "option");
4871
+ if (question === void 0 && (options.length > 0 || str(args, "duration") !== void 0)) {
4872
+ return err("share", "INVALID_INPUT", '--option and --duration belong to a --poll "<question>"');
4873
+ }
4874
+ let poll;
4875
+ if (question !== void 0) {
4876
+ poll = { question, options };
4877
+ const duration = str(args, "duration");
4878
+ if (duration !== void 0) poll.duration = duration;
4879
+ }
4671
4880
  return runShare(
4672
4881
  args.positionals[0],
4673
4882
  str(args, "visibility") ?? "public",
@@ -4675,7 +4884,8 @@ function share3(args, now, deps) {
4675
4884
  deps,
4676
4885
  surface,
4677
4886
  media,
4678
- str(args, "at")
4887
+ str(args, "at"),
4888
+ poll
4679
4889
  );
4680
4890
  }
4681
4891
  export {