Skip to content

[#636] Build MCP action catalog and search/describe/call gateway - #669

Merged
DVidal1205 merged 1 commit into
mainfrom
api/mcp-action-catalog
Nov 14, 2026
Merged

DVidal1205 merged 1 commit into
mainfrom
api/mcp-action-catalog

Conversation

@azizu06

@azizu06 azizu06 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Why

#641 needs a way to list, describe and run MCP actions for a signed-in member without skipping the checks Blade already runs.

What

Closes: #636
Part of #634

Based on main after #667 merged.

searchActions(session, query)
  load permissions fresh
  keep catalog entries where evaluateAccess passes
  rank by path and description match         // empty query returns every allowed action
describeAction(session, path)
  description + input JSON schema | FORBIDDEN | NOT_FOUND
callAction(session, path, input)
  appRouter.createCaller(ctx)[path](input)    // validation, permProcedure, resource checks, audit
  onToolCall(outcome)                          // hook for #637's writer

Follow-ups:

Test Plan

  • packages/api/src/tests/mcp/ covers search filtering and ranking, describe on an allowed and a forbidden action, a call denied by a resource check, a permission change applying on the very next call, and hook outcomes
  • A coverage test walks the router and fails if any meta.mcp procedure is missing from the catalog
  • pnpm format, pnpm lint, pnpm typecheck, pnpm --filter=@forge/api build and pnpm --filter=@forge/api test pass, 1172 tests
  • p50 over 100 warm runs with the permission lookup mocked: search 0.017 ms, call 0.052 ms

Merge Danger

Door: two-way. New exports only, nothing calls them yet.

Blast Radius: none until #641 wires the gateway into the MCP endpoint.

Checklist

  • Database: No schema changes, OR I ran pnpm db:generate and committed the generated files in packages/db/drizzle/
  • Environment Variables: No environment variables changed, OR I have contacted the Development Lead to modify them on Coolify BEFORE merging.

@azizu06 azizu06 added Feature New Feature or Request Major Big change - 2+ reviewers required API Change modifies code in the global API/tRPC package labels Nov 13, 2026
@azizu06 azizu06 self-assigned this Nov 13, 2026
Base automatically changed from api/mcp-action-permissions to main November 14, 2026 02:50
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 28 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d9723c9 and b72e390.

Files selected for processing: 6

  • packages/api/src/index.ts
  • packages/api/src/tests/mcp/catalog-coverage.test.ts
  • packages/api/src/tests/mcp/catalog.test.ts
  • packages/api/src/tests/mcp/gateway.test.ts
  • packages/api/src/utils/mcp/catalog.ts
  • packages/api/src/utils/mcp/gateway.ts
Walkthrough

The API package adds MCP access metadata and permission checks for opted-in procedures. It builds a cached action catalog with input schemas derived from Zod validators. The gateway adds authenticated action search, description, and calls. Analytics procedures declare read-access metadata, and the package entry point exports the catalog and gateway APIs. Tests cover access evaluation, catalog construction, gateway behavior, and analytics permission parity.

Merge Risk: Low · previous review d9723

This adds a catalog and gateway for MCP actions with no live callers yet, so production exposure is minimal. One edge case remains: actions with several chained input validators that use registered schema ids could emit input schemas with unresolvable references. Fix it before the follow-up endpoint work relies on those schemas.

Pre-merge checks: Passed 7

Check name Status Explanation
Title check Passed Title starts with issue number in brackets, is 64 characters (under 72), and describes the main change: building the MCP action catalog and the search/describe/call gateway, which matches the changese…
Linked Issues check Passed [#636] Requirements and evidence:
- Catalog walks procedures with meta.mcp, validates, dedupes, and memoizes (utils/mcp/catalog.ts, buildActionCatalog, getActionCatalog). Covered by `tests/mcp…
Out of Scope Changes check Passed [#636] Changes outside the gateway files:
- trpc.ts: permProcedure enforces meta.mcp.access for procedures that declare it. This is needed for the catalog access model.
- routers/analytics.ts …
Description check Passed The description explains the purpose (MCP action listing, describing, and calling for a signed-in member), the new gateway functions, catalog memoization, per-call permission reads, follow-up issues, …
No Hardcoded Secrets Passed I diffed the PR head against origin/main (the #667 base) and scanned the added lines. The PR changes six files: index.ts, catalog.ts, gateway.ts, and three test files under packages/api/src/tests/mcp/…
Validated Env Access Passed No process.env access was added in the PR's changed source files. The MCP sources (utils/mcp/access.ts, catalog.ts, gateway.ts), the MCP tests (tests/mcp/*), routers/analytics.ts, `trpc.ts…
No Typescript Escape Hatches Passed PR #669 (KnightHacks/forge, author azizu06) adds no TypeScript escape hatches. I diffed the PR head against local main (6 files, +798 lines). Findings: - any type: no added line uses the TypeScrip…
Full details: Title check

Explanation

Title starts with issue number in brackets, is 64 characters (under 72), and describes the main change: building the MCP action catalog and the search/describe/call gateway, which matches the changeset.

Full details: Linked Issues check

Explanation

[#636] Requirements and evidence:

  • Catalog walks procedures with meta.mcp, validates, dedupes, and memoizes (utils/mcp/catalog.ts, buildActionCatalog, getActionCatalog). Covered by tests/mcp/catalog.test.ts.
  • Input schemas come from existing Zod validators via z.toJSONSchema. Covered by catalog.test.ts.
  • searchActions returns only accessible actions and supports filtering and ranking. Covered by tests/mcp/gateway.test.ts.
  • describeAction returns description and schema for allowed actions and rejects disallowed ones. Covered by gateway.test.ts.
  • callAction runs the real procedure through a server-side caller. A resource-check denial after an action-level pass is covered by gateway.test.ts and perm-procedure.test.ts.
  • Permissions are read per call. A permission change applies to the next call (gateway.test.ts).
  • Router coverage: catalog-coverage.test.ts and parity.test.ts check that opted-in procedures appear in the catalog.

Test files were assessed from the change summary. Test contents were not inspected directly.

Full details: Out of Scope Changes check

Explanation

[#636] Changes outside the gateway files:

  • trpc.ts: permProcedure enforces meta.mcp.access for procedures that declare it. This is needed for the catalog access model.
  • routers/analytics.ts and utils/analytics/access.ts: analytics procedures declare meta.mcp using new clubAnalyticsReadAccess and hackathonAnalyticsReadAccess rules. The require*AnalyticsRead guards are removed from some handlers. The parity.test.ts tests compare these procedures with the former resolver checks. These changes support the MCP access declarations.
  • utils/forms/callbacks.ts: adds ForgeTRPCMeta.mcp. Needed for the metadata.
  • index.ts: re-exports only.

Note: the PR description says blast radius is none. The trpc.ts change applies to existing meta.mcp procedures on the normal tRPC path now. Parity tests cover equivalence but were not run here.

Full details: Description check

Explanation

The description explains the purpose (MCP action listing, describing, and calling for a signed-in member), the new gateway functions, catalog memoization, per-call permission reads, follow-up issues, test coverage, and the new exports. It is directly related to the changeset.

Full details: No Hardcoded Secrets

Explanation

I diffed the PR head against origin/main (the #667 base) and scanned the added lines. The PR changes six files: index.ts, catalog.ts, gateway.ts, and three test files under packages/api/src/tests/mcp/. The scan found no API-key formats (sk-, ghp_, xox, AKIA), no PEM blocks, no credentialed connection strings, no long high-entropy quoted literals, and no password or secret assignments. The only hits were two test-fixture session objects: token: "fixture" in catalog-coverage.test.ts and token: "fixture-token" in gateway.test.ts. These are placeholder values in a mocked Session object. They do not look like credentials and do not match any provider token format. The check targets real hardcoded credentials, so these do not trigger the failure condition. Note that a strictly literal reading of "tokens as string literals" would flag them. I judged that reading against the check's intent and examples.

Full details: Validated Env Access

Explanation

No process.env access was added in the PR's changed source files. The MCP sources (utils/mcp/access.ts, catalog.ts, gateway.ts), the MCP tests (tests/mcp/*), routers/analytics.ts, trpc.ts, utils/analytics/access.ts, utils/forms/callbacks.ts, and index.ts contain no process.env references. A repository-wide search of packages/api/src, excluding env.ts and tests, finds one match: utils/career/globe-cities.ts:148. That file is not in the PR's summarized change list. The PR is a single squashed commit (8ede2e6) with no usable parent, so the base diff could not be confirmed. The globe-cities.ts line is therefore treated as pre-existing. Other process.env hits are in env.ts (allowed) and in integration/unit test files (DATABASE_URL, BLADE_E2E_AUTH). None of those test files is in the PR's listed changes. Config files (vitest.config.ts, drizzle.config.ts) are allowed by the check.

Full details: No Typescript Escape Hatches

Explanation

PR #669 (KnightHacks/forge, author azizu06) adds no TypeScript escape hatches. I diffed the PR head against local main (6 files, +798 lines). Findings: - any type: no added line uses the TypeScript any type. The any matches are string literals for the MCP access mode (mode: "any", z.enum(["any", "all"]), and zod unrepresentable: "any"). - @ts-ignore, @ts-expect-error, @ts-nocheck: none found. - Non-null assertions (x!, x!., x![, x!)): none found. The only ! hits are !==/!= comparisons. The PR does add as type assertions (for example router._def.procedures as Record<string, AnyProcedure> in catalog.ts and as ForgeTRPCMeta | undefined in gateway.ts and catalog.ts). The check does not list type assertions as a failure condition, so they do not affect this verdict. Note: the raw summary lists changes to analytics.ts, trpc.ts, and utils/mcp/access.ts. Those files do not differ from local main, so they are likely in the base from PR #667. This check reviewed only the diff that is present.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

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

Note

Quiet mode is enabled, so only the most important comments were posted inline. Other review comments are grouped below.

Other comments: 1

packages/api/src/utils/mcp/catalog.ts: 1

86-86: Minor · Data Integrity & Integration · Quick win

Preserve $ref targets when combining input schemas.

For chained .input() validators, a nested z.string().meta({ id: "Slug" }) produces #/$defs/Slug. Wrapping the converted schema in allOf moves its $defs below allOf/0, but the reference still targets the document root. Schema consumers cannot resolve that reference. (raw.githubusercontent.com)

Combine the Zod validators before JSON Schema conversion so references use the final document root.

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b4fe071 and d9723c9.

Files selected for processing: 14

  • packages/api/src/index.ts
  • packages/api/src/routers/analytics.ts
  • packages/api/src/tests/mcp/access.test.ts
  • packages/api/src/tests/mcp/catalog-coverage.test.ts
  • packages/api/src/tests/mcp/catalog.test.ts
  • packages/api/src/tests/mcp/gateway.test.ts
  • packages/api/src/tests/mcp/parity.test.ts
  • packages/api/src/tests/mcp/perm-procedure.test.ts
  • packages/api/src/trpc.ts
  • packages/api/src/utils/analytics/access.ts
  • packages/api/src/utils/forms/callbacks.ts
  • packages/api/src/utils/mcp/access.ts
  • packages/api/src/utils/mcp/catalog.ts
  • packages/api/src/utils/mcp/gateway.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@DVidal1205
DVidal1205 force-pushed the api/mcp-action-catalog branch from d9723c9 to 8ede2e6 Compare November 14, 2026 02:57
@DVidal1205
DVidal1205 force-pushed the api/mcp-action-catalog branch from 8ede2e6 to b72e390 Compare November 14, 2026 03:22
@DVidal1205
DVidal1205 added this pull request to the merge queue Nov 14, 2026
Merged via the queue into main with commit 98f3f9d Nov 14, 2026
14 checks passed
@DVidal1205
DVidal1205 deleted the api/mcp-action-catalog branch November 14, 2026 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API Change modifies code in the global API/tRPC package Feature New Feature or Request Major Big change - 2+ reviewers required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[SPRINT-04] MCP: build the action catalog and the search, describe, and call gateway in @forge/api

2 participants