feat(posts): add newsletter + email_segment params to posts_edit#21
Open
kenbennett-penwood wants to merge 1 commit into
Open
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the
newsletterandemail_segmentparameters toposts_addandposts_editso 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_editwithstatus: "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: newemailSendParamsschema fragment (newsletter,email_segment), spread into bothposts_addandposts_editinput schemas.src/tools/posts.ts: both handlers now forward these two values via the@tryghost/admin-apiSDK's query-parameters argument (the same channel the existingsource: "html"option uses), rather than in the post body. This matters because Ghost expectsnewsletterandemail_segmentas 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
postMutableFieldspostMutableFieldsis spread into the request body.email_only(added earlier) belongs there because it is a real post property.newsletterandemail_segmentare 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_editwithnewsletter,email_segment, andstatus: "draft". Captured the outgoing request and confirmed the URL was:PUT /ghost/api/admin/posts/{id}/?newsletter=default-newsletter&email_segment=allGhost returned 200, the post stayed in draft, no email object was attached, and the draft was deleted afterward.
npm run buildpasses 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 removedSlowBuffer.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.