Repository navigation
feat(mcp): publishedAt on content_publish, seo/bylines/publishedAt on content_update - #890
Conversation
… 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.
🦋 Changeset detectedLatest commit: dc60faa The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-perf-coordinator | dc60faa | May 01 2026, 03:17 PM |
Deploying with
|
| 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 |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-i18n | dc60faa | May 01 2026, 03:18 PM |
Scope checkThis 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. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-demo-cache | dc60faa | May 01 2026, 03:19 PM |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
emdash-playground | dc60faa | May 01 2026, 03:19 PM |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
There was a problem hiding this comment.
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
publishedAtoverride support tocontent_publish(MCP + REST) gated bycontent:publish_any. - Expose/persist
seo,bylines, andpublishedAtvia MCPcontent_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.
| // 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, | ||
| }); |
There was a problem hiding this comment.
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.
| 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.", | ||
| }), |
There was a problem hiding this comment.
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 }.
| 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.", | |
| }), |
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.
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
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
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:
Checklist
AI-generated code disclosure
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.)