You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[4] Public catalog MCP surface for agent assembly - #32
Worker deploy: route lives on pegma-dev-api; after merge, operator must run npm run worker:deploy for /api/mcp to go live (Pages ships site surfaces automatically).
No full Streamable HTTP client integration test in CI (pure tool + fetch unit coverage).
The Phase 4 MCP surface is correctly scoped: public catalog reads only, progressive list/detail tools, and a Worker endpoint that is not the system of record. The pure tool layer is the right place for planning logic and is largely well tested. Two planner defects remain: exclusive-tag coverage admits the wrong recipe when a non-exclusive tag is shared, and multi-package emission drops @pegma/authorization-tokens via a name heuristic that contradicts both the catalog and the surrounding fail-open comment.
🐞 2 bugs · ⚠️0 warnings · 🤏 0 nits
See the review — 2 inline comments. Commit a54b727.
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements Agent Assembly Plan Phase 4 by adding a thin, stateless public MCP (Streamable HTTP) surface on the existing pegma-dev-api Worker that serves catalog-backed composition discovery and deterministic planning (no invented facts), and updates the site/docs to advertise the endpoint and configuration snippet.
Changes:
Add a public MCP server (/api/mcp) with tools for listing/getting components/recipes and a rule-based plan_composition.
Add Worker-side catalog fetch + short TTL in-isolate cache with ETag revalidation, plus unit tests for fetch + tool logic.
Update skill/docs/site surfaces (skill page, skill.md, llms.txt, footer) to document the optional MCP endpoint and setup.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
File
Description
worker/tsconfig.json
Extends Worker TS project includes so the MCP surface can typecheck against shared catalog/tool logic.
worker/src/mcp-server.ts
Implements the public MCP server and registers catalog-backed tools.
worker/src/mcp-catalog-fetch.ts
Adds catalog fetch with TTL cache + conditional GET (ETag) for MCP requests.
worker/src/mcp-catalog-fetch.test.ts
Unit tests for catalog fetch caching, ETag revalidation, URL override, and shape validation.
worker/src/index.ts
Routes /api/mcp to the MCP handler and returns a 503 JSON sentinel on handler failure.
worker/README.md
Documents the new public MCP endpoint hosted by the Worker.
worker/.dev.vars.example
Adds CATALOG_URL override example for local/dev MCP testing.
src/pages/skill.astro
Adds an “Optional MCP surface” section and links to /api/mcp.
Unit tests for progressive-disclosure behavior and planning logic.
public/skill.md
Documents the optional MCP transport, tools, and configuration snippet.
public/llms.txt
Adds an agents-facing section linking to the MCP endpoint and tool list.
package.json
Adds dependencies needed for MCP server + handler + schemas (@modelcontextprotocol/server, agents, zod).
package-lock.json
Lockfile updates for newly added dependencies.
docs/AGENT_ASSEMBLY_PLAN.md
Marks Phase 4 as shipped and documents delivered artifacts/surfaces.
Comments suppressed due to low confidence (4)
worker/src/mcp-server.ts:93
inputSchema should be a Zod object schema (e.g. z.object({ id: ... })) rather than an object literal of Zod properties. As written, this is unlikely to validate inputs correctly and may not match the MCP server SDK's expected schema type.
description:
'Full catalog entry for one component: owns, refuses, dependencies, adapters, hostMustProvide, packages, links.',
inputSchema: {
id: z.string().min(1).describe('Catalog component id (e.g. identity, storage-core)'),
},
},
worker/src/mcp-server.ts:120
McpServer.registerTool expects a schema object (typically z.object(...)) for inputSchema. Passing {} here can skip validation and may break tool registration depending on the MCP server SDK implementation.
description:
'List synthetic composition recipes (id, intent, packages, fixture status). Use get_recipe for full metadata and fixture citation.',
inputSchema: {},
},
worker/src/mcp-server.ts:145
inputSchema should be a Zod object schema (e.g. z.object({ id: ... })). Using an object literal of Zod properties is unlikely to be treated as a schema by the MCP server SDK.
inputSchema should be declared as a Zod object schema. Using an object literal here is unlikely to satisfy the MCP server SDK's schema expectations and may prevent proper input validation for plan_composition.
'Deterministic package/recipe recommendation from structured capabilityTags and optional host. Rule-based over the catalog — not an LLM. Prefer productionOnly=true for real hosts.',
inputSchema: {
capabilityTags: z
.array(capabilityTagSchema)
.describe('Structured capability tags from the catalog schema'),
host: z
The reason will be displayed to describe this comment to others. Learn more.
Intentional: Cloudflare Agents SDK docs for createMcpHandler/McpServer.registerTool use inputSchema as a map of field name to Zod schema (e.g. { name: z.string().optional() }), not a wrapping z.object(...). That is the form used in the Cloudflare handler-api docs and matches the installed @modelcontextprotocol/server registration shape.
Add a thin Streamable HTTP MCP server on pegma-dev-api at /api/mcp that
reads the published composition catalog. Tools list/get components and
recipes plus rule-based plan_composition; skill page and llms.txt carry
the config snippet. Catalog remains the system of record.
Close recommended packages over required component dependencies and
recipe package owners. Gate production plans on green fixtures. Fix
static_host heavy-tag filtering and log MCP error messages.
plan_composition no longer unions every partial recipe match into one
install set; packages come from the top recipe (or tag match) with
requires-closure. Adapter packages are filtered by host. Enrich
storage-blobs so it is reachable via the storage capability tag.
Include tag-matched components alongside the primary recipe so combined
capabilities (e.g. accounts+health) stay in the plan. Skip recipe package
pins that are adapters for a different host than requested.
Add storage_blobs to the catalog capability tag set and tag storage-blobs
with it so plan_composition no longer selects blob packages on generic
storage / host-only queries.
The reason will be displayed to describe this comment to others. Learn more.
Grok Build Review
Phase 4 delivers a coherent public MCP surface: pure catalog tools, Worker fetch/cache, Streamable HTTP wiring, and install documentation are aligned with the stated exit criteria. The critical defect is in plan_composition package assembly: with a primary recipe selected, the planner still emits every package on every closed component and never applies recipe pins, so production recommendations for green recipes (for example cf-passkey-accounts) over-include unrelated packages such as Auth0/Stripe authorization adapters. Catalog fetch also fails closed after TTL expiry even when a warm in-isolate cache remains usable.
Require meaningful core-tag coverage so incidental single-tag hits do not
select heavy recipes. Prefer primary-recipe package pins over dumping every
package on multi-package components. Serve stale catalog on revalidation
failure when a warm isolate cache exists.
The reason will be displayed to describe this comment to others. Learn more.
Grok Build Review
The MCP transport, catalog fetch path, and progressive-disclosure tool surface meet the Phase 4 contract and correctly avoid a private data plane. The deterministic planner does not. meaningfulCoverage requires half of each item's core tags and therefore rejects the production flagship accounts recipe for ordinary sparse requests such as accounts+passkeys. The multi-package emission heuristic also truncates legitimate multi-package components to a single package when no green recipe pin list is available. These are correctness defects in the agent-facing install plan, not documentation nits.
Allow singular accounts/passkeys requests while still rejecting incidental
storage-only selection of the accounts recipe. Emit host adapter packages
beside recipe core pins. On revalidation failure, serve stale catalog and
reset TTL to back off.
The reason will be displayed to describe this comment to others. Learn more.
Grok Build Review
The Phase 4 MCP surface is correctly scoped: public catalog reads only, progressive list/detail tools, and a Worker endpoint that is not the system of record. The pure tool layer is the right place for planning logic and is largely well tested. Two planner defects remain: exclusive-tag coverage admits the wrong recipe when a non-exclusive tag is shared, and multi-package emission drops @pegma/authorization-tokens via a name heuristic that contradicts both the catalog and the surrounding fail-open comment.
The reason will be displayed to describe this comment to others. Learn more.
🐞 [bug] Exclusive-tag gate admits recipes whose exclusive intent was never requested
meaningfulCoverage rejects only when unrequestedExclusive.length > overlap. A single shared non-exclusive tag therefore admits a recipe that also carries an unrequested exclusive intent.
Concrete case: support-queue-slice tags are support_queue + mail_transactional. For capabilityTags: ['mail_transactional'], overlap is 1 and unrequestedExclusive is ['support_queue']. The condition 1 > 1 is false, so the recipe is accepted. Sort then prefers it over storage-audit-mail-outbox because specificity (score / tagCount) is evaluated before fixture rank (1/2 > 1/3).
With productionOnly: false this already selects the deferred support recipe for a mail-only plan. Once that recipe is green, the same mis-selection occurs under the default production path. The comment states exclusive intents must not be selected from incidental overlap; the inequality does not implement that rule. Allowing accounts alone to match an accounts+passkeys recipe is still possible with a stricter rule: if the item has exclusive tags, require that at least one of those exclusive tags appears in the request.
Suggestion: Replace the length comparison with a requirement that any item carrying exclusive tags must share at least one exclusive tag with the request. Example: if itemExclusive.length > 0 and none of those tags are requested, return false. Keep non-exclusive recipes (e.g. storage/audit/mail outbox) selectable from non-exclusive tags alone. Add a regression test: mail_transactional alone must not select support-queue-slice; support_queue (with or without mail) may.
The reason will be displayed to describe this comment to others. Learn more.
🐞 [bug] Name heuristic drops first-party @pegma/authorization-tokens from authorization plans
emitComponentPackages special-cases multi-package components with no adapters by skipping names matching /-(auth0|stripe|tokens)$/. @pegma/authorization-tokens is a published first-party package on authorization-core and is part of that component's declared owns (short-lived signed access grants). It is not an Auth0/Stripe provider adapter.
For plan_composition({ capabilityTags: ['authorization'] }) there is no primary recipe that pins authorization packages, so emission takes this branch and omits @pegma/authorization-tokens while still emitting authorization-storage and other packages. That invents an install set the catalog does not justify and contradicts the immediate comment that this path should prefer failing open over silently dropping dependencies. The same regex would also drop any future legitimate @pegma/*-tokens package.
Suggestion: Limit name-based exclusion to true third-party provider adapters (-auth0, -stripe) only, or better: encode integrability in catalog metadata (e.g. adapter/package role) and filter on that. Do not treat -tokens as third-party. Add a test that an authorization-only plan includes @pegma/authorization-tokens when that package is published on the component.
The reason will be displayed to describe this comment to others. Learn more.
Handle singular accounts requests
When the valid input is only capabilityTags: ['accounts'], the accounts recipe has three unrequested exclusive tags (passkeys, email_codes, and rate_limit_durable) but only one overlap, so this condition rejects it; the Identity component is rejected similarly. The planner therefore returns no account packages for the singular account request that the function comment explicitly says should work.
The reason will be displayed to describe this comment to others. Learn more.
Reject the outbox recipe for bare storage requests
For capabilityTags: ['storage'], storage-audit-mail-outbox has one overlapping tag and no unrequested member of EXCLUSIVE_TAGS, so this predicate accepts the green recipe and makes its audit and mail packages part of the install plan. A caller asking only for record storage is thus given unrelated audit/outbox behavior; recipe matching needs to gate additional core capabilities such as audit and mail_transactional rather than treating this overlap as meaningful.
The reason will be displayed to describe this comment to others. Learn more.
Reject recipes incompatible with the requested host
When the requested host is Azure and the matching intent is accounts/passkeys, the only green accounts recipe is Cloudflare-specific, but this branch merely lowers its score, so it still becomes primary. Package generation then drops the D1 pin and adds the Azure Tables adapter while continuing to present the Cloudflare fixture as green, yielding an adapter-swapped composition that the cited fixture never executed; return no matching recipe (or a compatible fixture) instead of adapting it implicitly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements Agent Assembly Plan Phase 4 — a thin public MCP server over the published composition catalog.
https://pegma.dev/api/mcpon existingpegma-dev-api(stateless Streamable HTTP viacreateMcpHandler)list_components,get_component,list_recipes,get_recipe,plan_compositionhttps://pegma.dev/catalog.json(optionalCATALOG_URLfor local); MCP never invents package factsskill.md,llms.txt, footerPhase exit criteria
plan_compositionis rule-based over structuredcapabilityTags(not an LLM)Plan
docs/AGENT_ASSEMBLY_PLAN.mdPhase 4Test evidence
npm run test:node— 154 passed (includesmcp-tools+ catalog fetch tests)npx tsc -p worker/tsconfig.json --noEmit— cleannpx astro check— 0 errorsResidual risks / follow-up
pegma-dev-api; after merge, operator must runnpm run worker:deployfor/api/mcpto go live (Pages ships site surfaces automatically).Residual Phase 5
Scaffold + eval harness remains open.