feat(mcp): let agents select activity-log response fields - #70340
Conversation
Add a response.selectable YAML flag to the MCP tool codegen. When set, the generated tool exposes an optional fields param constrained to the response.include allowlist, so an agent can request only the fields its task needs. Omitting fields returns the full allowlist as before. Enable it on advanced-activity-logs-list, whose detail.changes diffs make default responses large enough to overwhelm the model.
🤖 CI report✅ Bundle size — no changeUncompressed size of every built Total: 64.33 MiB · no change No file changed by more than 1000 B. Posted automatically by build-bundle-size-report · uncompressed bytes from dist-report ✅ Eager graph — within budgetHow much code each root ships on the eager path — downloaded and parsed before the surface is interactive. Measured from the esbuild output chunks (post-tree-shake, static imports only); lazy
🟢 Largest files eagerly shipped from
|
| Size | File |
|---|---|
| 126.8 KiB | ../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom.production.min.js |
| 24.6 KiB | ../node_modules/.pnpm/buffer@6.0.3/node_modules/buffer/index.js |
| 6.3 KiB | ../node_modules/.pnpm/react@18.3.1/node_modules/react/cjs/react.production.min.js |
| 4.5 KiB | ../node_modules/.pnpm/@jspm+core@2.1.0/node_modules/@jspm/core/nodelibs/browser/process.js |
| 3.9 KiB | ../node_modules/.pnpm/scheduler@0.23.2/node_modules/scheduler/cjs/scheduler.production.min.js |
| 1.4 KiB | ../node_modules/.pnpm/base64-js@1.5.1/node_modules/base64-js/index.js |
| 1.3 KiB | src/RootErrorBoundary.tsx |
| 912 B | ../node_modules/.pnpm/ieee754@1.2.1/node_modules/ieee754/index.js |
| 789 B | src/scenes/ChunkLoadErrorBoundary.tsx |
| 668 B | src/index.tsx |
Largest files eagerly shipped from src/scenes/AuthenticatedShell.tsx
| Size | File |
|---|---|
| 278.6 KiB | ../node_modules/.pnpm/posthog-js@1.399.2/node_modules/posthog-js/dist/rrweb.js |
| 266.9 KiB | ../node_modules/.pnpm/@posthog+icons@0.37.4_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@posthog/icons/dist/posthog-icons.es.js |
| 234.9 KiB | src/taxonomy/core-filter-definitions-by-group.json |
| 221.5 KiB | ../node_modules/.pnpm/posthog-js@1.399.2/node_modules/posthog-js/dist/module.js |
| 164.0 KiB | src/queries/validators.js |
| 154.3 KiB | ../node_modules/.pnpm/re2js@0.4.1/node_modules/re2js/build/index.esm.js |
| 126.8 KiB | ../node_modules/.pnpm/react-dom@18.3.1_react@18.3.1/node_modules/react-dom/cjs/react-dom.production.min.js |
| 105.9 KiB | src/lib/api.ts |
| 93.3 KiB | ../node_modules/.pnpm/prosemirror-view@1.40.1/node_modules/prosemirror-view/dist/index.js |
| 90.6 KiB | ../node_modules/.pnpm/@tiptap+core@3.20.6_@tiptap+pm@3.20.6/node_modules/@tiptap/core/dist/index.js |
Posted automatically by check-eager-graph · sizes are eager output bytes (shipped, post-tree-shake) from the esbuild metafile · part of #32479
✅ Dist folder size — no change
Total size of the built frontend/dist folder (all assets), compared against the base branch.
Total: 1280.22 MiB · no change
ℹ️ MCP UI apps size — 31 app(s), 16373.4 KB JS
Built size of each MCP UI app (main.js + styles.css).
| App | JS | CSS |
|---|---|---|
| debug | 598.2 KB | 179.2 KB |
| action | 456.5 KB | 179.2 KB |
| action-list | 563.0 KB | 179.2 KB |
| cohort | 455.4 KB | 179.2 KB |
| cohort-list | 562.0 KB | 179.2 KB |
| email-template | 455.3 KB | 179.2 KB |
| error-details | 471.1 KB | 179.2 KB |
| error-issue | 456.1 KB | 179.2 KB |
| error-issue-list | 562.9 KB | 179.2 KB |
| experiment | 560.1 KB | 179.2 KB |
| experiment-list | 563.8 KB | 179.2 KB |
| experiment-results | 561.8 KB | 179.2 KB |
| feature-flag | 565.8 KB | 179.2 KB |
| feature-flag-list | 569.5 KB | 179.2 KB |
| feature-flag-testing | 459.4 KB | 179.2 KB |
| insight-actors | 560.8 KB | 179.2 KB |
| invite-email-preview | 454.7 KB | 179.2 KB |
| llm-costs | 558.1 KB | 179.2 KB |
| session-recording | 457.2 KB | 179.2 KB |
| session-summary | 462.5 KB | 179.2 KB |
| survey | 457.0 KB | 179.2 KB |
| survey-global-stats | 560.9 KB | 179.2 KB |
| survey-list | 563.7 KB | 179.2 KB |
| survey-stats | 560.8 KB | 179.2 KB |
| trace-span | 455.8 KB | 179.2 KB |
| trace-span-list | 562.9 KB | 179.2 KB |
| workflow | 455.8 KB | 179.2 KB |
| workflow-list | 562.4 KB | 179.2 KB |
| query-results | 743.6 KB | 179.2 KB |
| render-ui | 636.0 KB | 179.2 KB |
| visual-review-snapshots | 460.3 KB | 179.2 KB |
|
Reviews (1): Last reviewed commit: "chore: update OpenAPI generated types" | Re-trigger Greptile |
|
Note 🤖 stamphog reviewed Verified Greptile's unresolved inline concern is real: generateToolCode() early-returns to generateCustomSchemaToolCode() whenever config.input_schema is set (line 955-957), before buildSelectableFieldsExtension is ever invoked, so a tool that combines input_schema with response.selectable passes schema validation but silently gets no fields param — contradicting the PR's own claim that the codegen change is generic for any response.include tool.
Gate mechanics and policy version
|
The custom-schema codegen path (input_schema) emitted the response filter that reads params.fields but never added the fields param to the schema, so a tool combining input_schema with response.selectable would reference an undeclared param. Apply buildSelectableFieldsExtension in generateCustomSchemaToolCode too, mirroring the Orval-schema path. Generated-By: PostHog Code Task-Id: e255060a-5ea9-40e8-84bf-97412dd1af49
Generated-By: PostHog Code Task-Id: e255060a-5ea9-40e8-84bf-97412dd1af49
There was a problem hiding this comment.
Additive, backward-compatible MCP tool schema change (opt-in fields narrowing, allowlist-constrained, omitting it preserves prior behavior); Greptile flagged a real gap in the custom-schema codegen path and the fix plus a dedicated regression test are present in this diff, with the thread resolved and no other unresolved concerns.
- Author wrote 14% of the modified lines and has 12 merged PRs in these paths (familiarity MODERATE).
- 👍 on the PR from greptile-apps[bot], hex-security-app[bot].
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 63L, 5F substantive, 245L/11F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (245L, 11F, cross-cutting, feat) |
| stamphog 2.0.0b3 | .stamphog/policy.yml @ b75cbd5 · reviewed head ca5fcd3 |
Generated-By: PostHog Code Task-Id: a1e83dc0-4d16-49a7-902e-95e18a1fe735
An empty `fields: []` array previously fell through to the full allowlist because `[].length` is falsy. Add `.min(1)` to the generated Zod schema so an empty array is rejected at validation rather than silently returning the full payload the feature exists to avoid. Generated-By: PostHog Code Task-Id: 6f8cd86d-0181-48ec-80d9-0ae92a2b48d3
New commits pushed (delta classified non_trivial_delta) — stamphog approval dismissed; re-review running automatically.
Regenerate the advanced-activity-logs-list tool-schema snapshot to include `minItems: 1` on the `fields` array after adding the `.min(1)` validation. Generated-By: PostHog Code Task-Id: 6f8cd86d-0181-48ec-80d9-0ae92a2b48d3
Generated-By: PostHog Code Task-Id: 6f8cd86d-0181-48ec-80d9-0ae92a2b48d3
There was a problem hiding this comment.
Additive, backward-compatible MCP tool change (new optional fields param constrained to the existing allowlist, can only narrow never widen); the two edge cases agent reviewers (Greptile, Graphite) raised were fixed with dedicated tests and marked resolved, with Greptile reacting 👍 to the fix — that's independent assurance over the public-API-surface part of this change.
- Author wrote 14% of the modified lines and has 12 merged PRs in these paths (familiarity MODERATE).
- 👍 on the PR from greptile-apps[bot], hex-security-app[bot].
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 64L, 5F substantive, 252L/11F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (252L, 11F, cross-cutting, feat) |
| stamphog 2.0.0b3 | .stamphog/policy.yml @ f41423d · reviewed head 9464dcd |
buildSelectableFieldsExtension silently returned '' when a tool set response.selectable without a response.include allowlist, emitting a tool whose selectable flag did nothing. Throw instead so the misconfiguration surfaces at codegen time. Generated-By: PostHog Code Task-Id: 5ce5aa94-d3b3-4d48-ba6b-fc1ba9d86d31
|
Docs from this PR will be published at posthog.com
Preview will be ready in ~10 minutes. Click Preview link above to access docs at |
New commits pushed (delta classified non_trivial_delta) — stamphog approval dismissed; re-review running automatically.
There was a problem hiding this comment.
Additive, backward-compatible change to one MCP tool's schema (opt-in fields param strictly constrained to the existing allowlist, no data exposure beyond what's already returned); all bot/human reviewer concerns (empty-array fallback, custom-schema gap, missing-allowlist case) were fixed in follow-up commits with matching unit tests, and a human reviewer approved with no unresolved issues.
- Author wrote 14% of the modified lines and has 13 merged PRs in these paths (familiarity MODERATE).
- 👍 on the PR from greptile-apps[bot], hex-security-app[bot].
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 72L, 5F substantive, 285L/11F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1d-complex (285L, 11F, cross-cutting, feat) |
| stamphog 2.0.0b3 | .stamphog/policy.yml @ 13d7039 · reviewed head 8fee008 |
Problem
The
advanced-activity-logs-listMCP tool always returns every allowlisted field, including the fulldetail.changesdiffs. For questions like "who changed feature flags this week" that payload is large enough to overwhelm the model.Changes
response.selectableflag to the MCP tool codegen that exposes an optionalfieldsparam, letting an agent request only the fields it needsfieldsto the tool'sincludeallowlist via a generated enum, so callers can narrow but not widen the response; omitting it returns the full set as beforeadvanced-activity-logs-listand nudge the tool description toward minimal field setsHow did you test this code?
Automatic notifications
🤖 Agent context
Autonomy: Human-driven (agent-assisted)
I (Claude) built this at Yasen's direction. Invoked skills:
/implementing-mcp-tools(to follow the codegen pipeline),/writing-tests(to gate the test), and/creating-pull-requests. The codegen change is generic — any tool withresponse.includecan opt in viaselectable: true— but onlyadvanced-activity-logs-listis enabled here since that's the tool driving oversized responses. Considered a free-formfieldsstring list but chose a generatedz.enumover the allowlist so the model can only pick valid, exposed fields (no widening past what the tool already returns).