Skip to content

[#637] Store MCP activity and expose it through a tRPC router - #668

Merged
DVidal1205 merged 4 commits into
mainfrom
api/mcp-activity-log
Nov 14, 2026
Merged

DVidal1205 merged 4 commits into
mainfrom
api/mcp-activity-log

Conversation

@azizu06

@azizu06 azizu06 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Why

We need a record of every MCP tool call, allowed, denied or failed, that officers can review and members can check for their own account. #643's SQL tools write to it and #644's logs page reads it.

What

Closes: #637
Part of #634

recordMcpActivity(entry)          // called by #636's gateway hook and #643's SQL tools
  keep only the named fields      // no result rows, tokens or raw error text
  strip SQL literals and comments, cap the preview at 4096 chars
  insert one mcp_activity row

mcpActivity.list       IS_OFFICER   all activity, filters, cursor pages
mcpActivity.listMine   signed in    the caller's own activity
  • New mcp_activity table and migration 0066_sad_gorgon.sql. Columns are actor, client id and name, tool, procedure path, SQL preview, target, outcome, error code and created at
  • actorUserId references the user table with ON DELETE SET NULL, so deleting an account keeps its activity rows
  • outcome is limited to allowed, denied and failed by a check constraint
  • Indexes on (actorUserId, createdAt, id) and (createdAt, id) back the newest-first pages
  • Both procedures are added to api-surface.test.ts and the audit coverage list
  • Most of the +16k lines is the generated Drizzle snapshot

Test Plan

  • Each outcome writes exactly one row, and result rows, tokens and SQL literals never reach a row
  • Members only see their own rows, officers see everything, and losing the officer role applies on the next call
  • 8 integration tests migrate a throwaway Postgres database, run against it and drop it afterwards
  • pnpm format, pnpm lint, pnpm typecheck and pnpm --filter=@forge/api test pass, 1173 tests
  • pnpm db:generate and a local pnpm db:migrate ran clean
  • Newest-first page of 50 on 10k rows: listMine 0.0075 ms with the index and 0.28 ms without, list 0.007 ms and 0.56 ms

Merge Danger

Door: two-way for the code. The table only adds to the schema and can stay if the code is rolled back.

Blast Radius: database. The migration has to be applied before anything calls the writer or the router.

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 Database Change modifies code in the DB package API Change modifies code in the global API/tRPC package labels Nov 13, 2026
@azizu06 azizu06 self-assigned this Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Pre-merge checks: Passed 3

Check name Status Explanation
No Hardcoded Secrets Passed The PR diff (main to HEAD, 18 files, about 17.7k added lines) has no hardcoded API keys, passwords, or tokens. A search for credential-shaped literals (://user:pass@, AKIA, sk-…, ghp_…, PE…
Validated Env Access Passed No direct process.env usage was introduced by PR #668 in the files it touches. - The repository has a single root commit and no usable base, so a full PR diff could not be computed. I verified the MCP…
No Typescript Escape Hatches Passed No TypeScript escape hatches were introduced by PR #668 (KnightHacks/forge, author azizu06). The branch HEAD is a single root commit with no merge base against main, so I compared each changed file …
Full details: No Hardcoded Secrets

Explanation

The PR diff (main to HEAD, 18 files, about 17.7k added lines) has no hardcoded API keys, passwords, or tokens. A search for credential-shaped literals (://user:pass@, AKIA, sk-…, ghp_…, PEM headers) found nothing. The keyword hits are test sentinels used to prove that redaction works. Examples are "secret-token-value" in activity.test.ts, "oauth-credential" and "session-credential" in the activity test, and "synthetic-test-session" and "fixture-session-token" in the integration tests. None is a real credential. The integration test reads its database URL from provisionDisposableDatabase and does not embed one. The base could not be compared through a merge-base because the checkout is shallow. The main tree was used instead, which is adequate for this secret scan.

Full details: Validated Env Access

Explanation

No direct process.env usage was introduced by PR #668 in the files it touches. - The repository has a single root commit and no usable base, so a full PR diff could not be computed. I verified the MCP activity files named in the PR by searching for them by name. - Files checked with no process.env hits: packages/api/src/utils/mcp/activity.ts, packages/api/src/routers/mcp-activity.ts, packages/db/src/schemas/mcp-activity.ts, packages/api/src/tests/mcp/activity.test.ts, packages/api/src/tests/mcp/activity.integration.test.ts, packages/api/src/tests/mcp/router.test.ts, and the other mcp test files. - packages/db/src/client.ts reads configuration through the validated import env from "./env" (env.DATABASE_URL). It does not read process.env. - The integration test sets its database URL with vi.stubEnv, not with process.env. - The repository tree has many process.env reads. Most are inside env.ts files, .config. files, or pre-existing test helpers. The PR's named files do not add any of them. These pre-existing hits are not attributed to this PR. Limitation: the base commit is unavailable, so files the PR changed outside the MCP scope were not fully diffed.

Full details: No Typescript Escape Hatches

Explanation

No TypeScript escape hatches were introduced by PR #668 (KnightHacks/forge, author azizu06). The branch HEAD is a single root commit with no merge base against main, so I compared each changed file directly with main. - New files: packages/api/src/routers/mcp-activity.ts, packages/api/src/utils/mcp/activity.ts, packages/db/src/schemas/mcp-activity.ts, the three packages/api/src/tests/mcp/*.test.ts files, and packages/db/drizzle/0066_sad_gorgon.sql. I searched each for any, @ts-ignore, @ts-expect-error, and non-null assertions (x!., x!), x!;, x!,, x! at end of line). The only match was the word "any" in a comment in activity.integration.test.ts (line 79: "before importing any module"). That is prose, not a type. - Modified files: packages/db/src/client.ts, packages/api/src/root.ts, packages/api/src/index.ts, and packages/api/src/tests/root/api-surface.test.ts. The diffs against main add schema imports, a router registration, a re-export, and an API-surface test. None contains a matching construct. The check does not cover as casts, so those were not evaluated as failures.

  • 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

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

lgtm

@DVidal1205
DVidal1205 added this pull request to the merge queue Nov 14, 2026
Merged via the queue into main with commit e3dafe9 Nov 14, 2026
23 of 24 checks passed
@DVidal1205
DVidal1205 deleted the api/mcp-activity-log branch November 14, 2026 03:20
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 Database Change modifies code in the DB 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: store MCP activity and expose it through a tRPC router

3 participants