Skip to content

feat(mcp): let agents select activity-log response fields - #70340

Merged
yasen-posthog merged 9 commits into
masterfrom
feat/mcp-selectable-response-fields
Jul 14, 2026
Merged

feat(mcp): let agents select activity-log response fields#70340
yasen-posthog merged 9 commits into
masterfrom
feat/mcp-selectable-response-fields

Conversation

@yasen-posthog

Copy link
Copy Markdown
Contributor

Problem

The advanced-activity-logs-list MCP tool always returns every allowlisted field, including the full detail.changes diffs. For questions like "who changed feature flags this week" that payload is large enough to overwhelm the model.

Changes

  • Add a response.selectable flag to the MCP tool codegen that exposes an optional fields param, letting an agent request only the fields it needs
  • Constrain fields to the tool's include allowlist via a generated enum, so callers can narrow but not widen the response; omitting it returns the full set as before
  • Enable it on advanced-activity-logs-list and nudge the tool description toward minimal field sets
  • Document the flag in the MCP tools handbook and skill

How did you test this code?

  • 3 unit tests added covering the narrowed payload, the full-allowlist fallback, and schema-level allowlist enforcement
  • Regenerated tool definitions from a fresh OpenAPI spec; full mcp unit suite (2057) passes
  • Agent-authored; only the automated tests above were run.

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

🤖 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 with response.include can opt in via selectable: true — but only advanced-activity-logs-list is enabled here since that's the tool driving oversized responses. Considered a free-form fields string list but chose a generated z.enum over the allowlist so the model can only pick valid, exposed fields (no widening past what the tool already returns).

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.
@yasen-posthog yasen-posthog self-assigned this Jul 13, 2026
@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

🤖 CI report

Bundle size — no change

Uncompressed size of every built .js bundle, compared against the base branch.

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 budget

How 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 import() / React.lazy chunks are not counted.

Root Eager (shipped) Δ vs base Budget
entry (logged-out pages, app bootstrap)
src/index.tsx
1.21 MiB · 22 files no change ███░░░░░░░ 28.1% of 4.29 MiB
authenticated shell (every logged-in page)
src/scenes/AuthenticatedShell.tsx
8.10 MiB · 2,972 files no change █████████░ 87.5% of 9.25 MiB

🟢 node_modules/monaco-editor/ stays out of src/index.tsx
🟢 src/lib/components/ActivityLog/describers stays out of src/index.tsx
🟢 [object Object] stays out of src/index.tsx
🟢 [object Object] stays out of src/index.tsx
🟢 node_modules/monaco-editor/ stays out of src/scenes/AuthenticatedShell.tsx
🟢 src/lib/components/ActivityLog/describers stays out of src/scenes/AuthenticatedShell.tsx
🟢 [object Object] stays out of src/scenes/AuthenticatedShell.tsx
🟢 [object Object] stays out of src/scenes/AuthenticatedShell.tsx

Largest files eagerly shipped from src/index.tsx
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

@yasen-posthog
yasen-posthog marked this pull request as ready for review July 13, 2026 08:55
@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested a review from a team July 13, 2026 08:55
@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "chore: update OpenAPI generated types" | Re-trigger Greptile

Comment thread services/mcp/scripts/yaml-config-schema.ts
@yasen-posthog yasen-posthog added the stamphog Request AI approval (no full review) label Jul 13, 2026
@stamphog

stamphog Bot commented Jul 13, 2026

Copy link
Copy Markdown

Note

🤖 stamphog reviewed 5609deddff644ceba2349037db774d415d82b3bf — verdict: REFUSED

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.

  • Author wrote 14% of the modified lines and has 12 merged PRs in these paths (familiarity MODERATE).
  • greptile-apps[bot] reviewed the current head.
  • Greptile's inline comment on services/mcp/scripts/yaml-config-schema.ts (P2, unresolved) is accurate: selectable is silently ignored for tools using a custom input_schema, a reachable config combination the zod schema doesn't reject.
  • This is shared MCP codegen infrastructure other teams will configure going forward, so the silent no-op is a footgun beyond the one tool enabled in this PR.
Gate mechanics and policy version
Gate Result
prerequisites all clear
deny-list no deny categories matched
size 57L, 5F substantive, 212L/10F incl. docs/generated/snapshots — within ceiling
tier T1-agent / T1d-complex (212L, 10F, cross-cutting, feat)
stamphog 2.0.0b3 .stamphog/policy.yml @ 641dd5a · reviewed head 5609ded

⚠️ A later review run failed before producing a verdict — check the workflow run. The verdict above is from an earlier run.

@stamphog stamphog Bot removed the stamphog Request AI approval (no full review) label Jul 13, 2026
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
@trunk-io

trunk-io Bot commented Jul 13, 2026

Copy link
Copy Markdown

Static BadgeStatic BadgeStatic BadgeStatic Badge

View Full Report ↗︎Docs

@yasen-posthog yasen-posthog added the stamphog Request AI approval (no full review) label Jul 13, 2026
stamphog[bot]
stamphog Bot previously approved these changes Jul 13, 2026

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

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

github-actions[bot]
github-actions Bot previously approved these changes Jul 13, 2026
Generated-By: PostHog Code
Task-Id: a1e83dc0-4d16-49a7-902e-95e18a1fe735
Comment thread services/mcp/scripts/generate-tools.ts
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
@github-actions
github-actions Bot dismissed stale reviews from stamphog[bot] and themself July 13, 2026 12:16

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
stamphog[bot]
stamphog Bot previously approved these changes Jul 13, 2026

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

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

github-actions[bot]
github-actions Bot previously approved these changes Jul 13, 2026
@yasen-posthog
yasen-posthog requested a review from a team July 13, 2026 13:00

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

Great addition

Comment thread services/mcp/scripts/generate-tools.ts
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
@github-actions

Copy link
Copy Markdown
Contributor

Docs from this PR will be published at posthog.com

Project Deployment Preview Updated (UTC)
posthog.com 🤷 Unknown Preview Jul 13, 2026, 2:08 PM

Preview will be ready in ~10 minutes. Click Preview link above to access docs at /handbook/engineering/

@stamphog
stamphog Bot dismissed stale reviews from github-actions[bot] and themself July 13, 2026 14:08

New commits pushed (delta classified non_trivial_delta) — stamphog approval dismissed; re-review running automatically.

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

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

@yasen-posthog
yasen-posthog merged commit 1d13637 into master Jul 14, 2026
190 of 191 checks passed
@yasen-posthog
yasen-posthog deleted the feat/mcp-selectable-response-fields branch July 14, 2026 07:50
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 14, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-14 08:20 UTC Run
prod-us ✅ Deployed 2026-07-14 08:35 UTC Run
prod-eu ✅ Deployed 2026-07-14 08:37 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stamphog Request AI approval (no full review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants