Skip to content

feat(posts): add newsletter + email_segment params to posts_edit#21

Open
kenbennett-penwood wants to merge 1 commit into
MFYDev:mainfrom
kenbennett-penwood:feat/posts-newsletter-email-segment-params
Open

feat(posts): add newsletter + email_segment params to posts_edit#21
kenbennett-penwood wants to merge 1 commit into
MFYDev:mainfrom
kenbennett-penwood:feat/posts-newsletter-email-segment-params

Conversation

@kenbennett-penwood

Copy link
Copy Markdown

Summary

Adds the newsletter and email_segment parameters to posts_add and posts_edit so that publishing a post through this MCP can trigger the subscriber email send, matching Ghost's native Admin API behavior.

These two parameters already exist on Ghost's Admin API as query parameters on the post create/update endpoints (https://docs.ghost.org/admin-api/posts/sending-a-post). Without them, calling posts_edit with status: "published" transitions the post state but does not send the post as email, because Ghost only sends when a newsletter is specified on the request: "Posts are sent by email if and only if an active newsletter is provided."

Same gap was raised for the n8n Ghost node (https://community.n8n.io/t/add-newsletter-email-segment-to-ghost-node/106617) and on the Ghost forum (https://forum.ghost.org/t/email-segment-syntax-for-creating-a-post/50275).

Changes

  • src/tools/posts.ts: new emailSendParams schema fragment (newsletter, email_segment), spread into both posts_add and posts_edit input schemas.
  • src/tools/posts.ts: both handlers now forward these two values via the @tryghost/admin-api SDK's query-parameters argument (the same channel the existing source: "html" option uses), rather than in the post body. This matters because Ghost expects newsletter and email_segment as query parameters, not post fields, so they are destructured out of the post data before the create/update call.

Why a separate fragment instead of postMutableFields

postMutableFields is spread into the request body. email_only (added earlier) belongs there because it is a real post property. newsletter and email_segment are send-control query parameters, not post fields, so they are kept in their own fragment and routed to the SDK's query-param argument. Putting them in the body would get them ignored or rejected by Ghost.

Testing

Tested against a live Ghost Pro site via a local linked build, draft-only so no subscriber emails fired: created a draft post, then called posts_edit with newsletter, email_segment, and status: "draft". Captured the outgoing request and confirmed the URL was:

PUT /ghost/api/admin/posts/{id}/?newsletter=default-newsletter&email_segment=all

Ghost returned 200, the post stayed in draft, no email object was attached, and the draft was deleted afterward. npm run build passes clean.

Side observation (not this PR's bug to fix): the SDK's JWT auth chain (@tryghost/admin-api -> jsonwebtoken -> jwa -> buffer-equal-constant-time) throws on Node 24+ because it reads the removed SlowBuffer.prototype. I ran the smoke test under Node 20 LTS. The code in this PR is Node-version-agnostic; flagging in case it helps your own QA path.

Context

Filed in response to your invitation on #20 (2026-06-05): "let's just make a large PR should be good enough." I kept this one narrow to the two missing email params. Happy to adjust naming, types, or the body-vs-query split if you have a preferred convention.

…osts_edit

Forward Ghost's newsletter and email_segment query parameters through the
@tryghost/admin-api SDK's query-params argument so that publishing via this
MCP can trigger the subscriber email send. Kept in a dedicated emailSendParams
schema fragment (not postMutableFields) because they are send-control query
parameters, not post body fields.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kenbennett-penwood kenbennett-penwood marked this pull request as ready for review June 9, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant