Add MCP blueprint management tools#6
Draft
hookdump wants to merge 14 commits into
Draft
Conversation
The Data API returns error bodies as plain text, but the client only read a JSON `message` field, so every validation/authorization failure showed as a generic "Churnkey API error <status>". Relay the server message verbatim and add clearer 403/404 fallbacks. Contract/doc alignment with the dashboard: - list_blueprints: document the new hasUnpublishedChanges flag and that status is a coarse subset of the dashboard badges (not a 1:1 mirror) - get_blueprint: document the step/offer/survey-choice guid response shape - list_segments: document audience filter rules, priority, enabled, and that A/B variant segments appear as separate entries - update_blueprint_draft: brandImage validation now mirrors the server (path ends in png/jpg/jpeg/gif/webp, or images.churnkey.co); reject empty-string step/choice guids instead of silently treating as absent - dsr_delete: document the deleted/reasonForRejection outcome - README: scope the live/test mode note (sessions + DSR only; config is shared and recoveries are not mode-partitioned); drop the phantom invoiceMonth breakdown from the changelog Tests: add client error-handling cases and brandImage validation cases; add scripts/smoke.mjs for end-to-end checks against a local churnkey-api. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
New tools so an agent can edit a flow without resending the whole steps array: - update_blueprint_offer: change an offer's type + functional config (discount/pause/trial/redirect/plan-change), addressable on an offer step, a survey choice, or a structured follow-up option via guids. - edit_survey_structure: add/remove/reorder survey choices and configure a choice's follow-up (freeform / structured / freeform-structured / none). - add_blueprint_step / remove_blueprint_step: add a step at a canonical place (server builds the base step) or remove one by stepGuid. - update_blueprint_step gained survey behavior (randomize, followupRequired, minLength) and freeform/confirm config. - set_segment_enabled and update_segment_filter for segment config. Draft blueprint edits are draft-only and not confirm-gated (publish is the live gate; destructive ones carry destructiveHint). Segment edits act on live config so they require a confirm literal. Adds routing/validation tests and an observed reversible write round-trip to scripts/smoke.mjs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
9a67918 to
03da3d7
Compare
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 a full read + create + granular-write tool surface to the
@churnkey/mcpserver so agents can inspect, create, edit, publish, and manage cancel-flow blueprints and segments through a Data API key. Every edit is granular (the agent never resends the whole nestedstepsarray), draft edits are kept separate from live-impacting actions, and the API audit-logs every configuration change.This branch is rebased onto current
origin/mainand includes support for the new cancel-flowREBATEoffer type.update_blueprint_offeracceptsofferType: "REBATE"plus rebate config fields:amountType,customAmount,percentAmount,mbgWindowDays, andinvoiceScope.Backed by companion API PR churnkey/churnkey-api#836.
Tools
Read
list_blueprints- current flow inventory: the default org flow plus every non-deleted segment flow, each withstatus,published,hasUnpublishedChanges, editable/published blueprint IDs, and compact draft/published metadata.get_blueprint- the full blueprint including thestepsarray and stableguidvalues for targeted edits.list_segments- segment metadata in priority order, includingpriority,enabled, and audiencefilterrules.Create
create_blueprint(confirm: "create_blueprint") - creates the default org-level draft only when the org does not already have one. Supportstemplate: "empty" | "BASIC" | "B2B" | "MERGEFIELDS"plus optional name/branding/languages.create_segment_flow(confirm: "create_segment_flow") - creates a cancel-flow segment and a linked editable blueprint draft. This is the preferred repeatable path for new flows and smoke tests.archive_segment(confirm: "archive_segment") - soft-deletes a segment, useful for cleaning up disposable test flows.Blueprint draft edits - granular, draft-only
update_blueprint_draft- top-level fields (name,brandImage,primaryColor,translatedLanguages).update_blueprint_step- one step's copy + behavioral config bystepGuidorstepIndex.update_blueprint_offer- an offer's type + functional config, addressable on an offer step, survey choice, or structured follow-up option. Supports discount, pause, trial extension, redirect, plan change, contact, and rebate.edit_survey_structure- add/remove/reorder survey choices and configure a choice's follow-up.add_blueprint_step/remove_blueprint_step- add a step at a canonical place or remove one bystepGuid.Publish & live segment config - confirm-gated
publish_blueprint(confirm: "publish")reorder_segments(confirm: "reorder_segments")set_segment_enabled(confirm: "set_segment_enabled")update_segment_filter(confirm: "update_segment_filter")Design principles
stepsarray with translations.publish_blueprintis the live gate. Segment creation/priority/enabled/filter/archive mutate live segment config and require confirmation.REBATE, then archives the segment instead of touching the org's primary draft.API dependency
Depends on companion API PR: https://github.com/churnkey/churnkey-api/pull/836
Linear
Related PRs
Validation
pnpm --filter @churnkey/mcp exec vitest run tests/tools/blueprints.test.ts tests/tools/segments.test.ts- 23 tests passed.pnpm --filter @churnkey/mcp typecheck- passed.pnpm --filter @churnkey/mcp build- passed.git diff --check- clean.Smoke note
The smoke harness is updated for the create/edit/rebate/archive lifecycle. I did not rerun live
--mutatein this pass because it requires a running local API plus credentials and writes real configuration, even though the flow is disposable and archived at the end.