Skip to content

feat(mcp): add workflow toolbox planner#533

Open
Khaostica wants to merge 2 commits into
JSONbored:mainfrom
Khaostica:claude/sweet-yalow-a3e2b7
Open

feat(mcp): add workflow toolbox planner#533
Khaostica wants to merge 2 commits into
JSONbored:mainfrom
Khaostica:claude/sweet-yalow-a3e2b7

Conversation

@Khaostica
Copy link
Copy Markdown
Contributor

Summary

  • Adds a read-only plan_workflow_toolbox MCP tool that composes existing registry primitives into a bounded toolbox for a user goal.
  • Returns recommended entries with reason codes, caveats, trust metadata, and nextSteps pointers to existing tools.
  • Surfaces guidance instead of fabricating recommendations when the goal does not match.

What changed

  • Added plan_workflow_toolbox to READ_ONLY_TOOL_NAMES, TOOL_DEFINITIONS, TOOL_INPUT_SCHEMAS, the registry dispatcher, and .d.ts type surface.
  • Required at least one keyword match when the goal is specific, so weak/empty matches return a guidance[] payload instead of unrelated entries.
  • Diversified across categories by default (preferDiverseCategories=true); tagged surfaced entries with complementary_category when multiple categories are picked.
  • Wired reason codes query_match, category_match, same_platform, trusted_package, source_backed, has_safety_notes, has_privacy_notes, complementary_category.
  • Added protocol-level tests for happy path, constrained category/platform, and weak-match guidance. Extended the MCP HTTP route tool-list assertion.
  • Documented the tool in packages/mcp/README.md.

Why

Closes #491.

Invariants

  • Read-only: no external calls, no submission writes, no local file writes.
  • All output is metadata-derived from search-index.json; no fabricated source stats.
  • Tool annotations stay { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }.
  • MCP_PUBLIC_POLICY envelope is applied by the existing withPublicPolicy wrapper; not bypassed.
  • Bounded: limit clamped to 1–10, token count capped at 12.

Backward compatibility

  • Additive only. Existing tool names, input/output schemas, and dispatch behavior are unchanged.
  • No changes to apps/web/public/data/**, apps/web/src/generated/**, README.md, or apps/web/public/downloads/**.

Visual impact

No visual impact — MCP tool surface only, no UI/route changes.

Validation

  • pnpm test:mcp
  • pnpm exec vitest run tests/mcp-server.test.ts tests/mcp-cli.test.ts tests/mcp-http-route.test.ts
  • pnpm validate:packages
  • git diff --check

@Khaostica Khaostica requested a review from JSONbored as a code owner May 26, 2026 21:45
@superagent-security superagent-security Bot added the contributor:verified Contributor passed trust analysis. label May 26, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Review Change Stack

Warning

Review limit reached

@Khaostica, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 8 minutes and 45 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: ee590563-1726-452d-9559-ba42ddd00eac

📥 Commits

Reviewing files that changed from the base of the PR and between c97b80b and 320e6ff.

📒 Files selected for processing (7)
  • packages/mcp/README.md
  • packages/mcp/src/registry.d.ts
  • packages/mcp/src/registry.js
  • packages/mcp/src/schemas.d.ts
  • packages/mcp/src/schemas.js
  • tests/mcp-http-route.test.ts
  • tests/mcp-server.test.ts
📝 Walkthrough

Walkthrough

Adds a new read-only MCP tool plan_workflow_toolbox that accepts a workflow goal and optional filters (category, platform, limit, diversity flag), loads the registry search index, scores and ranks candidates using token and metadata signals, and returns a bounded recommendation list with per-entry reason codes, caveats, next-step pointers, and guidance.

Changes

Workflow Toolbox Planner Tool

Layer / File(s) Summary
Input Schema Contract
packages/mcp/src/schemas.d.ts, packages/mcp/src/schemas.js
New PlanWorkflowToolboxInputSchema validates required goal and optional category, platform, limit, preferDiverseCategories, and is registered in TOOL_INPUT_SCHEMAS.
Tokenization & Stopwords
packages/mcp/src/registry.js
Goal tokenization helpers with stopword filtering produce tokens used for matching and scoring.
Haystack, Scoring & Enrichment
packages/mcp/src/registry.js
Builds per-entry haystacks, counts token matches, generates nextSteps pointers and per-entry caveats from metadata, and computes reason codes and scores.
Core Planner & Selection
packages/mcp/src/registry.js
planWorkflowToolbox loads search-index.json, filters by category/platform, ranks candidates with tie-breakers, optionally enforces category diversity, and returns enriched recommendations plus guidance/notes for empty/weak matches.
Tool Registration and Dispatch
packages/mcp/src/registry.js
Adds plan_workflow_toolbox to READ_ONLY_TOOL_NAMES, includes tool entry in TOOL_DEFINITIONS wired with input schema, and dispatches the tool via callRegistryTool.
Type Definitions and Public API
packages/mcp/src/registry.d.ts
Exports planWorkflowToolbox(args?, options?) returning Promise<RegistryToolResult> and re-exports PlanWorkflowToolboxInputSchema.
Documentation and Test Coverage
packages/mcp/README.md, tests/mcp-http-route.test.ts, tests/mcp-server.test.ts
README documents metadata-only toolbox behavior; HTTP route test list updated; protocol test args and three tests added for bounded results, filtered responses, and no-match guidance.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant planWorkflowToolbox
    participant SearchIndex
    participant Scorer

    Client->>planWorkflowToolbox: goal, category?, platform?, limit?
    planWorkflowToolbox->>planWorkflowToolbox: Tokenize goal (stopword filter)
    planWorkflowToolbox->>SearchIndex: Load search-index.json
    SearchIndex-->>planWorkflowToolbox: entry catalog
    planWorkflowToolbox->>Scorer: Filter catalog by category/platform
    Scorer->>Scorer: Score entries (token match + category + platform + trust)
    Scorer->>Scorer: Apply category diversity if requested
    Scorer-->>planWorkflowToolbox: Ranked candidates
    planWorkflowToolbox->>planWorkflowToolbox: Generate reasons, caveats, nextSteps
    planWorkflowToolbox-->>Client: {entries, reasons, guidance, notes, count}
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

Suggested labels

feature

Suggested reviewers

  • JSONbored

Poem

A planner reads your goal and sifts the index fine,
Scores entries by tokens, trust, and platform line.
It returns a small toolbox — reasons, caveats, next-step cue,
No installs, no guessing, just metadata true. ✨


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Docstring Coverage ❌ Error Docstring coverage is 0.00% which is insufficient. The required threshold is 90.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (7 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding a workflow toolbox planner feature to the MCP tool suite.
Description check ✅ Passed The PR description is comprehensive, covering summary, what changed, why it matters, invariants, backward compatibility, and validation steps. However, it does not follow the provided template structure for this repository.
Linked Issues check ✅ Passed The PR fully implements all acceptance criteria from issue #491: bounded deterministic toolbox, reason codes, trust metadata, guidance for weak matches, and comprehensive protocol/unit tests.
Out of Scope Changes check ✅ Passed All changes are directly scoped to the plan_workflow_toolbox feature. No extraneous modifications to unrelated areas or unexpected file changes detected.
Security Pattern Review ✅ Passed Input validation enforced via Zod schemas pre-execution, all data metadata-derived only (no external calls/PII), no eval/injection risks, read-only tool properly annotated with security policy.
Client/Server Boundary Validation ✅ Passed No client/server boundary violations detected. MCP package is purely server-side with no 'use client' directives and proper API route patterns.
Logging Standards Compliance ✅ Passed PR changes are in packages/mcp/ and tests/ directories; custom check only applies to apps/web/src/ and packages/web-runtime/src/, which are not modified here.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@superagent-security superagent-security Bot added the pr:verified PR passed security analysis. label May 26, 2026
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Inline comments:
In `@packages/mcp/src/registry.js`:
- Line 1955: The runtime path of planWorkflowToolbox currently calls
normalizeLimit(args.limit, 5) which allows up to 25 via normalizeLimit; update
the runtime to enforce the intended 1–10 bound by clamping the computed limit to
10 (e.g. call normalizeLimit with a max of 10 or apply
Math.min(normalizeLimit(...), 10)) so that planWorkflowToolbox cannot be invoked
with >10 even when called directly; reference normalizeLimit and
planWorkflowToolbox when making the change.
- Around line 1891-1893: The current token-length check increments score
(tokens.length === 0 -> score += 1), which improperly rewards candidates with
empty/weak tokenization; remove that increment and instead skip token-based
scoring when tokens.length === 0 so the algorithm falls back to guidance-only
evaluation. Locate the tokenization branch that references tokens and score in
the scoring loop (the tokens.length === 0 check) and change it to not modify
score (no score += 1) and ensure control flows to the guidance-only path (i.e.,
do not treat empty tokens as a positive match).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 011f2cba-398e-43d5-a2b3-a32f2d7ca0b7

📥 Commits

Reviewing files that changed from the base of the PR and between e4371ce and c5baae0.

📒 Files selected for processing (7)
  • packages/mcp/README.md
  • packages/mcp/src/registry.d.ts
  • packages/mcp/src/registry.js
  • packages/mcp/src/schemas.d.ts
  • packages/mcp/src/schemas.js
  • tests/mcp-http-route.test.ts
  • tests/mcp-server.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: pipelock-advisory-scan
🧰 Additional context used
📓 Path-based instructions (1)
packages/mcp/**/*

📄 CodeRabbit inference engine (AGENTS.md)

MCP package behavior must live under packages/mcp/

Files:

  • packages/mcp/README.md
  • packages/mcp/src/schemas.d.ts
  • packages/mcp/src/schemas.js
  • packages/mcp/src/registry.js
  • packages/mcp/src/registry.d.ts
🔇 Additional comments (7)
packages/mcp/src/schemas.d.ts (1)

29-29: LGTM!

packages/mcp/src/schemas.js (1)

285-293: LGTM!

Also applies to: 321-321

packages/mcp/src/registry.js (1)

87-87: LGTM!

Also applies to: 248-253, 2150-2152

packages/mcp/src/registry.d.ts (1)

168-171: LGTM!

Also applies to: 206-206

packages/mcp/README.md (1)

82-85: LGTM!

tests/mcp-http-route.test.ts (1)

111-111: LGTM!

tests/mcp-server.test.ts (1)

132-135: LGTM!

Also applies to: 860-974

Comment thread packages/mcp/src/registry.js Outdated
Comment thread packages/mcp/src/registry.js Outdated
@Khaostica Khaostica force-pushed the claude/sweet-yalow-a3e2b7 branch from c5baae0 to 9e4f9c4 Compare May 26, 2026 21:56
@Khaostica Khaostica force-pushed the claude/sweet-yalow-a3e2b7 branch 2 times, most recently from 6ef3a72 to c97b80b Compare May 27, 2026 20:14
@superagent-security superagent-security Bot removed contributor:verified Contributor passed trust analysis. pr:verified PR passed security analysis. labels May 27, 2026
@Khaostica Khaostica force-pushed the claude/sweet-yalow-a3e2b7 branch 2 times, most recently from 7d68dcd to 320e6ff Compare May 27, 2026 21:00
Copy link
Copy Markdown
Owner

@JSONbored JSONbored left a comment

Choose a reason for hiding this comment

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

@Khaostica this MCP toolbox planner is close, but one runtime correctness issue should be fixed before merge.

  • The query tokens are lowercased, but the searchable entry haystack is not consistently lowercased.
  • That makes matching case-sensitive for titles/descriptions/brand text and can miss relevant workflow-toolbox results.
  • Normalize the haystack to lowercase before token matching.
  • Add a regression test where a lowercase user goal matches mixed-case title or description text.
  • Expected validation: run the focused MCP workflow-toolbox tests plus the MCP package test lane.
  • Please fix merge conflicts, and ensure CI passes fully.

@Khaostica Khaostica force-pushed the claude/sweet-yalow-a3e2b7 branch from 320e6ff to de0cd41 Compare May 28, 2026 13:15
@Khaostica Khaostica requested a review from JSONbored May 28, 2026 13:25
Copy link
Copy Markdown
Owner

@JSONbored JSONbored left a comment

Choose a reason for hiding this comment

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

Action: request changes

  • The previous maintainer blocker is fixed: the planner haystack is now lowercased, there is a mixed-case regression test, merge conflicts are gone, and the MCP/required checks are green.
  • One still-valid runtime contract issue remains before merge.
  • planWorkflowToolbox() still calls normalizeLimit(args.limit, 6), and normalizeLimit() allows up to 25. The tool contract is a 1-10 planner result bound, so direct runtime calls can exceed the public schema.
  • Please clamp this tool’s runtime limit to 10 and add/update a focused test proving limit > 10 returns at most 10 entries.

@Khaostica Khaostica requested a review from JSONbored May 29, 2026 01:53
@Khaostica Khaostica force-pushed the claude/sweet-yalow-a3e2b7 branch from c6e85ff to b3683ae Compare May 29, 2026 13:59
@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label May 29, 2026
Copy link
Copy Markdown
Owner

@JSONbored JSONbored left a comment

Choose a reason for hiding this comment

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

@Khaostica the MCP planner fixes look close, but this PR needs to stay scoped before merge.

  • Keep this PR focused on plan_workflow_toolbox and MCP tests.
  • Remove the unrelated changes to scripts/resolve-pr-preview-url.mjs and tests/deployment-preview-url.test.ts, or move them to a separate PR with its own explanation.
  • Update the branch against current main so required checks rerun on the current base.
  • Keep the lowercase matching regression and runtime limit <= 10 coverage.
  • Re-run pnpm test:mcp and the focused MCP tests after removing the unrelated files.

Khaostica and others added 2 commits May 30, 2026 15:07
…ching

The workflow-toolbox planner lowercases query tokens but matched them
against entrySearchText, whose case-insensitivity was only implicit via
normalizeText. Make the guarantee explicit by lowercasing the joined
haystack so token matching cannot silently regress to case-sensitive and
miss relevant mixed-case titles, descriptions, or brand text.

Adds a regression test where a lowercase planner goal matches mixed-case
entry title ("CLUSTER") and description ("ROLLOUTS") text.

Validation: pnpm test:mcp (54 passed).
planWorkflowToolbox() called normalizeLimit(args.limit, 6), which allows
up to 25, so direct runtime calls could exceed the 1-10 planner result
bound enforced by the public input schema. Clamp the runtime limit to 10
and add a focused test proving limit > 10 returns at most 10 entries.
@Khaostica Khaostica force-pushed the claude/sweet-yalow-a3e2b7 branch from 01559eb to 1b76aeb Compare May 30, 2026 19:08
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels May 30, 2026
@Khaostica Khaostica requested a review from JSONbored May 30, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(mcp): add workflow toolbox planner

2 participants