UNPKG

@awesomate/hosting-mcp

Version:

Awesomate MCP server — lets Claude manage your Awesomate WordPress hosting, plan, limits, n8n automations, and build Node/static apps + databases

185 lines (156 loc) • 12.5 kB
# Hold for a decision: a person's OK before an automation acts Use this when a workflow is about to do something a person should approve first: send a quote, give a refund or a discount, reply to a customer in words it wrote. The automation files a decision for a role on the business map; it goes to whoever answers for that role (or to the owners when the role is empty), waits in their Tasks in the hub and in an email, and the run carries on only when they answer. Nothing is ever approved on silence: after the deadline the run is resumed with `expired`. Check the map first: `awesomate_business_map` action `roles` gives each role's key (its slug). The decision has to name one. ## The shape ``` … → Hold for a decision (POST to the hub) → Wait (On Webhook Call) → IF approved → do the thing └ else → stop, or tell the customer "we'll be in touch" ``` 1. **Hold for a decision.** Use the Awesomate node's **Task: Hold for a Decision** (`holdForDecision`; see [awesomate-node.md](awesomate-node.md)): it reads the run's own resume address and id. Where their node does not have it yet (check its Operation list), use an HTTP Request node with the account's **Awesomate Hub** credential (check `hubNodeCredential` in `awesomate_n8n_context`: when it is missing, add it with `awesomate_n8n_hub_credential` (or the owner presses "Add it to my n8n" on the hub); when their n8n has no Awesomate node, use Generic Credential Type, Header Auth, **Awesomate Hub Key**, if the credential inventory has it): - `POST https://hub.awesomate.ai/api/hub-key/v2/<account>/decisions` - JSON body: ```json { "role": "quotes-and-follow-up", "title": "Refund $80 to a customer", "type": "yes_no", "context": "Their order arrived damaged.", "facts": { "amount": 80, "discount_pct": null, "new_customer": false }, "draft_field": "reply", "draft_node": "Write the reply", "workflow_name": "Refunds", "resume_url": "{{ $execution.resumeUrl }}", "execution_id": "{{ $execution.id }}" } ``` - `type` is `yes_no`, `approve_draft` (a message the person may edit: name the field and the node whose output holds it with `draft_field` and `draft_node`; the hub reads that one field live from the paused run and never stores it) or `pick_one` (with `options`, 2 to 5, each up to 60 characters). - `title` (up to 120) and `context` (up to 500) are plain text in your own words, never a customer's message. `facts` are numbers only; the card says they are as the automation reported them. - `expires_in_hours` is optional: 48 by default, 1 to 168. 2. **Wait.** A Wait node, Resume: On Webhook Call, HTTP Method POST, Authentication: Header Auth with the credential **Awesomate decision resume** (the hub places it on the instance the first time a decision is filed; the filing's answer names it). Limit the wait to the deadline plus an hour (49 hours for the default). 3. **IF** `{{ $json.body.decision }}` equals `approved`. The Wait's body is `{ decision: 'approved' | 'rejected' | 'expired', decision_id, pick?, edited_text?, value? }`. `pick` is the label of the option the person chose, exactly as you sent it in `options` (for `pick_one`, read it as `{{ $json.body.pick }}`; a pick still comes back as `approved`, so a Pick One card has no "no" unless nobody answers in time). `edited_text` is the words the person approved (`approve_draft`) and `value` the number a figure card asked for: use those, not your draft. Anything else (`rejected`, `expired`, or the Wait timing out) means do nothing. ## Rules - One decision per run, ever: the hub refuses a second one for the same execution. - A run of a workflow Awesomate built (an agent's actions gateway, a library install) cannot be held this way; agents already hold their own actions. - The Hub Key files only. It can never approve, read the answer, or cancel: the answer comes back only through the Wait. Never build a workflow that approves its own decision. - The account needs decisions switched on; until then the hub answers 403 `not_on`. Say so plainly. - The answers 4xx carry a sentence: relay it, don't guess around it. ## An automation that holds a role: check limits first On the business map an agent or an automation built for the business can hold a role (`heldBy` on the role in `awesomate_business_map`; giving it one is `holder.set` with `helperId`, which needs the account's Agents in roles and Decisions features). Holding is only as good as the workflow's own check: when you build or give a role to a workflow, add a Check limits step before each action that spends money, gives a discount or reaches a customer. Until the Awesomate node has a Check Limits operation, use an HTTP Request node with the same Awesomate Hub credential: - `POST https://hub.awesomate.ai/api/hub-key/v2/<account>/authorise` - JSON body: ```json { "role": "quotes-and-follow-up", "execution_id": "{{ $execution.id }}", "facts": { "amount": 80, "discount_pct": 10, "new_customer": false }, "process": 2 } ``` - `execution_id` is required and is how the hub knows who is asking: it reads that run from the account's n8n and checks it is a run, happening now, of the workflow that holds the role. Never send the workflow id as a header for this; it is ignored. Check from the holding workflow's own run: a sub-workflow is a different run, which does not hold the role. - `facts` are in the business's own currency with no currency field: `amount` in dollars or `amount_cents`, `discount_pct`, `new_customer`. The amount is required when the role has an approval limit. - `process` is optional: the process's place in the role's list (1, 2, ...), when the work is one this automation does. `flagged_exception: true` marks work the owner asked to hear about. Read the answer like this, and never act on anything but `go: true`: - `{ "go": true }`: do it. With `"tell": true` as well, do it and tell the owner (the workflow sends the message; the hub tells nobody). - `{ "go": false, "next": "hold", "why": ... }`: file a Hold for a decision for the role and wait, as above. The hub routes the card (usually one role up from the held role). When `why` says level 2, a person picks: file it as `pick_one` with 2 to 5 options. When `why` says this automation does not hold the role, or asks for the amount, the workflow is built wrong (a sub-workflow checking, the wrong role key, no amount): fix it rather than filing a decision on every run. - `{ "go": false, "next": "stop" }`: at this level the holder may only find out and report. Do not act and do not file a decision; report what you found. - An error with status 503, 500 or 429, whatever its code (`n8n_unreachable`, `plan_unreadable`, `daily_cap`, `feature_unavailable` when the plan could not be read, or none): the hub could not check just now, so hold, or try again later. - Any other error (a 400, 403, 404, 409 or 422: `bad_facts`, `no_such_role`, `no_such_run`, `run_not_running`, `hub_built_run`, `feature_unavailable`, ...): the workflow is built wrong or the account is not set up. Do not act; relay the sentence and fix the build, rather than filing a decision on every run. A run can file only one Hold for a decision. A holder that works through several items in one run checks each, does the ones that go, and stops at the first that needs a hold: the rest wait for the next run. Facts are the automation's own word: the holding workflow's checks are audited and capped per day (a check from any other run is answered and not counted). A run of a workflow Awesomate built (an agent's gateway, a library install) cannot check limits this way. ## Recipe: publish a WordPress post after a person's yes For a scheduled article (a guide every Tuesday and Friday), the automation writes the post as a draft, asks the person who answers for marketing to approve it, and publishes only on their yes. The hub holds the rule: a post is published, scheduled, or a live post changed, only with the id of a decision this same run filed, naming that post, and a person answered yes. ``` Schedule → write the article → create the post (draft) → Hold for a decision (approve_draft, names the post) → Wait → IF approved → update the post (status publish, decisionId) ``` All three calls use an HTTP Request node with the account's **Awesomate Hub** credential and these two headers, which tie the decision to this run: `x-awesomate-workflow: {{ $workflow.id }}` and `x-awesomate-execution: {{ $execution.id }}`. If their Awesomate node has a **Website** resource (check its Operation list), use its Create Post and Update Post instead: they send both headers themselves. 1. **Create the draft.** `POST https://hub.awesomate.ai/api/hub-key/v2/<account>/website/sites/<domain>/posts` with `{ "type": "post", "title": "...", "content": "<p>...</p>", "status": "draft", "excerpt": "...", "categories": ["Guides"], "seo": { "title": "...", "description": "..." }, "jsonLd": { "@context": "https://schema.org", "@type": "Article", "headline": "..." }, "featuredImage": { "url": "https://..." } }`. Keep the answer's `postId`. The domain must be one of the business's own WordPress sites with Awesomate; categories must already exist; content is ordinary post HTML (scripts, frames, forms and event handlers are refused, so write none). A new post is always a draft (or `pending`): it is published in step 3. 2. **Hold for a decision**, `type: "approve_draft"`. For `role`, read `awesomate_business_map` action `roles` and use the key of the role that answers for marketing (marketing is a department, not a role key). Set `draft_field` to the NAME of the field that holds the article's HTML (such as `html`) and `draft_node` to the NAME of the node whose output has it, so the hub reads the real text from the paused run and the person reads and may edit it. Give a title such as "Publish Tuesday's guide: Why oak burns hot", and **always** `"publish": { "domain": "<domain>", "post_id": <postId> }`. The card then says which post the yes publishes, and the yes publishes that post on that site only. With `publish`, `context` has about 440 characters left (the card starts with which post the yes publishes): keep it to a line or two. Then the Wait. 3. **IF approved**, `PATCH .../website/sites/<domain>/posts/<postId>` with `{ "status": "publish", "decisionId": <the decision id> }` (`{{ $json.body.decision_id }}` from the Wait). When the person edited the words, the Wait's body carries `edited_text`: send `"content": "{{ $json.body.edited_text }}"` in the same call only when it is there (an IF on it), and the original stays otherwise. Their edit must still be ordinary post HTML, or the call answers 400 `content_not_allowed`. To publish at a set time instead, send `"status": "future"` and a `"date"` with its zone, worked out when this call runs (`{{ $now.plus({ minutes: 15 }) }}` at the least, or the next slot): the yes can come hours after the article was written, and a date less than 5 minutes ahead is refused. Scheduling needs the decision too. Rules the hub keeps (say them plainly when it refuses): - The decision must come from Hold for a decision in the SAME run, name this post, be a yes/no or approve-the-draft card, be answered yes by a person in the last 7 days, and not have published before. The hub also checks with n8n that the run is running when it publishes. - One run holds once, so one run publishes one post. To publish several articles, run a sub-workflow per article (Execute Workflow makes a separate run each), each holding for its own decision. - A refused decision writes nothing and answers 409 `decision_not_usable`, without saying which part failed: check the run headers, the post named in the hold, the yes, and that it was not used before. A decision sent without the two headers answers 400 `run_headers_missing`. - Website switched on, Support Plus and above, 20 writes a day for the business. Each article uses two (the draft and the publish), so plan at most 10 a day. - Keep these as regular workflow steps: never give an AI agent the Awesomate Hub credential as a tool for them. - Chat (Claude on claude.ai) still never publishes: a person publishes there in WordPress.