Skip to content

Fix plugin MCP names and isolate invalid schemas - #988

Merged
danielmlr merged 1 commit into
emdash-cms:mainfrom
masonjames:codex/plugin-mcp-tools
Oct 9, 2026
Merged

danielmlr merged 1 commit into
emdash-cms:mainfrom
masonjames:codex/plugin-mcp-tools

Conversation

@masonjames

@masonjames masonjames commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Scoped plugin IDs produced MCP names containing @ and /. This fixes the generated names and displays them in the admin consent list. Duplicate generated names are skipped with a warning, and unreadable serialized schemas no longer prevent other tools from loading in either the sandboxed or built-plugin path.

Existing MCP-safe plugin IDs keep their names. The changeset explains how to update saved calls using old scoped names. Addresses the latest review on the plugin MCP support already in main.

Type of change

  • Bug fix
  • Feature (requires an accepted feature plan or RFC)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Your connection to this change

This continues my existing plugin-MCP contribution in #988 and addresses the specific fixes requested in its maintainer review. I reviewed the complete replacement commit before approving its submission.

  • I use EmDash and ran into the problem this PR addresses
  • I maintain a tool, dependency, or service that EmDash uses, and this change concerns that integration
  • A Maintainer requested this specific follow-up on my existing PR

Checklist

No new translatable strings: the changed display is an MCP identifier supplied by the API. Arabic RTL was checked. A feature design is not applicable to this bug fix.

AI assistance disclosure

  • This PR includes AI-generated code or text — model/tool: OpenAI Codex (GPT-6), GPT-6 Astra (rendered UI verification), Claude Opus 5.5 (independent review of this commit). Incorporates feedback from the linked review; earlier assistance remains recorded in the PR history.

Screenshots / test output

Local validation for 581207cf1, based on upstream 9f7eb2288:

  • Full root build, package typecheck, formatting, quick lint, and type-aware lint passed; zero lint diagnostics.
  • MCP, adapter, and admin API integration suites: 544 tests passed.
  • PluginManager browser suite: 25 tests passed.
  • Docs build passed.
  • Tool-disabled Claude Opus 5.5 review of this commit found no blocking defects. Additional local checks cover scoped underscore names and fallback-schema MCP listing and invocation.
  • Removing the collision and schema guards produced five regression failures; restoring them produced 62 passing focused tests. The browser regression also failed before the display fix and passed afterwards.

The screenshots use the real PluginManager component and styles. The before fixture omits the new API field to reproduce the legacy display. The after fixtures show the server-generated name in English and Arabic, with MCP consent off.

Legacy API response displays @acme/calendar__createEvent before consent

English plugin consent list displays acme__calendar__createEvent

Arabic RTL plugin consent list displays the generated MCP name

Hosted CI is reported separately by GitHub.

@changeset-bot

changeset-bot Bot commented May 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 581207c

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

This PR includes changesets to release 12 packages
Name Type
emdash Patch
@emdash-cms/admin Patch
@emdash-cms/cloudflare Patch
@emdash-cms/plugin-test Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
create-emdash Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
@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

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 683 lines across 26 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.

@pkg-pr-new

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

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/auth-atproto

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

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

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

emdash

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

create-emdash

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

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

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

@emdash-cms/plugin-cli

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

@emdash-cms/plugin-test

npm i https://pkg.pr.new/@emdash-cms/plugin-test@988

@emdash-cms/plugin-types

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

@emdash-cms/registry-client

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

@emdash-cms/registry-lexicons

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

@emdash-cms/registry-loader

npm i https://pkg.pr.new/@emdash-cms/registry-loader@988

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/@emdash-cms/registry-moderation@988

@emdash-cms/registry-verification

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

upgrade-emdash

npm i https://pkg.pr.new/upgrade-emdash@988

@emdash-cms/sandbox-workerd

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-field-kit

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: 581207c

@masonjames
masonjames marked this pull request as ready for review May 11, 2026 13:57
@github-actions

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.

@ascorbic

Copy link
Copy Markdown
Member

/review

@ask-bonk ask-bonk 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.

Solid implementation overall — capability gating, hex-encoded tool names to avoid plugin-id collisions, admin scope + ADMIN role enforced before dispatch, and good test coverage (capability filter, sandbox-not-loaded guard, scope check, ID collision). The delegation to handlePluginApiRoute is a clean reuse strategy.

Findings are mostly DX/footgun concerns at the definePlugin boundary plus a couple of manifest cross-validation gaps. No correctness or auth bugs that block merge.

Notes:

  • Trusted (definePlugin) plugins skip several validations that sandboxed plugins get from pluginManifestSchema — tool-name shape, route existence, and capability declaration. Silent filtering vs. early errors.
  • getPluginRouteMeta falls back to { public: false } for any route on an existing sandboxed plugin, so MCP tools pointing at nonexistent sandboxed routes register fine and fail at call time. The catch-all route has the same behavior, so this matches existing semantics — flagging only as DX context.
  • One coverage gap: no test for requireRole(ADMIN) rejecting a non-admin user holding an admin-scoped token (the defense-in-depth branch).
  • Sandboxed plugin MCP tools have no input schema in ManifestMcpToolEntry, so they all fall back to z.record(z.string(), z.unknown()) — MCP clients lose introspection. Future work, but worth tracking.

Comment thread packages/core/src/mcp/server.ts Resolved
Comment thread packages/core/src/mcp/server.ts Resolved
Comment thread packages/core/src/emdash-runtime.ts Resolved
@ask-bonk

ask-bonk Bot commented May 12, 2026

Copy link
Copy Markdown
Contributor

Review submitted successfully (review ID 4270626524) with 6 line-anchored comments and a summary body.

Key findings:

  • DX footguns at definePlugin: no validation of MCP tool name shape, route existence, or required mcp:tools capability — sandboxed plugins get all three from manifest schema, trusted plugins fail silently.
  • Manifest cross-validation gaps: mcpTools[i].route not cross-checked against routes; mcpTools non-empty not cross-checked against the capability declaration.
  • Test coverage gap: no test for the defense-in-depth requireRole(ADMIN) branch.
  • Schema introspection: sandboxed plugin tools fall back to z.record(string, unknown), losing client-side schema info.
  • Documentation suggestion: note that routeMeta.public is intentionally ignored in the MCP path.
  • Dedup gap: getPluginMcpTools doesn't dedup across the three sources; relies on registration-order semantics in createMcpServer.

No blocking issues — auth/correctness paths check out.

github run

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Excellent work. One thing that would be good would be if there was a way we could provide a schema for tool inputs so we can validate and describe them. While we can't serialise a Zod schema directly, maybe a JSON schema would work?

Can you include docs in the PR too, as it will also make it easier to review.

Comment thread packages/core/src/mcp/server.ts Resolved
@masonjames

Copy link
Copy Markdown
Contributor Author

Excellent work. One thing that would be good would be if there was a way we could provide a schema for tool inputs so we can validate and describe them. While we can't serialise a Zod schema directly, maybe a JSON schema would work?

Can you include docs in the PR too, as it will also make it easier to review.

Agreed on both.

I’ll add docs in this PR, and I’ll look at adding a constrained inputSchema field to ManifestMcpToolEntry for client-facing tool introspection. I’m inclined to keep route handlers as the runtime validation source of truth for now, so plugin tools still execute through the existing route validation/context path, while JSON Schema gives MCP clients useful parameter descriptions.

I’ll keep the JSON Schema subset conservative: object root, properties, required, additionalProperties, scalar/array types, enum, description, default, and basic string/number/array constraints.

No $ref/recursive schemas in this pass unless you think we should make that part of the initial contract.

@masonjames

Copy link
Copy Markdown
Contributor Author

Done. I added docs for plugin MCP tools and added manifest-side inputSchema support using a constrained JSON Schema subset. Trusted plugins can still pass Zod via input; manifest/sandboxed plugins can now provide serializable JSON Schema, which is converted to Zod at MCP registration for client metadata and call validation.

Comment thread packages/core/src/mcp/json-schema.ts Resolved
Comment thread packages/core/src/plugins/types.ts Resolved
Comment thread packages/core/src/emdash-runtime.ts Resolved
@ascorbic

Copy link
Copy Markdown
Member

/review

@ask-bonk ask-bonk 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.

Reviewing on top of the existing rounds (ask-bonk + ascorbic). Most of the substantive concerns from the earlier passes — capability cross-check, route cross-check, tool-name shape validation, JSON Schema introspection, dual-check coverage, admin-only intent comment, runtime dedup — have been addressed. A few remaining things worth a look, all DX/robustness rather than auth/correctness:

  • One bad inputSchema from a trusted plugin can take down the whole MCP endpoint because jsonSchemaObjectToZod is called inline during createMcpServer and has no isolation. Trusted plugins skip the Zod manifest validation that sandboxed plugins get, so the JSON Schema is unvalidated until z.fromJSONSchema throws.
  • pluginToolName collision detection looks for __ within a single segment, but two distinct valid scoped IDs can still collapse to the same generated name when a dash sits on either side of the slash boundary (@a-/b vs @a/-b both → a___b__foo). Narrow but real.
  • No dedicated unit test file for pluginToolName — the integration tests cover the happy paths but the ambiguous-segment / hash-fallback branches aren't directly exercised.

No blocking issues from me.

Comment thread packages/core/src/mcp/server.ts Resolved
@ask-bonk

ask-bonk Bot commented May 16, 2026

Copy link
Copy Markdown
Contributor

Review submitted successfully (review ID 4303523122) with three line-anchored comments and a summary body.

Key findings (all non-blocking, DX/robustness rather than auth/correctness):

  • Trusted-plugin inputSchema blast radius: jsonSchemaObjectToZod is called inline in createMcpServer. Sandboxed plugins get manifest-level Zod validation; trusted plugins go straight through with no runtime check. A single malformed schema makes z.fromJSONSchema throw, which the outer try/catch in api/mcp.ts turns into a JSON-RPC 500 — taking down every other built-in MCP tool, not just the offending one. Suggested wrapping the conversion in a try/catch fallback, or validating inputSchema in definePlugin.
  • pluginToolName narrow collision: the __-in-segment check misses cases where a dash sits on either side of the slash boundary (@a-/b vs @a/-b both → a___b__foo). The runtime dedup silently drops the second registration. Tightening the regex to look at the joined readable id (or hashing unconditionally) closes it.
  • Unit-test coverage gap: pluginToolName has no dedicated unit tests — the hash-fallback and segment edge cases are only indirectly covered by the integration suite.

Prior reviewers' concerns (capability/route cross-validation, JSON Schema introspection, dual-check coverage, runtime dedup, admin-only intent comment, real-implementation testing) all look addressed.

github run

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-rereview New commits since the last review labels Oct 9, 2026
@masonjames
masonjames force-pushed the codex/plugin-mcp-tools branch from 42a37df to 581207c Compare October 9, 2026 15:43
@masonjames masonjames changed the title Harden plugin MCP tool registration Fix plugin MCP names and isolate invalid schemas Oct 9, 2026
@github-actions github-actions Bot added area/admin size/L review/needs-rereview New commits since the last review and removed size/M needs-rebase review/awaiting-author Reviewed; waiting on the author to respond labels Oct 9, 2026
@emdashbot emdashbot Bot added review/needs-rereview New commits since the last review and removed review/needs-rereview New commits since the last review labels Oct 9, 2026
@masonjames

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review @danielmlr!

Addressed these in 581207cf1 and rebuilt the branch on main, resolving the import conflict.

Both plugin API endpoints now return the generated MCP name, and the admin consent list displays it. Schema conversion is guarded in both loading paths, with conversion still lazy for built plugins.

The collision handling, regression coverage, changeset, and documentation are updated. Local build, lint, typecheck, docs build, and relevant tests passed. English and Arabic screenshots are in the PR description.

Ready for another look

@danielmlr danielmlr added the ci:run Approve and re-run CI on the PR's latest commit label Oct 9, 2026
@github-actions github-actions Bot removed the ci:run Approve and re-run CI on the PR's latest commit label Oct 9, 2026
@danielmlr danielmlr self-assigned this Oct 9, 2026

@danielmlr danielmlr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for sticking with this one, Mason, and for rebuilding it on top of the MCP support that landed in the meantime.
Everything from my last review is covered.

@emdashbot emdashbot Bot added review/needs-rereview New commits since the last review and removed review/needs-rereview New commits since the last review labels Oct 9, 2026
@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/needs-rereview New commits since the last review labels Oct 9, 2026
@danielmlr
danielmlr merged commit 0ce875f into emdash-cms:main Oct 9, 2026
77 of 79 checks passed
@emdashbot emdashbot Bot mentioned this pull request Oct 9, 2026
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.

3 participants