Kenso MCP tools

Email Sequences email_sequences

Campaign and segment email sequences. preview needs use_random: false with a contact_id, true to pick one. segment-email-sequences-delete removes a segment's sequence entirely.

Call it from an MCP client connected to https://mcp.ken.so/mcp: reads go through email_sequences_read and changes through email_sequences_write. Each takes operation plus that operation's parameters, and your workspace role decides which operations you see.

Each operation with a route calls the Kenso API at https://api.ken.so with Authorization: Bearer <Kenso API key>, Ken-Version: 1.1 and X-Ken-Workspace-Id: <workspace id>. You can call that route directly with the same headers.

Operations: delete, segment-email-sequences-delete, branching-sequences-get, get, segment-email-sequences-get, sequence-variables-get, get-version, list-versions, preview, segment-email-sequences-preview, sequence-imports-preview, branching-sequences-replace, replace, segment-email-sequences-replace, restore-version, save-version, test-send, segment-email-sequences-test-send, save_bundle_version

delete

Write. DELETE https://api.ken.so/v1/campaigns/{campaignId}/email-sequence

Path: campaignId

Delete the campaign email sequence. Returns 204. Requires sequence edit access.

DELETE /api/v1/campaigns/{campaignId}/email-sequence. Public. Sends Ken-Version 1.1.

segment-email-sequences-delete

Write. DELETE https://api.ken.so/v1/segments/{segmentId}/email-sequence

Path: segmentId

Delete the segment email sequence. Returns 204. Requires sequence edit access.

DELETE /api/v1/segments/{segmentId}/email-sequence. Public. Sends Ken-Version 1.1.

branching-sequences-get

Read. Early access: needs sequence_conditions on for the workspace. GET https://api.ken.so/v1/campaigns/{campaignId}/branching-sequence

Path: campaignId

Return a campaign's sequence with conditions, which conditions it can use, and per-step counts. Needs the sequence_conditions flag and Campaigns view.

GET /api/v1/campaigns/{campaignId}/branching-sequence. Sends Ken-Version 1.1; client_id is
sent as X-Ken-Workspace-Id. Returns {campaignId, segments, workflowId, modifiedAt,
conditions: [{kind, available, reason}], stats: [{nodeId, reached, completed}]}. segments is
empty when the campaign has no sequence with conditions (it sends its normal sequence).
email_opened is unavailable (reason open_tracking_off) on every campaign: campaign emails never
carry an open-tracking pixel, so opens are not tracked. A campaign of another workspace, or a
workspace without the flag, is 404.

get

Read. GET https://api.ken.so/v1/campaigns/{campaignId}/email-sequence

Path: campaignId

Return the campaign email sequence.

GET /api/v1/campaigns/{campaignId}/email-sequence. Public. Sends Ken-Version 1.1.
client_id is sent as X-Ken-Workspace-Id.

segment-email-sequences-get

Read. GET https://api.ken.so/v1/segments/{segmentId}/email-sequence

Path: segmentId

Return the segment email sequence.

GET /api/v1/segments/{segmentId}/email-sequence. Public. Sends Ken-Version 1.1.

sequence-variables-get

Read. GET https://api.ken.so/v1/sequence-variables

Query: campaignId integer

Read the sequence variable catalog. Pass campaign_id to add that campaign's custom variables. Requires Campaigns view.

GET /api/v1/sequence-variables. Public. Sends Ken-Version 1.1.
Replaces GET /v1/campaigns/email-sequence/variables. There is no clientId query.
A campaign outside the workspace is not_found before the catalog is returned.

get-version

Read. GET https://api.ken.so/v1/segments/{segmentId}/email-sequence/versions/{versionId}

Path: segmentId, versionId

Return one segment email sequence version. Snapshot step types are lowercase snake_case. Requires Campaigns view.

GET /api/v1/segments/{segmentId}/email-sequence/versions/{versionId}. Public. Sends Ken-Version 1.1.
A segment outside the workspace is not_found before the version read.
Snapshot steps carry handwrittenEnabled, handwrittenBackground and handwrittenIntro
(false and null for a version saved before handwritten letters existed).

list-versions

Read. GET https://api.ken.so/v1/segments/{segmentId}/email-sequence/versions

Path: segmentId

Query: cursor string, limit integer

List saved versions of a segment email sequence, newest first. limit is 1 to 100. Omit it for 20. Requires Campaigns view.

GET /api/v1/segments/{segmentId}/email-sequence/versions. Public. Sends Ken-Version 1.1.

preview

Read. GET https://api.ken.so/v1/campaigns/{campaignId}/email-sequence/preview

Path: campaignId

Query: contactId integer, language string, senderEmailId integer, useRandom boolean

Preview a campaign email sequence for one contact. use_random picks a contact when contact_id is omitted. sender_email_id previews from that campaign inbox. Requires Campaigns view.

GET /api/v1/campaigns/{campaignId}/email-sequence/preview. Public. Sends Ken-Version 1.1.
Variable types are lowercase snake_case. A campaign outside the workspace is not_found.
Each step shows the text dispatch sends the contact. A contact routed to another language
gets the approved localization: the step then carries language (fr-FR), mirrorSubject and
mirrorBody (the English mirror filled with the same variables) and qaScore (0-100); a step
in the source text has none of them. language (fr-FR, de) previews as a contact in that
language; the campaign's source language previews the source text. A language that is not
a language tag is validation_failed. sender_email_id (the test send's sender_email_id) fills
the sender names, signature and unsubscribe host from that inbox, and sender names it; an
inbox the campaign does not use, or none, previews from the first sender by email.

segment-email-sequences-preview

Read. GET https://api.ken.so/v1/segments/{segmentId}/email-sequence/preview

Path: segmentId

Query: contactId integer, language string, providerTrack string, senderEmailId integer, useRandom boolean

Preview a segment email sequence for one contact. use_random picks a contact when contact_id is omitted. sender_email_id previews from that campaign inbox. Requires Campaigns view.

GET /api/v1/segments/{segmentId}/email-sequence/preview. Public. Sends Ken-Version 1.1.
Variable types are lowercase snake_case. A segment outside the workspace is not_found.
language, sender_email_id, and the language, mirrorSubject, mirrorBody and qaScore of a
localized step, work as on email_sequences(operation="preview").
provider_track (google, microsoft or other): test or preview the email as that provider
track sends it; recipients on Google get plain text. A track's own sequenceSegmentId
implies its track. Each step's sendsPlainText is true when that track sends the step as
plain text; false with no track or on a campaign that is not on provider tracks. Any
other provider_track value is validation_failed (invalid_track).

sequence-imports-preview

Read. POST https://api.ken.so/v1/sequence-imports/previews

Body (json): source string, text string

Read a sequence from another tool (Origami, lemlist, Instantly, La Growth Machine) into Kenso steps. Returns the proposed email and LinkedIn steps with warnings. Saves nothing: save the kept steps with email_sequences(operation="replace") and linkedin.

POST /api/v1/sequence-imports/previews. Public. Sends Ken-Version 1.1.
The gateway path is /api/v1/sequence-imports/previews (backend POST
/v1/sequence-imports/previews). client_id is sent as X-Ken-Workspace-Id.
Requires campaigns edit.

text is the sequence as pasted or exported (required, at most 50,000
characters): lemlist's sequences JSON, an Instantly campaign JSON, any JSON
array of step objects, CSV with a header row (type or channel, delay or
wait, subject, body or message), or free text ("Step 2 - Email - 1 day
later / Subject: ... / Hey {{firstName}}, ..."). source is optional:
origami, lemlist, instantly, la_growth_machine or other.

JSON and CSV are read in code (parser "structured", no quota). Free text
takes one model call (parser "ai") that returns only the structure and the
lines that hold each subject and body; the copy is cut from the text, so it
comes back exactly as written. Free text counts on the workspace's
sequenceImportPreviews quota (30 an hour, 200 a day; past it a 429
quota_exceeded). Only placeholders change: {{firstName}} and the like
become Kenso variables for the step's channel ({company} on email,
{companyName} on LinkedIn).

Returns the API data object: steps (channel email or linkedin; stepType
email, connection_request, message, profile_visit, follow, like_post,
endorse_skill, comment_post or voice_note; waitDays 0-30 after the previous
step; condition none, accepted or not_accepted; waitFromCondition; subject
and body, null when absent, a null subject on a same-thread follow-up),
warnings (code, message, stepIndex; null stepIndex for a dropped step) and
parser. Warning codes: unsupported_step (calls, tasks, SMS dropped; the
wait moves on), in_mail (sent as a message), not_accepted_days (the N of
"not accepted after N days", which is the campaign's LinkedIn
notAcceptedAfterDays setting), unknown_variable, wait_clamped,
wait_rounded, condition_dropped, too_many_steps (over 30), variants_dropped,
body_dropped, missing_body, missing_subject, body_too_long,
unsupported_syntax, copy_not_found.

Errors: 400 validation_failed (blank or too long text, unknown source), 422
no_steps_found, 429 quota_exceeded, 503 provider_unavailable (the free-text
read failed; retry or paste CSV).

Examples:
- email_sequences(operation="sequence-imports-preview", text="Step 1 - LinkedIn connection request\n\nStep 2 - Email - 1 day later\nSubject: quick question\nHey {{firstName}}, ...", source="origami", client_id=7)
- email_sequences(operation="sequence-imports-preview", text="step,type,delay,subject,body\n1,email,0,Hi,Hey {{firstName}}", client_id=7)

branching-sequences-replace

Write. Early access: needs sequence_conditions on for the workspace. PUT https://api.ken.so/v1/campaigns/{campaignId}/branching-sequence

Path: campaignId

Body (json): expectedModifiedAt date-time, segments array

Save a draft campaign's sequence with conditions (the whole tree; no condition removes it). Needs the sequence_conditions flag and Campaigns edit. Launch publishes it and refuses a tree that cannot send.

PUT /api/v1/campaigns/{campaignId}/branching-sequence. Sends Ken-Version 1.1; client_id is
sent as X-Ken-Workspace-Id. Only a Draft campaign takes a tree with conditions (else 400
campaign_not_draft). With provider tracks on, a tree with conditions is refused while a provider
track has its own copy of a segment's sequence (400 provider_track_own_sequence): set the track
back to shared with segments(operation="set-provider-track", ...) first. The save compiles a draft campaign workflow and never publishes it. A tree
with no condition removes the sequence with conditions in any status, and the campaign keeps
its normal sequence (launch sends the normal sequence then, not a tree).

segments: one entry per segment, {segment_id, steps}; segment_id null is the default for
leads of any other segment. Each step is a node with a unique id (a-z, 0-9, _; 1-40 chars):
- {id, type: "email", wait_days (0-30), subject, body}
- {id, type: "linkedin_connect", wait_days, text (note, up to 300 chars, optional)}
- {id, type: "linkedin_message", wait_days, text}
- {id, type: "condition", condition: {kind, ...}, timing: {mode, days}, yes: [...], no: [...]}
  Behaviour kinds take timing ({mode: "within", days: 1-30}, or {mode: "wait_until"} with
  an empty no path) and need a step earlier on their path: email_opened, link_clicked,
  replied, meeting_booked, linkedin_invite_accepted, linkedin_message_engaged, unsubscribed.
  email_opened is refused on every campaign (open_tracking_off): opens are not tracked.
  Lead data kinds take no timing: has_email, has_linkedin_url, has_phone,
  lead_score ({operator: gte|lte|eq, value: number}),
  custom_variable ({variable, operator: equals|contains, value: text}).
- {id, type: "move_to_campaign", campaign_id}: another live campaign of the workspace.
A condition or a move ends its list. At most 100 nodes and 6 nested conditions.
expected_modified_at: the modifiedAt you read; a newer save answers 409 stale_write.
Every invalid field comes back in one 400 validation_failed (details[].field) and nothing
is written. Returns the GET shape.

replace

Write. PUT https://api.ken.so/v1/campaigns/{campaignId}/email-sequence

Path: campaignId

Body (json): expectedModifiedAt date-time, instruction string, isActive boolean, name string, steps array

Replace the campaign email sequence. Creates the sequence when none exists. Requires sequence edit access.

PUT /api/v1/campaigns/{campaignId}/email-sequence. Public. Sends Ken-Version 1.1.

Each step accepts id, step_order, variant (a, b, c, or d), name, subject, body,
body_format (plain, markdown or html), wait_days, is_active, open_tracking_enabled,
handwritten_enabled, handwritten_background, handwritten_intro, and
studio_template_version_id. open_tracking_enabled is stored for compatibility and does not
affect sending: campaign emails never carry an open-tracking pixel.
Omitted variant defaults to a. Omitted body_format defaults to plain.

The call replaces the whole sequence, so steps is required every time: to change
only name or is_active, send every step from your last read with it (a step left
out is deleted). An omitted name keeps the current one; an omitted is_active saves
the sequence as active.

Pass the modifiedAt from your last read as expected_modified_at so the write is
refused (409 stale_write) if someone changed the sequence since. It is sent as
expectedModifiedAt (ISO-8601) only when given; sending it when no sequence exists
yet is also 409 stale_write. An empty steps list deletes every step, so it is
refused before any call unless allow_empty_steps=true.

studio_template_version_id pins a published Studio email version (a version of a
format email template) to the step: each lead then gets that template rendered for
them, and the step's body and subject become the version's fallback, sent when a
lead has no render yet. The step is saved as html with the template's subject; body,
subject and body_format sent with a pin are ignored. Needs the workspace's studio and
studio_email features (else 400 studio_email_disabled) and html_steps (else
html_steps_disabled). The version must be published, of an email template of this
workspace, with a fallback for every required slot or a fallback.liquid (else 400
studio_pin_not_allowed). Null or omitted unpins: the step then sends the body and
subject the save carries, and the save response gives it the warning
studio_pin_removed. To keep a pin, send studioTemplateVersionId back on every save.
Reads return studioTemplateVersionId and studioPin
{versionId, templateId, state ok|stale}; stale means the version is no longer
published or its template was deleted, and the step sends its stored fallback.

body_format html needs the workspace's html_steps feature (else html_steps_disabled).
The body is sanitized on save (scripts, event handlers, forms, non-https images and
images on Kenso hosts are removed) and must stay under 100 KB (else html_too_large).
A body the send's Kenso brand check would still refuse (a Kenso tracking link, or an
image that loads from a Kenso host however it is spelled) is refused
(html_brand_domain); host the image on the workspace's own domain. Each saved html
step may carry warnings: html_on_mailbox_inbox, html_size_near_cap,
html_external_image:<host> (an https image outside the workspace's tracking hosts,
once per host), html_removed:<what>.

Handwritten letter (per variant): handwritten_enabled sends the body above the
{sender_signature} line or the unsubscribe link as an image of a handwritten letter,
under a short normal-text intro line (handwritten_intro: one line, at most 200
characters, no HTML, links or {spin:...}; null is "Hey {firstName|there},
{sender_first_name} wrote you a personal letter:"). handwritten_background is the
paper: walnut, linen, kraft, marble, deckle, or notepad (null is walnut). The letter
part is text only: no links, URLs, or link tokens such as {{tracking_link:ID}} or
{{booking_url}}. Put links after the {sender_signature} line or the unsubscribe link
(a typed sign-off is part of the letter), otherwise the save fails with 400 naming
the step and variant. The workspace flag handwritten_letters must be on, or the step
sends as a normal email. Replace semantics: a step sent without these fields turns
the letter off, so carry all three from the read like open_tracking_enabled.

Content policy: data.contentWarnings lists findings on active steps (stepOrder,
variant, code, severity warning|hard_warning|block, path, message, policyVersion).
Omitted when there are none. Report-only by default, so the save still succeeds.
link_count_exceeded means a cold step has more than 2 distinct links.
link_host_mismatch means link text reads as a web address, or a bare URL is in the
body. Tracking rewrites every href to the tracking domain, so the visible host
never matches. Use descriptive link text instead. When the platform turns on
enforcement, a block finding fails the save with 400 validation_failed and
nothing is written. error.details then has one entry per block: field
steps[i].body or steps[i].subject (i = index in the request steps) and code =
the finding code.

A campaign whose inbox pool has a sender that cannot thread a follow-up needs a subject
on every step. A step left with an empty subject fails the save with 400
validation_failed: error.details has one entry per such step, on field steps[i].subject.
A content-policy block can also sit on steps[i].subject; this refusal is the one on a
step whose subject you sent empty. Nothing is written.

instruction: the person's request behind this save, in their words ("make step 2
shorter"), kept as agent-reported in the steps' edit history (2,000 characters).
Omit it when no person asked; never invent one.

segment-email-sequences-replace

Write. PUT https://api.ken.so/v1/segments/{segmentId}/email-sequence

Path: segmentId

Body (json): expectedModifiedAt date-time, instruction string, isActive boolean, name string, steps array

Replace the segment email sequence. Creates the sequence when none exists. Requires sequence edit access.

PUT /api/v1/segments/{segmentId}/email-sequence. Public. Sends Ken-Version 1.1.
Step fields, data.contentWarnings, and content-policy failures match the campaign
email sequence (email_sequences(operation="replace")). That includes the handwritten
letter fields: a step sent without handwritten_enabled, handwritten_background and
handwritten_intro turns the letter off, so carry them from the read like
open_tracking_enabled. The letter part takes no links. It replaces the whole
sequence the same way: send every step even to change only name or is_active.

Pass the modifiedAt from your last read as expected_modified_at so the write is
refused (409 stale_write) if someone changed the sequence since. It is sent as
expectedModifiedAt (ISO-8601) only when given; sending it when no sequence exists
yet is also 409 stale_write. An empty steps list deletes every step, so it is
refused before any call unless allow_empty_steps=true.

instruction: the person's request behind this save, in their words ("make step 2
shorter"), kept as agent-reported in the steps' edit history (2,000 characters).
Omit it when no person asked; never invent one.

restore-version

Write. POST https://api.ken.so/v1/segments/{segmentId}/email-sequence/versions/{versionId}/restore

Path: segmentId, versionId

Restore a segment email sequence to a saved version. Requires sequence edit access.

POST /api/v1/segments/{segmentId}/email-sequence/versions/{versionId}/restore.
Public. Sends Ken-Version 1.1. A segment outside the workspace is not_found.

save-version

Write. POST https://api.ken.so/v1/segments/{segmentId}/email-sequence/versions

Path: segmentId

Body (json): isActive boolean, name string, sourceVersionId integer, steps array

Save a segment email sequence version. Omit steps to snapshot the live sequence. Requires sequence edit access.

POST /api/v1/segments/{segmentId}/email-sequence/versions. Public. Sends Ken-Version 1.1.
With source_version_id, omitted or empty steps keep that version's steps.
A non-empty list overlays them. There is no campaign-level email sequence version save.
Step fields match email_sequences(operation="replace"), including handwritten_enabled,
handwritten_background and handwritten_intro: a step sent without them is saved with the
handwritten letter off, so carry them like open_tracking_enabled. The letter part takes no
links. A restore brings back the version's handwritten settings; a version saved before
handwritten letters existed restores a normal email.

test-send

Write. POST https://api.ken.so/v1/campaigns/{campaignId}/email-sequence/test-send

Path: campaignId

Body (json): contactId integer, language string, senderEmailId integer, targetEmails string

Send a campaign email sequence to test recipients. Requires sequence edit access. A send that never attempts a message returns an error.

POST /api/v1/campaigns/{campaignId}/email-sequence/test-send. Public. Sends Ken-Version 1.1.
A send that attempted messages returns the tally, including partial failures.
notes lists each handwritten letter step that went out as normal text, with the
reason (flag_off, letter_too_long, unsupported_characters, letter_has_link, ...).
target_emails takes at most 5 valid addresses (comma or semicolon separated); an address
blocklisted by itself or with a hard bounce refuses the whole send (validation_error).
A blocklisted domain alone does not. When the campaign has inboxes assigned,
sender_email_id must be one of them. Each recipient x step counts against the
workspace's daily test-send quota (500 emails); rate_limited (429) when it is used up.
Each step goes out as dispatch sends it to the contact, in the contact's language, or as
a contact in language (fr-FR, de) gets it. notes names a step sent as an approved
translation, and a step the campaign would hold for the contact (no approved translation;
the test sends the source text).
402 free_plan_sending_needs_plan: a Free workspace created after the Free no-send rule
started sends nothing, test emails included. error.refusal has code
FREE_PLAN_SENDING_NEEDS_PLAN and remedy Upgrade: the user picks a paid plan, then test again.

segment-email-sequences-test-send

Write. POST https://api.ken.so/v1/segments/{segmentId}/email-sequence/test-send

Path: segmentId

Body (json): contactId integer, language string, providerTrack string, senderEmailId integer, targetEmails string

Send a segment email sequence to test recipients. Requires sequence edit access. A send that never attempts a message returns an error.

POST /api/v1/segments/{segmentId}/email-sequence/test-send. Public. Sends Ken-Version 1.1.
A send that attempted messages returns the tally, including partial failures.
notes lists each handwritten letter step that went out as normal text, with the
reason (flag_off, letter_too_long, unsupported_characters, letter_has_link, ...).
target_emails takes at most 5 valid addresses (comma or semicolon separated); an address
blocklisted by itself or with a hard bounce refuses the whole send (validation_error).
A blocklisted domain alone does not. When the campaign has inboxes assigned,
sender_email_id must be one of them. Each recipient x step counts against the
workspace's daily test-send quota (500 emails); rate_limited (429) when it is used up.
language and the translation notes work as on email_sequences(operation="test-send").
provider_track (google, microsoft or other): test or preview the email as that provider
track sends it; recipients on Google get plain text. A track's own sequenceSegmentId
implies its track. On a campaign that is not on provider tracks the test sends as
without it. Any other provider_track value is validation_failed (invalid_track).
402 free_plan_sending_needs_plan: a Free workspace created after the Free no-send rule
started sends nothing, test emails included. error.refusal has code
FREE_PLAN_SENDING_NEEDS_PLAN and remedy Upgrade: the user picks a paid plan, then test again.

save_bundle_version

Write.

Save a user-visible version checkpoint of a segment (sequence + prompts + segment).

Save a user-visible version checkpoint of a campaign segment.

To write the live sequence, call email_sequences(operation="replace", ...) for a
campaign or email_sequences(operation="segment-email-sequences-replace", ...) for a
segment (DEV-15: the legacy create and update were removed). Both take
expected_modified_at (409 stale_write when someone changed the sequence since your
read) and refuse an empty steps list unless allow_empty_steps=true.

Each campaign/segment can have one email sequence with up to 30 steps.
Steps support A/B/C/D versions and database, campaign-custom, and AI variables.

TEMPLATE VARIABLE SYNTAX
------------------------
- Campaign custom / lead / DB field: `{variable_key}` or `{firstName}`.
  Optional inline fallback: `{name|fallback}` (for example,
  `{firstName|there}`, `{renewal_date|TBD}`).
- AI variable: `{{AI Variable}}` (double braces around the personalization
  prompt name). Optional inline fallback: `{{AI Name|fallback}}` (for
  example, `{{First Line|Hope you're well.}}`). Never use double braces
  for campaign custom fields.
- Tracking link: `{{tracking_link:<id>}}` (double braces; id from
  tracking_links(operation='tracking-links-create')). Wrap in bodyContent as
  `<a href="{{tracking_link:<id>}}">display</a>`. Wrap is the contract;
  do not flatten to `{{tracking_link_N}}`.

Inline fallback rules (applies to both single- and double-brace forms):
- Fallback text is static plain text only. It cannot contain `|`, `{`, or
  `}`. Nested variables inside fallback text are not supported.
- An empty fallback (`{name|}` / `{{Name|}}`) is a validation error.
- Precedence is ALWAYS: inline pipe fallback > AI-dialog
  `fallbackIfEmpty` (from prompts(operation="ai_variables_save")) > bare token (no default).
- A set fallback (inline or dialog) satisfies `isRequiredForSending` for
  that variable, so the lead ships with the fallback rather than being
  excluded.

BODYCONTENT HTML CONTRACT (save_bundle_version with steps)
---------------------------------------------------------------
Stored bodyContent is HTML that matches the Kenso Sequence editor serializer.
bodyFormat is almost always 1 (Plain) even when the
body is HTML tags - that is the platform convention, not a contradiction.

Paragraph and blank-line tags:
- Every paragraph is a block: `<p>...</p>`
- A deliberate blank line between blocks is the literal spacer
  `<p><br /></p>` (not bare `<p></p>`, not raw newlines alone, not
  `<br>` / `<br/>` without the wrapping `<p>`)
- A single line break *inside* one paragraph is `<br />` (for example
  sign-off and name on consecutive lines in one block)

Signature block (do not insert spacers between signature lines):
- One spacer after the last body paragraph (before the sign-off).
- Sign-off word (`Enjoy,` / `Best,` / similar) then sender name / title /
  LinkedIn line consecutive with NO `<p><br /></p>` between them.
- Preferred: one paragraph joined by `<br />`, or adjacent `<p>` tags
  with no spacer between them. Either is fine; a spacer between name and
  LinkedIn is wrong (renders a stray blank line inside the signature).
- One spacer again before a PS block if present.

CORRECT signature (single paragraph form):
    <p>...body...</p><p><br /></p><p>Best,<br />{sender_first_name}<br />LinkedIn: ...</p><p><br /></p><p>PS: ...</p>

CORRECT signature (adjacent paragraphs, no spacer between lines):
    <p>...body...</p><p><br /></p><p>Best,</p><p>{sender_first_name}</p><p>LinkedIn: ...</p><p><br /></p><p>PS: ...</p>

INCORRECT (spacer between signature lines - do not do this):
    <p>Best,</p><p><br /></p><p>{sender_first_name}</p><p><br /></p><p>LinkedIn: ...</p>

A campaign with Send as plain text on never carries a click-tracking link: type each address
as text without https:// (www.example.com/apply), alone on its line, and create no tracking
link. In a campaign that sends as HTML,
outbound URLs must use tracking links (not bare https:// in body text):
1. Create a tracking link first:
   tracking_links(operation="tracking-links-create", campaign_id=...,
                  name=..., domain_name="https://example.com/path",
                  text_value="optional anchor text")
   -> response id is the link id
2. Embed the token in bodyContent as an href (wrap is the contract):
   `<a href="{{tracking_link:<id>}}">display text</a>`
   (example: `<a href="{{tracking_link:116}}">Book a call</a>`).
3. Do NOT put a raw `https://...` URL in bodyContent for tracked CTAs -
   bare URLs lose click attribution. Do not flatten to
   `{{tracking_link_N}}`. Display text is the anchor body
   (`text_value` on the redirect link). Bare tokens are wrapped on
   save/send; already-wrapped hrefs keep author text.

CONTENT POLICY FINDINGS (sequence saves)
----------------------------------------
- The response can carry top-level `contentWarnings`: one entry per
  finding on an active step, with stepOrder, variant (a-d), code,
  severity (warning, hard_warning, block), path, message, and
  policyVersion. Omitted when there are none. Report-only by default:
  the save still succeeds.
- link_count_exceeded: a cold step has more than 2 distinct links.
- link_host_mismatch: link text that reads as a web address, or a bare
  URL in the body. Tracking rewrites every href to the tracking domain,
  so the visible host never matches. Use descriptive link text
  ("Book a call") instead.
- When the platform turns on enforcement, a block finding fails the save
  with HTTP 400 and subcode `content_policy_blocked`, still carrying
  `contentWarnings`. Nothing is written.
- Links in active steps also go through the URL reputation check. Once
  that is enforced, a link to a host a malware-blocking DNS resolver
  (Cloudflare or Quad9) blocks, or to a domain registered less than 30
  days ago, fails the save with HTTP 400 and subcode
  `link_reputation_blocked`. Nothing is written. Until then it is only
  logged. The body's `blockedLinks` names each refused link with its
  stepId, stepOrder, variant, path (subject or body), url and rule.
  email_sequences(operation="save-version") and
  email_sequences(operation="restore-version") refuse such a link the
  same way; on a restore, stepId is the live step the version would
  overwrite.
- A campaign whose inbox pool has a sender that cannot thread a follow-up
  needs a subject on every step. A save that leaves a step's subject
  empty fails with HTTP 400 `validation_failed`, and the detail's code
  starts with `subject_required`. Nothing is written.

SAVE SEMANTICS
--------------
- email_sequences(operation="replace") /
  email_sequences(operation="segment-email-sequences-replace"): mutate the
  live working sequence. They do NOT create a version row.
- email_sequences(operation="save-version"): creates one immutable
  email-sequence-version row only. That row alone is NOT visible in the
  dashboard version-history popover, which lists CAMPAIGN SEGMENT
  versions (not sequence versions). Prefer save_bundle_version for any
  user-visible checkpoint.
- save_bundle_version: the correct operation for a user-visible checkpoint.
  Writes three versions in order - sequence (gating), prompt-bundle
  (best-effort, variables branch only), segment (anchor). The dashboard
  popover lists segment versions and reverts cascade to sequence + prompts.
  The sequence leg is email_sequences(operation="save-version") and the
  segment leg is segments(operation="save-version") with no fields, which
  snapshots the live segment and changes none of its values. Segment-
  scoped only - REQUIRES campaign_segment_id. See
  docs/sequence-versioning-workflow.md.
- email_sequences(operation="restore-version"): restores a historical
  sequence snapshot to live AND creates a restore version row. For
  UI-driven multi-resource restore, use
  segments(operation="restore-version"), which cascades.
- email_sequences(operation="list-versions") /
  email_sequences(operation="get-version"): read-only history. These are
  sequence-table rows; the popover still anchors on segment versions.

Operations:
-----------
save_bundle_version:
    Create a user-visible version checkpoint (sequence + prompts + segment).
    Requires campaign_id and campaign_segment_id; a segment of another
    campaign fails the sequence leg before anything is written. client_id
    names the workspace (sent as X-Ken-Workspace-Id); omit it on a
    connection that already has one. Optional name / is_active / steps are
    forwarded to the sequence version save (omit them to snapshot the
    current live sequence). All three legs omit sourceVersionId, so each
    snapshots the live resource.
    The sequence and segment legs send Ken-Version 1.1 to
    POST /api/v1/segments/{segmentId}/email-sequence/versions and
    POST /api/v1/segments/{segmentId}/versions. The segment leg sends no
    fields, so it changes no segment value and runs no A/B percentage check.
    Prompt-version saves have no canonical route: the prompts leg stays on
    POST /api/v1/campaigns/{campaignId}/segments/{segmentId}/prompt-versions.
    Prompts leg uses the variables branch so non-personalization prompts are
    back-filled from live into a complete bundle snapshot. If that yields
    zero personalization variables, the tool POSTs variables:[] ONLY when a
    scan CONCLUSIVELY proves the sequence has no {{...}} AI tokens:
    supplied steps that are a usable list, or (when steps omitted) a
    successful live-sequence GET whose steps value is an actual list.
    Every other case is fail-closed: prompts leg failed, no POST (fetch
    failed, unexpected envelope, steps absent/null/not a list, or
    {{...}} tokens found). A failed prompts leg does NOT block the
    checkpoint - sequence + segment still run and still anchor; cascade-
    revert retains the previous prompt sibling, so failing closed is the
    safe default.
    Example: operation="save_bundle_version", campaign_id=123,
             campaign_segment_id=45
    Response shape (BundleSaveResult):
    {
      "success": true,
      "message": "...",
      "error": null,
      "data": {
        "sequence": {"status": "ok", "versionId": 10, "versionNumber": 3,
                     "error": null, "versionWarning": null},
        "prompts":  {"status": "ok", "versionId": 8, "error": null,
                     "versionWarning": null},
        "segment":  {"status": "ok", "versionId": 12, "error": null,
                     "versionWarning": null}
      }
    }
    If sequence fails, prompts and segment are status="skipped". If segment
    fails (including success:true with version:null / no version id) after
    sequence succeeded, overall success=false (checkpoint not reachable
    from history). A prompts failure is non-blocking for overall success
    when segment is ok, but the checkpoint's prompt sibling is then a
    STALE OLDER version - later revert to this anchor restores prompts
    from an earlier point in time.

Parameters:
-----------
client : KenAPIClient
    API client instance
operation : str
    The operation to perform
campaign_id : int
    Campaign ID
campaign_segment_id : int
    Segment ID (required: email-sequence versioning is segment-scoped only).
name : str, optional
    Sequence name forwarded to the sequence version.
is_active : bool, optional
    Sequence active status forwarded to the sequence version.
client_id : int, optional
    Workspace id, sent as X-Ken-Workspace-Id. Omit it on a connection that
    already has one.
steps : list, optional
    List of step dicts forwarded to the sequence version (omit them to
    snapshot the current live sequence). The tool sends them in the
    canonical save's shape: subjectLine, bodyContent and versionType go out
    as subject, body and variant (a-d), and bodyFormat as plain, markdown or
    html. The canonical names are accepted too.
    Each step: stepOrder, versionType (1=A,2=B,3=C,4=D),
    subjectLine, bodyContent, bodyFormat (1=Plain,2=Markdown,3=Html), waitDays,
    isActive (optional bool, defaults true; applies to A/B/C/D versions),
    name (optional string - custom label for A/B test versions),
    openTrackingEnabled (optional bool), and the handwritten letter fields
    handwrittenEnabled (optional bool), handwrittenBackground (optional
    paper: walnut, linen, kraft, marble, deckle or notepad; null is walnut)
    and handwrittenIntro (optional one-line intro, at most 200
    characters, no HTML, links or {spin:...}). A handwritten step sends the
    body above the {sender_signature} line or the unsubscribe link as an
    image of a handwritten letter; that letter part takes no links, URLs or
    link tokens (put them after the {sender_signature} line or the
    unsubscribe link; a typed sign-off is part of the letter; otherwise the
    save fails with 400). The workspace flag handwritten_letters must be on,
    or the step sends as a normal email. Carry openTrackingEnabled and the
    three handwritten fields from the read: omitting them turns open
    tracking and the letter off.
    For each stepOrder, at least one A/B/C/D version must remain active.

Returns:
--------
dict
    API response with email sequence data