Skip to content

[4] Public catalog MCP surface for agent assembly - #32

Merged
FlyOverCoderKY merged 7 commits into
mainfrom
grok/agent-assembly-phase-4
Jul 29, 2026
Merged

FlyOverCoderKY merged 7 commits into
mainfrom
grok/agent-assembly-phase-4

Conversation

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor

Summary

Implements Agent Assembly Plan Phase 4 — a thin public MCP server over the published composition catalog.

  • Endpoint: https://pegma.dev/api/mcp on existing pegma-dev-api (stateless Streamable HTTP via createMcpHandler)
  • Tools: list_components, get_component, list_recipes, get_recipe, plan_composition
  • Source of truth: fetches https://pegma.dev/catalog.json (optional CATALOG_URL for local); MCP never invents package facts
  • Config snippet: skill page, skill.md, llms.txt, footer
  • No private data plane: public catalog reads only; no auth for reads

Phase exit criteria

  • MCP config snippet on pegma.dev
  • Tools return catalog facts only
  • Progressive disclosure (list compact → detail on demand)
  • plan_composition is rule-based over structured capabilityTags (not an LLM)
  • No private data plane

Plan

docs/AGENT_ASSEMBLY_PLAN.md Phase 4

Test evidence

  • npm run test:node — 154 passed (includes mcp-tools + catalog fetch tests)
  • npx tsc -p worker/tsconfig.json --noEmit — clean
  • npx astro check — 0 errors

Residual risks / follow-up

  • 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).

Residual Phase 5

Scaffold + eval harness remains open.

Copilot AI review requested due to automatic review settings July 29, 2026 15:39
@cursor

cursor Bot commented Jul 29, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@github-actions

github-actions Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Grok Grok Build Review — 2 issues found

Review complete. Findings are listed below.

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.

workflow run

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 86109c23e0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/data/mcp-tools.ts Resolved
Comment thread src/data/mcp-tools.ts Resolved

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

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.
src/layouts/Base.astro Adds an MCP link in the site footer nav.
src/data/mcp-tools.ts Adds pure, progressive-disclosure catalog tool functions + deterministic planComposition.
src/data/mcp-tools.test.ts 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.
        'Full recipe: intent, packages, adapters, host responsibilities, anti-patterns, fixture citation. Synthetic intents only.',
      inputSchema: {
        id: z.string().min(1).describe('Catalog recipe id (e.g. cf-passkey-accounts)'),
      },
    },

worker/src/mcp-server.ts:175

  • 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

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

Comment thread worker/src/mcp-server.ts
Comment on lines +65 to +68
description:
'List Pegma composition catalog components (id, summary, status, packages). Progressive disclosure — use get_component for owns/refuses/deps/adapters.',
inputSchema: {},
},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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.

Comment thread src/data/mcp-tools.ts Resolved
Comment thread worker/src/index.ts Resolved
@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85bcfba21e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/data/mcp-tools.ts Resolved
Comment thread src/data/mcp-tools.ts Resolved
Comment thread src/data/mcp-tools.ts Resolved
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.
@FlyOverCoderKY
FlyOverCoderKY force-pushed the grok/agent-assembly-phase-4 branch from 85bcfba to 74e1062 Compare July 29, 2026 16:04
@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74e1062d57

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/data/mcp-tools.ts Resolved
Comment thread src/data/mcp-tools.ts Resolved
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.
@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 21bf1ecbe9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/data/catalog-enrichment.ts Resolved
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.
@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3f11e4d571

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/data/mcp-tools.ts Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Grok 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.

🐞 1 bugs · ⚠️ 1 warnings · 🤏 0 nits

Reviewed commit 3f11e4d · workflow run

Comment thread src/data/mcp-tools.ts Resolved
Comment thread worker/src/mcp-catalog-fetch.ts Resolved
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.
@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Grok 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.

🐞 1 bugs · ⚠️ 1 warnings · 🤏 0 nits

Reviewed commit 2630701 · workflow run

Comment thread src/data/mcp-tools.ts Resolved
Comment thread src/data/mcp-tools.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2630701561

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/data/mcp-tools.ts Resolved
Comment thread src/data/mcp-tools.ts Resolved
Comment thread src/data/mcp-tools.ts Resolved
Comment thread worker/src/mcp-catalog-fetch.ts Resolved
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.
@FlyOverCoderKY

Copy link
Copy Markdown
Contributor Author

@codex review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Grok 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.

🐞 2 bugs · ⚠️ 0 warnings · 🤏 0 nits

Reviewed commit a54b727 · workflow run

Comment thread src/data/mcp-tools.ts
(t) => EXCLUSIVE_TAGS.has(t) && !requested.includes(t),
);
// More unrequested exclusive intents than overlapping tags → incidental.
if (unrequestedExclusive.length > overlap) return false;

Copy link
Copy Markdown

Choose a reason for hiding this 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.

Comment thread src/data/mcp-tools.ts
// Skip known third-party integration package name suffixes when not
// requested via recipe pins (auth0/stripe/tokens-style integrations).
if (
/-(auth0|stripe|tokens)$/.test(p.name) ||

Copy link
Copy Markdown

Choose a reason for hiding this comment

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.

@FlyOverCoderKY
FlyOverCoderKY merged commit ea6cdfa into main Jul 29, 2026
2 checks passed
@FlyOverCoderKY
FlyOverCoderKY deleted the grok/agent-assembly-phase-4 branch July 29, 2026 16:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a54b727da4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/data/mcp-tools.ts
Comment on lines +143 to +144
// More unrequested exclusive intents than overlapping tags → incidental.
if (unrequestedExclusive.length > overlap) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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.

Useful? React with 👍 / 👎.

Comment thread src/data/mcp-tools.ts
Comment on lines +140 to +144
const unrequestedExclusive = itemCore.filter(
(t) => EXCLUSIVE_TAGS.has(t) && !requested.includes(t),
);
// More unrequested exclusive intents than overlapping tags → incidental.
if (unrequestedExclusive.length > overlap) return false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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.

Useful? React with 👍 / 👎.

Comment thread src/data/mcp-tools.ts
Comment on lines +374 to +378
adapterHosts.length > 0 &&
!adapterHosts.includes(input.host) &&
!adapterHosts.includes('memory')
) {
// Soft demote: still include but lower score for host mismatch.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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.

AGENTS.md reference: AGENTS.md:L32-L34

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants