Skip to content

feat(mcp): publishedAt on content_publish, seo/bylines/publishedAt on content_update - #890

Merged
ascorbic merged 2 commits into
mainfrom
feat/mcp-publish-update-fields
May 1, 2026
Merged

ascorbic merged 2 commits into
mainfrom
feat/mcp-publish-update-fields

Conversation

@ascorbic

@ascorbic ascorbic commented May 1, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Closes #621 and #622.

The MCP `content_update` tool previously dropped `seo`, `bylines`, and `publishedAt` even though the underlying handler accepted them (added in #777). Callers had to fall back to raw SQL against `_emdash_seo` and `_emdash_content_bylines` to set these fields, breaking MCP-first workflows.

`content_publish` (and the equivalent REST route) now accept an optional ISO 8601 `publishedAt` to backdate a publish, useful when migrating content from another CMS or correcting a historical publish date. The override requires `content:publish_any`. Without it, the existing `COALESCE(published_at, now())` preserve-on-re-publish behavior is unchanged.

The MCP `content_update` `inputSchema` now reuses the REST `contentSeoInput` and `contentBylineInputSchema` rather than redefining inline. The first adversarial review pass caught that an inline `z.string()` shape on `seo.canonical` would have bypassed the REST schema's `httpUrl` refinement (which rejects `javascript:` and `data:` URIs), letting an LLM-driven MCP client write a stored XSS into the rendered `<link rel="canonical">`. Reusing the REST schemas closes that gap and keeps the layers in lockstep going forward.

Taxonomies (the third item in #621) are not in this PR. The handler doesn't yet wire taxonomies through `handleContentUpdate`; that's a separate piece of work and gets its own PR.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

The new MCP fields fill capability gaps where the handler already supported the behavior. Filed as bug fix per the same logic #777 used for similar gaps.

Notable changes

  • `repo.publish(type, id, publishedAt?)` \u2014 optional override. When provided, written directly. When omitted, the COALESCE preserve branch runs unchanged. Two SQL branches rather than one to keep the override semantically explicit.
  • `handleContentPublish` runtime/handler/REST/MCP all gain an optional `publishedAt`. REST publish now accepts an optional JSON body via `parseOptionalBody`; empty body keeps the previous behavior. `publishedAt` writes are gated on `content:publish_any` regardless of ownership at all four layers.
  • MCP `content_update` exposes `seo`, `bylines`, `publishedAt`. The status='published' and status='draft' branches forward the new fields through the underlying `handleContentUpdate` call. The `publishedAt` gate fires regardless of ownership (mirrors the REST PUT route at `[id].ts:103-110`).
  • `EmDashHandlers` interface in `astro/types.ts` extended for both `handleContentPublish` and `handleContentUpdate` to match the runtime signatures.
  • New `contentPublishBody` Zod schema in `api/schemas/content.ts`.
  • 16 new MCP integration tests covering positive, negative, ownership, permission, and atomicity paths.

Adversarial review

Two review cycles. The first pass caught a stored-XSS gap (inline SEO schema bypassing the REST canonical-URL refinement), three test-quality issues (passes-for-the-wrong-reason patterns), and the AI-trope em dashes in the changeset. Second pass confirmed the fixes hold and flagged one missing positive test for the C1 fix, which I added (`rejects SEO canonical URL with non-http scheme`). Two leftover LOW items deferred:

  • REST `contentPublishBody.publishedAt` is `.nullish()` (inherited from the shared `contentDateOverride`) but `null` is silently dropped by the route. Behavior-preserving; not in scope.
  • Per-tool `as Permission` casts on the new `hasPermission` calls match the pre-existing pattern at `mcp/server.ts:587`. Removing only the new ones would create inconsistency; touching the old one is a drive-by.

Checklist

  • I have read CONTRIBUTING.md
  • `pnpm typecheck` passes
  • `pnpm lint` passes (0 diagnostics)
  • `pnpm test` passes (282/282 MCP integration, 3097/3097 core)
  • `pnpm format` has been run
  • I have added/updated tests for my changes
  • User-visible strings in the admin UI are wrapped for translation \u2014 N/A (no admin UI changes)
  • I have added a changeset
  • New features link to an approved Discussion \u2014 N/A, this is a bug fix

AI-generated code disclosure

  • This PR includes AI-generated code \u2014 model/tool: Claude Opus 4.7

Driven by Claude with manual oversight at each adversarial review cycle. Each fix was verified against a failing test, and tests were re-checked across review passes for tautologies and assertions that pass for the wrong reason.

Test output

```
Test Files 17 passed (17)
Tests 282 passed (282)
```

(MCP integration suite. Full core suite: 3097/3097.)

… content_update

Addresses #621 and #622. The MCP content_update tool previously dropped
seo, bylines, and publishedAt even though the underlying handler accepted
them (added in #777). Callers had to fall back to raw SQL against
_emdash_seo and _emdash_content_bylines.

content_publish (and the equivalent REST route) now accept an optional
ISO 8601 publishedAt to backdate a publish, gated on content:publish_any.
Without an override, the existing COALESCE preserve-on-re-publish
behavior is unchanged.

The MCP content_update inputSchema now reuses the REST contentSeoInput
and contentBylineInputSchema rather than redefining inline. This avoids
the URL scheme bypass that an inline z.string() shape would create on
the seo.canonical field.
Copilot AI review requested due to automatic review settings May 1, 2026 15:06
@changeset-bot

changeset-bot Bot commented May 1, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: dc60faa

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
emdash Minor
@emdash-cms/cloudflare Minor
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/admin Minor
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
create-emdash Minor
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 1, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-perf-coordinator dc60faa May 01 2026, 03:17 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 1, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
docs dc60faa Commit Preview URL

Branch Preview URL
May 01 2026, 03:18 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 1, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-i18n dc60faa May 01 2026, 03:18 PM

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 823 lines across 9 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 1, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-demo-cache dc60faa May 01 2026, 03:19 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 1, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground dc60faa May 01 2026, 03:19 PM

@pkg-pr-new

pkg-pr-new Bot commented May 1, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@890

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@890

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@890

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@890

emdash

npm i https://pkg.pr.new/emdash@890

create-emdash

npm i https://pkg.pr.new/create-emdash@890

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@890

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@890

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@890

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@890

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@890

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@890

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@890

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@890

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@890

commit: dc60faa

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds missing field support to MCP tools and extends publish endpoints to allow controlled publishedAt overrides, aligning MCP and REST behavior for content lifecycle metadata.

Changes:

  • Add optional publishedAt override support to content_publish (MCP + REST) gated by content:publish_any.
  • Expose/persist seo, bylines, and publishedAt via MCP content_update, reusing REST Zod schemas for validation parity.
  • Add MCP integration coverage for publish/update field persistence, permissions, and atomicity.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/core/tests/integration/mcp/publish-update-fields.test.ts New integration tests covering MCP publish/update for publishedAt, SEO, bylines, permissions, and atomicity.
packages/core/src/mcp/server.ts Extends MCP content_update schema/forwarding for seo, bylines, publishedAt; extends content_publish to accept publishedAt with permission gating.
packages/core/src/emdash-runtime.ts Extends runtime handler signatures/options for handleContentPublish (and types for update payload).
packages/core/src/database/repositories/content.ts Adds optional publishedAt parameter to publish() with explicit SQL branch for override vs COALESCE preservation.
packages/core/src/astro/types.ts Updates EmDashHandlers signatures to include new update fields and publish options.
packages/core/src/astro/routes/api/content/[collection]/[id]/publish.ts REST publish endpoint now parses optional body and forwards publishedAt to runtime with permission gating.
packages/core/src/api/schemas/content.ts Adds contentPublishBody schema for REST publish endpoint input.
packages/core/src/api/handlers/content.ts Threads optional publishedAt through handleContentPublish → repository.
.changeset/mcp-publish-update-fields.md Changeset documenting new MCP/REST capabilities and permissions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +61 to +75
// Backdating overwrites historical record — gate behind publish_any
// regardless of ownership.
if (body?.publishedAt !== undefined && !hasPermission(user, "content:publish_any")) {
return apiError(
"FORBIDDEN",
"Setting publishedAt requires content:publish_any permission",
403,
);
}

const resolvedId = typeof existingItem?.id === "string" ? existingItem.id : id;

const result = await emdash.handleContentPublish(collection, resolvedId);
const result = await emdash.handleContentPublish(collection, resolvedId, {
publishedAt: body?.publishedAt ?? undefined,
});

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contentPublishBody allows publishedAt: null (via contentDateOverride.nullish()), but this route treats publishedAt !== undefined as a privileged backdate attempt and then passes body?.publishedAt ?? undefined to the handler (so null is silently dropped). This makes { publishedAt: null } require content:publish_any even though it behaves like omitting the field. Consider either (a) rejecting null at the schema layer for this route/tool, or (b) normalizing const publishedAt = body?.publishedAt ?? undefined first and using that for both the permission check and the handler call so null behaves identically to undefined.

Copilot uses AI. Check for mistakes.
Comment on lines +77 to +80
publishedAt: contentDateOverride.meta({
description:
"Optional ISO 8601 datetime to backdate the publish (e.g. when migrating content). Requires content:publish_any permission. Without this, existing published_at is preserved on re-publish.",
}),

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contentPublishBody.publishedAt currently reuses contentDateOverride which is .nullish(), so null is accepted. The publish endpoint/tool appears to only support an optional timestamp override (not clearing), and downstream code drops null anyway. Consider changing this field to .optional() (no null) or preprocessing null to undefined so the schema matches the actual supported behavior and avoids surprising permission failures for { publishedAt: null }.

Suggested change
publishedAt: contentDateOverride.meta({
description:
"Optional ISO 8601 datetime to backdate the publish (e.g. when migrating content). Requires content:publish_any permission. Without this, existing published_at is preserved on re-publish.",
}),
publishedAt: z.iso
.datetime({ offset: true, message: "must be an ISO 8601 datetime" })
.optional()
.meta({
description:
"Optional ISO 8601 datetime to backdate the publish (e.g. when migrating content). Requires content:publish_any permission. Without this, existing published_at is preserved on re-publish.",
}),

Copilot uses AI. Check for mistakes.
Address Copilot review on PR #890. The schema previously inherited
.nullish() from contentDateOverride, but publishing has no semantic
meaning for null (you can't 'clear' a publish timestamp by publishing).
The route silently dropped null via ?? undefined while still treating
{publishedAt: null} as a privileged backdate attempt — surprising
permission failures for what amounts to omitting the field.

Tightening the schema to .optional() makes the contract match actual
behavior: callers either pass a valid datetime or omit the field.
@ascorbic
ascorbic enabled auto-merge (squash) May 1, 2026 15:18
@ascorbic
ascorbic merged commit 8ae227c into main May 1, 2026
37 checks passed
@ascorbic
ascorbic deleted the feat/mcp-publish-update-fields branch May 1, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(mcp): content_update should persist SEO, bylines, and taxonomies

2 participants