Skip to content

feat(mcp): add safe schema update tools - #2354

Open
masonjames wants to merge 2 commits into
emdash-cms:mainfrom
masonjames:codex/1681-mcp-schema-updates
Open

feat(mcp): add safe schema update tools#2354
masonjames wants to merge 2 commits into
emdash-cms:mainfrom
masonjames:codex/1681-mcp-schema-updates

Conversation

@masonjames

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds schema_update_collection and schema_update_field MCP tools so agents can update existing schemas without deleting tables, columns, content, or stored field values.

Both tools reuse the canonical REST handlers and validation, require schema:write plus the Admin role, preserve omitted properties during concurrent partial updates, invalidate affected caches, and return explicit migration errors for changes that cannot be represented safely as metadata-only updates. The MCP reference documents the new surface and migration limits.

Closes #1681

Type of change

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

Checklist

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: OpenAI Codex (GPT-5); RepoPrompt Oracle was used for adversarial review

Screenshots / test output

No visual changes.

  • pnpm typecheck — passed
  • pnpm lint:json | jq '.diagnostics | length'0
  • MCP integration and schema registry tests — 374 passed
  • Full MCP integration suite — 335 passed
  • Workspace build — passed
  • Docs build — passed
  • Changeset status and git diff --check — passed
  • Full core suite — 5,188 passed; one unrelated macOS path assertion compares /var/... with its /private/var/... resolved path
  • Package validation — publint passed; attw 0.18.2 exited with its internal Cannot read properties of undefined (reading 'filename') error

@masonjames masonjames added enhancement New feature or request area/core area/docs roadmap/1.0 Issues included in the public EmDash 1.0 roadmap. roadmap/api-mcp-agents Roadmap track: API, MCP, and agent workflows. roadmap/data-safety Roadmap track: data safety, schema, localization correctness. labels Aug 7, 2026
@changeset-bot

changeset-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b628703

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

This PR includes changesets to release 17 packages
Name Type
emdash Minor
@emdash-cms/cloudflare Minor
@emdash-cms/sandbox-workerd Patch
@emdash-cms/plugin-mcp-smoke Major
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-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

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 964 lines across 12 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.

@masonjames masonjames removed the size/L label Aug 7, 2026
@masonjames masonjames added this to the 1.0 milestone Aug 7, 2026
@pkg-pr-new

pkg-pr-new Bot commented Aug 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/auth-atproto

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

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

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

emdash

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

create-emdash

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

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

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

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@2354

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@2354

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@2354

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@2354

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@2354

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@2354

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@2354

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: b628703

@masonjames
masonjames marked this pull request as ready for review August 7, 2026 02:36
@github-actions github-actions Bot added the review/needs-review No maintainer or bot review yet label Aug 7, 2026

@emdashbot emdashbot Bot 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.

This PR is a focused, well-scoped feature addition: two new MCP tools (schema_update_collection, schema_update_field) that delegate to the existing REST handlers and validation, plus the underlying registry changes needed to make partial updates safe and concurrent-friendly.

Approach: The approach is sound and fits EmDash. Reusing updateCollectionBody/updateFieldBody for the MCP input schemas keeps the REST and MCP surfaces in sync, and the registry rewrite of updateCollection/updateField moves the read-modify-write logic inside the transaction so omitted fields are preserved. The narrowing of in-place type changes to the safe string/text/slug aliases (even when the SQLite column type happens to match) is the right conservative choice for a "safe update" tool.

What I checked:

  • Diff and full changed files in packages/core/src/{api,mcp,schema,query}.
  • Caching/invalidation paths: field writes now call both invalidateCollectionCache and invalidateSchemaCache; collection writes go through invalidateUrlPatternCache() which also busts the schema object-cache namespace.
  • Validation: updateCollectionBody and updateFieldBody are used by both REST and MCP; new urlPatternValue and fieldValidation refinements close validation gaps without increasing the logged-out query count.
  • Security: schema writes require schema:write + Role.ADMIN; SQL is built with Kysely/parameterized values; no interpolation into SQL.
  • Tests: new integration tests cover happy paths, migration errors, invalid validation, concurrent partial updates, and permission gating.

I did not find any blocking issues. The changeset, docs, and tests are all in place, and the implementation matches the PR's stated goals.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-review No maintainer or bot review yet labels Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core area/docs cla: signed enhancement New feature or request overlap review/approved Approved; no new commits since roadmap/api-mcp-agents Roadmap track: API, MCP, and agent workflows. roadmap/data-safety Roadmap track: data safety, schema, localization correctness. roadmap/1.0 Issues included in the public EmDash 1.0 roadmap. size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add MCP tools for safe schema updates

1 participant