# Connect a site on its own code to Sightkick

Your user wants Sightkick to publish pages on a site built in code (Next.js, Astro, a Lovable or Bolt project, anything). Sightkick sends each page, signed, to a webhook on the site, and the site saves it and serves it. About 5 minutes if you work in the site's code.

## 1. Connect to Sightkick

- Sightkick's MCP server is https://app.sightkick.so/mcp (streamable HTTP, OAuth). If it isn't connected yet, connect it by https://sightkick.so/connect/agent.md. Its sign-in picks your user's workspace.
- Call get_settings with view: sites. If a webhook for this site is there with status connected, tell your user it's connected already and stop.
- A site has one publishing destination, so a second connection is refused. If another one is there, ask your user whether to move. Only on their yes, remove it (update_connections with action: remove), then go on.

## 2. Build the webhook and the blog pages

Look at how the site is built and follow its conventions. Render the blog pages on the server, or pre-render them at build time.

1. The webhook: a POST endpoint, for example /api/sightkick.
- Check the signature before anything else. The x-sightkick-signature header is "sha256=" followed by the hex HMAC-SHA256 of the raw request body, keyed with the SIGHTKICK_SIGNING_SECRET environment variable (64 hex characters). Compare in constant time and answer 401 when it doesn't match.
- Refuse a body whose timestamp is more than 10 minutes old (a replayed delivery).
- The body's event_type says what to do: "publish_article", "update_article", "unpublish_article" or "test". Answer 200 to any other event_type you don't know.
- publish_article and update_article carry an article. Save the post by article.id, never by slug: a changed slug is an update, and the old URL redirects to the new one. Keep title, slug, page_type, path, content_html, meta_title, meta_description, excerpt, language, tags, author, author_profile, image_url, images, internal_links, published_at, updated_at and json_ld.
- article.status is "published": every page Sightkick sends goes live on the site.
- When article.minor_edit is true, keep the post's visible "Updated" date as it was.
- Skip a delivery whose x-sightkick-idempotency-key you've already handled, and still answer 200. The test event has no idempotency key and no article.
- unpublish_article: take the post (or the page at article.path) down. When article.redirect_to is set, redirect the old URL to its url, or to /blog/<its slug> when url is empty.
- test: answer 200 without saving anything.
- Answer 200 with {"published_url": "<the post's live URL>"}. article.expected_url is only Sightkick's guess at that URL.

2. The blog pages: /blog lists the published posts, /blog/<slug> shows one.
- Some articles are pages, not posts: article.page_type is "comparison", "alternatives", "integration" or "use_case", and article.path is where the page lives (for example /vs/peec-ai or /alternatives/peec-ai). Serve each at its path, in its own folder at the site's root, never under /blog, and leave it out of the blog list. A post has page_type null.
- Render them on the server or pre-render them at build time. AI crawlers don't run JavaScript, so a page drawn in the browser is invisible to them.
- Use content_html as it is, and never mix in content_markdown.
- Put meta_title in <title>, meta_description in the meta description, a canonical link to the page's own URL (never expected_url), image_url as og:image, and json_ld in a <script type="application/ld+json"> tag.
- List every published post in sitemap.xml with updated_at as its <lastmod>.

3. IndexNow, so search engines hear about new posts right away: serve /<key>.txt at the site's root, where <key> is the SIGHTKICK_INDEXNOW_KEY environment variable, with the key as its only content.

Read SIGHTKICK_SIGNING_SECRET and SIGHTKICK_INDEXNOW_KEY from the environment: step 3 gives you both. Deploy, so the webhook answers at a public https address.

## 3. Connect

Call update_connections with action: connect_webhook, webhookUrl (the webhook's full public https address) and blogUrl (where the posts are listed, like https://<their-site>/blog).

It returns signingSecret and indexNowKey, this once. Set them in the host's environment as SIGHTKICK_SIGNING_SECRET and SIGHTKICK_INDEXNOW_KEY, never in the code or a commit, and deploy again. If you can't reach the host's settings, give your user the two values and tell them where to add them.

## 4. Test

Call update_connections with action: test and the connectionId. Sightkick sends a signed test event (event_type test, no article), and your webhook answers 200 without saving anything. A failure comes with what it likely means: 401 or 403 is the secret, 404 the route, 500 and up the site's logs.

## Tell your user

Sightkick publishes each page to their site on its day: the webhook saves it and the site shows it. They see the connection in Sightkick under Settings → Publishing, and change or remove it there.

If a step fails, its error says what to fix. Your user can also connect by hand: Settings → Publishing in Sightkick, "Set it up yourself".
