Skip to content

feat(mcp): wave 2b — design package tools (list / create / set specs / delete) - #349

Merged
thewrz merged 1 commit into
mainfrom
feat/mcp-contract-wave2b
Jul 3, 2026
Merged

feat(mcp): wave 2b — design package tools (list / create / set specs / delete)#349
thewrz merged 1 commit into
mainfrom
feat/mcp-contract-wave2b

Conversation

@thewrz

@thewrz thewrz commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Why

Wave 2b of the MCP contract build-out (ADR-044) — packages, the middle of the final Wave 2 remainder. Wraps the design-package REST surface so an agent can group a project's sections into issuable packages.

What

Four new tools, contract-bound to existing REST ops (no openapi.yaml change):

Tool Tier REST op
list_packages read get /projects/{}/packages
create_package write post /projects/{}/packages
set_package_specs write put /packages/{}/specs
delete_package destructive delete /packages/{}
  • A design package is a subset of a project's sections issued together.
  • create_package — name unique per project (409 on collision → tool error), position auto-assigned.
  • set_package_specs — full ordered replacement (empty array clears); every specId must be in the package's own project TOC (else tool error).
  • delete_package is destructive — a hard CASCADE that also destroys the package's issued revisions and their frozen snapshots (there is no guard for issued revisions), so it's gated off by default.
  • Handlers reuse the REST body schemas via .shape and never throw (return { isError: true }). Four ops move MCP_UNEXPOSEDOP_TO_TOOL; tiers registered. Parity (INV-1/2/3) + coverage stay green.

Wave 2c (revisions — issue_package_revision + get_revision) is the last sub-wave; it completes full REST↔MCP parity.

Testing

  • Unit tests pass
  • Integration tests pass (package.integration.test.ts, 9/9)
  • Parity contract green (contract.integration.test.ts, 5/5)
  • Full pnpm test:coverage green (2233 pass; branches 80.39%)
  • pnpm lint green
  • CI green

🤖 Co-authored by Claude Opus 4.8 (1M context).

Summary by CodeRabbit

  • New Features

    • Added support for package-related actions: listing packages, creating packages, updating package specs, and deleting packages.
    • These actions are now available through the app’s tool interface with appropriate access levels.
  • Bug Fixes

    • Improved validation and error handling for package actions, including invalid IDs, missing input, duplicate names, and out-of-project references.
    • Package deletion and listing now return clearer, more consistent results.

…/ delete)

Expose the design-package REST surface as MCP tools, continuing REST↔MCP parity
(ADR-044). Four tools: list_packages (read), create_package and set_package_specs
(write), delete_package (destructive). A design package is a subset of a project's
sections issued together. create is name-unique per project; set_package_specs is
a full ordered replacement whose members must be in the project TOC; delete is a
hard CASCADE (also destroys the package's issued revisions + frozen snapshots —
no guard), so it's destructive/off-by-default. Handlers reuse the REST body
schemas via `.shape` and never throw (return { isError } on failure). Four ops
move MCP_UNEXPOSED → OP_TO_TOOL; tiers registered. Parity + coverage stay green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 92930ade-bdeb-46a4-ad05-811782d73168

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds Wave 2b "design packages" MCP tools: capability tiers and contract mappings for list/create/set-specs/delete package operations, corresponding Zod-validated handlers backed by DB calls, a registration module wiring these into the tool registrar, integration into registerTools, and an integration test suite.

Changes

Design package MCP tools

Layer / File(s) Summary
Capability tiers and contract mappings
src/mcp/capabilities.ts, src/mcp/contract-map.ts
Adds TOOL_TIERS entries for list_packages, create_package, set_package_specs (read/write), and delete_package (destructive); updates OP_TO_TOOL and MCP_UNEXPOSED to map the new REST operations and remove stale pending placeholders.
Package tool handlers
src/mcp/package-handlers.ts
Adds Zod schemas (ProjectIdShape, PackageIdShape, CreatePackageShape, SetPackageSpecsShape) and handler functions (handleListPackages, handleCreatePackage, handleSetPackageSpecs, handleDeletePackage) that validate input, call DB operations, and map errors (e.g., duplicate name, missing project/package) to tool errors.
Tool registration and wiring
src/mcp/package-tools.ts, src/mcp/tools.ts
Adds registerPackageTools to register read/write/destructive package tools on the ToolRegistrar and wires it into registerTools.
Integration tests
src/mcp/package.integration.test.ts
Adds DB-backed setup/teardown helpers and tests covering package create/list/delete, spec-setting validation, and rejection of invalid/unknown IDs.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant PackageHandler
  participant Zod
  participant DB

  Client->>PackageHandler: handleCreatePackage(args)
  PackageHandler->>Zod: validate projectId + name
  Zod-->>PackageHandler: parsed args or validation error
  PackageHandler->>DB: createPackage(projectId, name, pool)
  DB-->>PackageHandler: package row or Postgres error (23503/23505)
  PackageHandler-->>Client: ok(package) or toolError

  Client->>PackageHandler: handleSetPackageSpecs(args)
  PackageHandler->>Zod: validate packageId + specIds
  Zod-->>PackageHandler: parsed args or validation error
  PackageHandler->>DB: setPackageSpecs(packageId, specIds, pool)
  DB-->>PackageHandler: specs or PackageNotFoundError/SpecNotInProjectError
  PackageHandler-->>Client: ok({packageId, specs}) or toolError
Loading

Possibly related PRs

  • wrzonance/SpecR#334: Introduces the same tier-gated REST↔MCP contract infrastructure (contract-map.ts, TOOL_TIERS) that this PR extends with package tools.
  • wrzonance/SpecR#341: Adds new TOOL_TIERS entries and tool registrations in src/mcp/tools.ts following the same pattern for a different tool group (templates).
  • wrzonance/SpecR#344: Extends TOOL_TIERS, OP_TO_TOOL/MCP_UNEXPOSED, and registerTools wiring in the same shared files for a different tool group (revision-nomenclature).
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: Wave 2b MCP design package tools for list, create, set specs, and delete.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/mcp-contract-wave2b

Comment @coderabbitai help to get the list of available commands.

@thewrz
thewrz marked this pull request as ready for review July 3, 2026 15:26
@thewrz

thewrz commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

Codex (GPT-5.5, xhigh) adversarial review against main: no actionable defects. The package REST ops map to registered tools with tiers/handlers consistent with existing patterns.

@thewrz

thewrz commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
src/mcp/package.integration.test.ts (1)

117-137: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for order-preservation and empty-array clearing in set_package_specs.

The PR explicitly documents that set_package_specs "preserves order" and that "an empty array clears" the package's specs, but this test only exercises a single-spec array. Neither the ordering contract nor the clear-with-[] behavior is verified here.

♻️ Suggested additional assertions
   it('sets package members from the project TOC and rejects out-of-project specs', async () => {
     const { projectId, specId } = await projectWithSection('09 91 00');
     const pkg = parse<PackageSummary>(await handleCreatePackage({ projectId, name: 'Members' }));

     const res = await handleSetPackageSpecs({ packageId: pkg.packageId, specIds: [specId] });
     expect(isToolError(res)).toBe(false);
     expect(parse<{ specs: unknown[] }>(res).specs.length).toBe(1);

+    // empty array clears membership
+    const cleared = await handleSetPackageSpecs({ packageId: pkg.packageId, specIds: [] });
+    expect(isToolError(cleared)).toBe(false);
+    expect(parse<{ specs: unknown[] }>(cleared).specs).toHaveLength(0);
+
     // a spec not in this project's TOC → not in project
     expect(
       isToolError(await handleSetPackageSpecs({ packageId: pkg.packageId, specIds: [MISSING] }))
     ).toBe(true);

A separate multi-section fixture would be needed to assert order preservation (e.g., pass [specB, specA] and confirm specs[0].specId === specB).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mcp/package.integration.test.ts` around lines 117 - 137, The
`set_package_specs` coverage only verifies a single spec and misses the
documented ordering and clear semantics. Extend the `handleSetPackageSpecs` test
to use multiple specs from a multi-section fixture and assert the returned
`specs` preserve the input order, then add a call with an empty `specIds` array
and verify it clears the package’s specs. Keep the existing
`handleSetPackageSpecs`/`PackageSummary` assertions and add checks around
`parse(...)` for both the ordered result and the empty-array case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/mcp/package.integration.test.ts`:
- Around line 117-137: The `set_package_specs` coverage only verifies a single
spec and misses the documented ordering and clear semantics. Extend the
`handleSetPackageSpecs` test to use multiple specs from a multi-section fixture
and assert the returned `specs` preserve the input order, then add a call with
an empty `specIds` array and verify it clears the package’s specs. Keep the
existing `handleSetPackageSpecs`/`PackageSummary` assertions and add checks
around `parse(...)` for both the ordered result and the empty-array case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fb419675-fd26-48f8-8ac2-9daefa5fd1f6

📥 Commits

Reviewing files that changed from the base of the PR and between 9877816 and ae4f6de.

📒 Files selected for processing (6)
  • src/mcp/capabilities.ts
  • src/mcp/contract-map.ts
  • src/mcp/package-handlers.ts
  • src/mcp/package-tools.ts
  • src/mcp/package.integration.test.ts
  • src/mcp/tools.ts

@thewrz
thewrz merged commit d31dad0 into main Jul 3, 2026
6 checks passed
@thewrz
thewrz deleted the feat/mcp-contract-wave2b branch July 3, 2026 15:35
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.

1 participant