:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore: generate the OAuth-hidden scopes for the frontend (#110219)
Alex Lider31215e04a1f4
diff --git a/.agents/skills/adding-api-scopes/SKILL.md b/.agents/skills/adding-api-scopes/SKILL.mdindex 01a92eb396d9..1e23fcc46071 100644--- a/.agents/skills/adding-api-scopes/SKILL.md+++ b/.agents/skills/adding-api-scopes/SKILL.md@@ -38,8 +38,8 @@ Then decide two more things, separately from the kind:- A custom `@action` needs `required_scopes`, for example `required_scopes=["<object>:write"]`. Use `:read` if it only reads data, and `:write` if it changes data. Without it, token requests get a 403.- An endpoint set to `scope_object = "INTERNAL"` accepts only logged-in sessions. Change it to the new object to open it to tokens.- Then call each custom action with a personal API key that has only the new scope. No test checks this.-3. **Regenerate.** Run `hogli build:openapi`, which carries the object to the frontend type, and `hogli build:projections`, which updates the MCP OAuth list. **DO NOT EDIT GENERATED FILES BY HAND.**-4. **Show it in the pickers.** In `frontend/src/lib/scopes.tsx`:+3. **Regenerate.** Run `hogli build:openapi`, which carries the object to the frontend type, and `hogli build:projections`, which updates the OAuth lists of the MCP server and the web app. **DO NOT EDIT GENERATED FILES BY HAND.**+4. **Show it in the pickers.** Skip this step for an OAuth-hidden object: no picker shows it, and the tests do not ask for a row or a group. Otherwise, in `frontend/src/lib/scopes.tsx`:- Add a row to `API_SCOPES` with a sentence-case label and plural (`/writing-user-facing-copy`). Disable `write` if no endpoint writes. If the key modal should not offer the object, add a reason to `API_SCOPES_OMITTED_FROM_MODAL` instead.- Add the object to one group in `API_SCOPE_GROUPS`. See "Choose a group".5. **Let MCP tools request it.** For each MCP tool that calls the endpoint, add the scope under `scopes:` in `products/<product>/mcp/tools.yaml`.@@ -52,12 +52,11 @@ The groups make a long list readable, so a person can find a product quickly.- A group is a product area that a person recognizes, such as "Session replay" or "Feature flags, experiments & surveys". It is not a code module or a team.- Put the object in the existing group that a person would look in first.- Add a new group only when it gets two or more objects. A group with one object makes the list longer, not easier to read.-- OAuth-hidden objects go in "Internal tools". The pickers do not show these objects, so a person never sees this group. Do not put a public object there, because it would show under the "Internal tools" label.## If a test fails-- **`frontend/src/lib/scopes.test.ts`, the coverage test:** a grantable object has no picker row and no omission reason. Add a row to `API_SCOPES`, or a reason to `API_SCOPES_OMITTED_FROM_MODAL`. If the object is missing from `APIScopeObject`, run `hogli build:openapi` first.-- **`frontend/src/lib/scopes.test.ts`, the group test:** an object is in no group, or in two groups. Put it in exactly one group of `API_SCOPE_GROUPS`.+- **`frontend/src/lib/scopes.test.ts`, the coverage test:** a grantable object has no picker row and no omission reason. Add a row to `API_SCOPES`, or a reason to `API_SCOPES_OMITTED_FROM_MODAL`. If the object is missing from `APIScopeObject`, run `hogli build:openapi` first. If the object is OAuth-hidden, run `hogli build:projections` instead, so the test learns to skip it.+- **`frontend/src/lib/scopes.test.ts`, the group test:** an object is in no group, or in two groups. Put it in exactly one group of `API_SCOPE_GROUPS`. It also fails when an OAuth-hidden object has a row or a group. Remove them, because no picker shows a hidden object.- **`posthog/test/test_scopes.py`:** an internal, OAuth-hidden or privileged scope leaks into a list it must stay out of, or the project secret API key list in `posthog/scopes.py` differs from the copy in `frontend/src/lib/scopes.tsx`. Fix the set, or make the two lists equal.- **`services/mcp/tests/unit/tool-filtering.test.ts`, the completeness test:** an MCP tool requires a scope that OAuth does not advertise. If the scope is new, run `hogli build:projections`. If it is internal, add it to the test's server-only list. Otherwise fix the scope name in `tools.yaml`.@@ -81,4 +80,4 @@ Use these instead of writing your own list of scopes.- **Frontend type:** `APIScopeObject` from `~/types`.- **Frontend list at runtime:** `Object.values(ScopeObjectEnumApi)`, from `products/access_control/frontend/generated/api.schemas`.- **Frontend labels and groups:** `API_SCOPES`, `API_SCOPE_GROUPS` and `getScopeDescription` from `lib/scopes`.-- **MCP server:** `OAUTH_SCOPES_SUPPORTED` and `OAUTH_SCOPES_HIDDEN` from `services/mcp/src/lib/oauth-scopes.generated.ts`.+- **OAuth lists:** `OAUTH_SCOPES_SUPPORTED` and `OAUTH_SCOPES_HIDDEN`, from `lib/oauthScopes.generated` in the web app and `services/mcp/src/lib/oauth-scopes.generated.ts` in the MCP server. The two files are the same.diff --git a/.github/workflows/ci-python.yml b/.github/workflows/ci-python.ymlindex 39e08f21f4bd..6e8a4906cce6 100644--- a/.github/workflows/ci-python.yml+++ b/.github/workflows/ci-python.yml@@ -135,6 +135,7 @@ jobs:- 'products/tasks/frontend/modelCatalog.generated.ts'- 'packages/agent/packages/agent-contracts/src/model-catalog.generated.ts'- 'services/mcp/src/lib/oauth-scopes.generated.ts'+ - 'frontend/src/lib/oauthScopes.generated.ts'# hogli CLI changes need validation- 'tools/hogli/**'- 'tools/hogli-commands/hogli_commands/**'diff --git a/frontend/src/lib/oauthScopes.generated.ts b/frontend/src/lib/oauthScopes.generated.tsnew file mode 100644index 000000000000..7a29cbf5383a--- /dev/null+++ b/frontend/src/lib/oauthScopes.generated.ts@@ -0,0 +1,255 @@+// AUTO-GENERATED by posthog/scopes_projection.py from posthog/scopes.py.+// Regenerate with `hogli build:projections`. Do not edit.+//+// The OAuth scopes a client can request, from get_oauth_scopes_supported().+// The MCP server publishes this list as `scopes_supported` in its+// protected-resource metadata (RFC 9728). The web app's consent screen+// expands a wildcard grant to the read scopes in this list when the server+// sends no computed list. The OAuth authorization server publishes the same+// list at `/.well-known/oauth-authorization-server`. If the lists differ, a+// spec-compliant client (e.g. Claude Code) fails sign-in with `invalid_scope`.++export const OAUTH_SCOPES_SUPPORTED = [+ 'openid',+ 'profile',+ 'email',+ 'introspection',+ 'action:read',+ 'action:write',+ 'access_control:read',+ 'access_control:write',+ 'account:read',+ 'account:write',+ 'activity_log:read',+ 'activity_log:write',+ 'alert:read',+ 'alert:write',+ 'annotation:read',+ 'annotation:write',+ 'approvals:read',+ 'approvals:write',+ 'autoresearch:read',+ 'autoresearch:write',+ 'batch_export:read',+ 'batch_export:write',+ 'batch_import:read',+ 'batch_import:write',+ 'billing:read',+ 'billing:write',+ 'business_knowledge:read',+ 'business_knowledge:write',+ 'canvas:read',+ 'canvas:write',+ 'cohort:read',+ 'cohort:write',+ 'comment:read',+ 'comment:write',+ 'conversation:read',+ 'conversation:write',+ 'customer_analytics:read',+ 'customer_analytics:write',+ 'customer_task:read',+ 'customer_task:write',+ 'customer_journey:read',+ 'customer_journey:write',+ 'customer_profile_config:read',+ 'customer_profile_config:write',+ 'data_catalog:read',+ 'data_catalog:write',+ 'data_catalog_approval:read',+ 'data_catalog_approval:write',+ 'data_deletion:read',+ 'data_deletion:write',+ 'dashboard:read',+ 'dashboard:write',+ 'event_filter:read',+ 'event_filter:write',+ 'dashboard_template:read',+ 'dashboard_template:write',+ 'dataset:read',+ 'dataset:write',+ 'early_access_feature:read',+ 'early_access_feature:write',+ 'endpoint:read',+ 'endpoint:write',+ 'engineering_analytics:read',+ 'engineering_analytics:write',+ 'error_tracking:read',+ 'error_tracking:write',+ 'evaluation:read',+ 'evaluation:write',+ 'element:read',+ 'element:write',+ 'event_definition:read',+ 'event_definition:write',+ 'experiment:read',+ 'experiment:write',+ 'experiment_holdout:read',+ 'experiment_holdout:write',+ 'experiment_saved_metric:read',+ 'experiment_saved_metric:write',+ 'export:read',+ 'export:write',+ 'external_data_schema:read',+ 'external_data_schema:write',+ 'external_data_source:read',+ 'external_data_source:write',+ 'feature_flag:read',+ 'feature_flag:write',+ 'file_system:read',+ 'file_system:write',+ 'file_system_shortcut:read',+ 'file_system_shortcut:write',+ 'group:read',+ 'group:write',+ 'health_issue:read',+ 'health_issue:write',+ 'heatmap:read',+ 'heatmap:write',+ 'hog_flow:read',+ 'hog_flow:write',+ 'hog_function:read',+ 'hog_function:write',+ 'ingestion_warning:read',+ 'ingestion_warning:write',+ 'insight:read',+ 'insight:write',+ 'insight_variable:read',+ 'insight_variable:write',+ 'integration:read',+ 'integration:write',+ 'legal_document:read',+ 'legal_document:write',+ 'link:read',+ 'link:write',+ 'live_debugger:read',+ 'live_debugger:write',+ 'llm_analytics:read',+ 'llm_analytics:write',+ 'ai_observability_clusters:read',+ 'ai_observability_clusters:write',+ 'llm_playground:read',+ 'llm_playground:write',+ 'llm_prompt:read',+ 'llm_prompt:write',+ 'llm_provider_key:read',+ 'llm_provider_key:write',+ 'llm_skill:read',+ 'llm_skill:write',+ 'logs:read',+ 'logs:write',+ 'loop:read',+ 'loop:write',+ 'marketing_analytics:read',+ 'marketing_analytics:write',+ 'mcp_analytics:read',+ 'mcp_analytics:write',+ 'mcp_registry:read',+ 'mcp_registry:write',+ 'metrics:read',+ 'metrics:write',+ 'notebook:read',+ 'notebook:write',+ 'offline_evaluation_ingestion:read',+ 'offline_evaluation_ingestion:write',+ 'organization:read',+ 'organization:write',+ 'organization_integration:read',+ 'organization_integration:write',+ 'organization_member:read',+ 'organization_member:write',+ 'person:read',+ 'person:write',+ 'plugin:read',+ 'plugin:write',+ 'product_enablement:read',+ 'product_enablement:write',+ 'product_tour:read',+ 'product_tour:write',+ 'project:read',+ 'project:write',+ 'property_definition:read',+ 'property_definition:write',+ 'query:read',+ 'query:write',+ 'replay_scanner:read',+ 'replay_scanner:write',+ 'review_hog:read',+ 'review_hog:write',+ 'revenue_analytics:read',+ 'revenue_analytics:write',+ 'session_recording:read',+ 'session_recording:write',+ 'session_recording_playlist:read',+ 'session_recording_playlist:write',+ 'sharing_configuration:read',+ 'sharing_configuration:write',+ 'signal_scout:read',+ 'signal_scout:write',+ 'stamphog:read',+ 'stamphog:write',+ 'streamlit_app:read',+ 'streamlit_app:write',+ 'subscription:read',+ 'subscription:write',+ 'support_ticket:read',+ 'support_ticket:write',+ 'survey:read',+ 'survey:write',+ 'tagger:read',+ 'tagger:write',+ 'ticket:read',+ 'ticket:write',+ 'task:read',+ 'task:write',+ 'today:read',+ 'today:write',+ 'toolbar:read',+ 'toolbar:write',+ 'tracing:read',+ 'tracing:write',+ 'field_note:read',+ 'field_note:write',+ 'uploaded_media:read',+ 'uploaded_media:write',+ 'usage_metric:read',+ 'usage_metric:write',+ 'user:read',+ 'user:write',+ 'user_interview:read',+ 'user_interview:write',+ 'vision_action:read',+ 'vision_action:write',+ 'vision_alert:read',+ 'vision_alert:write',+ 'visual_review:read',+ 'visual_review:write',+ 'warehouse_objects:read',+ 'warehouse_objects:write',+ 'warehouse_table:read',+ 'warehouse_table:write',+ 'warehouse_view:read',+ 'warehouse_view:write',+ 'web_analytics:read',+ 'web_analytics:write',+ 'webhook:read',+ 'webhook:write',+] as const++export type OAuthScope = (typeof OAUTH_SCOPES_SUPPORTED)[number]++// PAT-grantable but deliberately absent from OAUTH_SCOPES_SUPPORTED, so OAuth+// clients can never request them (mirrors OAUTH_SCOPES_HIDDEN in posthog/scopes.py).+// The MCP server shows a tool that requires one of these only to a staff user+// whose personal API key carries it (plus `user:read` for the staff lookup);+// `*` does not match. The web app's scope pickers never show these objects.+export const OAUTH_SCOPES_HIDDEN = [+ 'batch_import_support:read',+ 'batch_import_support:write',+ 'query_performance:read',+ 'query_performance:write',+ 'wizard_run:read',+ 'wizard_run:write',+ 'wizard_session:read',+ 'wizard_session:write',+] as constdiff --git a/frontend/src/lib/scopes.test.ts b/frontend/src/lib/scopes.test.tsindex 091790e0b4c7..1e2cdfb1c014 100644--- a/frontend/src/lib/scopes.test.ts+++ b/frontend/src/lib/scopes.test.ts@@ -1,4 +1,5 @@import { AGENT_USE_CASE_SCOPES } from 'lib/agentScopes.generated'+import { OAUTH_SCOPES_HIDDEN } from 'lib/oauthScopes.generated'import {AGENT_CLI_API_KEY_SCOPES,API_KEY_SCOPE_PRESETS,@@ -11,7 +12,10 @@ import {import { ScopeObjectEnumApi } from 'products/access_control/frontend/generated/api.schemas'-const API_SCOPE_OBJECTS = Object.values(ScopeObjectEnumApi)+const OAUTH_HIDDEN_SCOPE_OBJECTS = new Set(OAUTH_SCOPES_HIDDEN.map((scope) => scope.split(':')[0]))++// The pickers never show an OAuth-hidden object, so only the rest need a row and a group.+const PICKER_SCOPE_OBJECTS = Object.values(ScopeObjectEnumApi).filter((obj) => !OAUTH_HIDDEN_SCOPE_OBJECTS.has(obj))const getRenderableKeyCreationScopes = (): Set<string> =>new Set(@@ -54,7 +58,7 @@ describe('API_SCOPES modal coverage', () => {it('offers or explicitly omits every scope object', () => {// The enum is generated from posthog/scopes.py, so a new backend scope object fails here// until someone offers it in the key-creation modal or gives a reason to omit it.- const uncovered = API_SCOPE_OBJECTS.filter((obj) => !offered.has(obj) && !omitted.has(obj))+ const uncovered = PICKER_SCOPE_OBJECTS.filter((obj) => !offered.has(obj) && !omitted.has(obj))expect(uncovered).toEqual([])})@@ -65,14 +69,23 @@ describe('API_SCOPES modal coverage', () => {})describe('API_SCOPE_GROUPS', () => {- it('files every scope object in exactly one group', () => {+ const filed = API_SCOPE_GROUPS.flatMap(({ objects }) => objects)++ it('files every picker scope object in exactly one group', () => {// A new scope object fails here until someone picks the product area it belongs to.- const filed = API_SCOPE_GROUPS.flatMap(({ objects }) => objects)const duplicates = [...new Set(filed.filter((obj, index) => filed.indexOf(obj) !== index))]- const missing = API_SCOPE_OBJECTS.filter((obj) => !filed.includes(obj))+ const missing = PICKER_SCOPE_OBJECTS.filter((obj) => !filed.includes(obj))expect({ duplicates, missing }).toEqual({ duplicates: [], missing: [] })})+ it('keeps OAuth-hidden scope objects out of every picker', () => {+ // A hidden object with a row would show in the key picker, and a group that exists only for+ // hidden objects carries a label that no person should ever see.+ const shown = [...filed, ...API_SCOPES.map(({ key }) => key)]+ const hidden = shown.filter((obj) => OAUTH_HIDDEN_SCOPE_OBJECTS.has(obj))+ expect(hidden).toEqual([])+ })+it('uses each group label once', () => {const labels = API_SCOPE_GROUPS.map(({ label }) => label)expect(labels).toEqual([...new Set(labels)])diff --git a/frontend/src/lib/scopes.tsx b/frontend/src/lib/scopes.tsxindex 33a38848caf9..0c61d05be347 100644--- a/frontend/src/lib/scopes.tsx+++ b/frontend/src/lib/scopes.tsx@@ -267,14 +267,10 @@ export const API_SCOPES: APIScope[] = [API_SCOPES.sort((a, b) => a.objectName.localeCompare(b.objectName))// Scope objects deliberately absent from the key-creation modal above, each with the reason.-// Every grantable scope object in `ScopeObjectEnumApi` must be either offered in `API_SCOPES` or listed here —+// Every scope object in `ScopeObjectEnumApi` must be either offered in `API_SCOPES` or listed here,+// except the OAuth-hidden ones in `OAUTH_SCOPES_HIDDEN` (lib/oauthScopes.generated), which no picker shows.// scopes.test.ts enforces that partition so a newly added backend scope can't silently go missing.export const API_SCOPES_OMITTED_FROM_MODAL: Partial<Record<APIScopeObject, string>> = {- // OAUTH_HIDDEN_SCOPE_OBJECTS — pasteable into a PAT, but never advertised via OAuth/CLI/MCP.- batch_import_support: 'OAuth-hidden: staff-only, pasteable into a PAT but not advertised.',- query_performance: 'OAuth-hidden: staff-only, pasteable into a PAT but not advertised.',- wizard_session: 'OAuth-hidden: pasteable into a PAT but not advertised.',- wizard_run: 'OAuth-hidden: pasteable into a PAT but not advertised.',// Umbrella access-control resource that `warehouse_view`/`warehouse_table` inherit from —// the granular scopes are offered instead, so keep the umbrella out of the modal.warehouse_objects: 'Umbrella resource: grant warehouse_view/warehouse_table instead.',@@ -394,10 +390,9 @@ export const PROJECT_SECRET_API_KEY_SCOPE_PRESETS: ProjectSecretAPIKeyScopePrese{ value: 'llm_gateway', label: 'AI gateway access', scopes: ['llm_gateway:read'] },]-// The product areas that the scope pickers use to group objects, in display order. Each grantable-// scope object in `ScopeObjectEnumApi` is in exactly one group, and scopes.test.ts fails until a new-// object has a group. OAuth-hidden objects go in the last group, "Internal tools". The pickers do not-// show those objects, so a person never sees that group.+// The product areas that the scope pickers use to group objects, in display order. Each scope object+// in `ScopeObjectEnumApi` is in exactly one group, except the OAuth-hidden ones, which no picker shows.+// scopes.test.ts fails until a new object has a group.export type APIScopeGroup = {label: stringobjects: APIScopeObject[]@@ -559,10 +554,6 @@ export const API_SCOPE_GROUPS: APIScopeGroup[] = ['file_system_shortcut',],},- {- label: 'Internal tools',- objects: ['batch_import_support', 'query_performance', 'wizard_session', 'wizard_run'],- },]export const OTHER_SCOPE_GROUP_LABEL = 'Other'diff --git a/frontend/src/scenes/oauth/oauthAuthorizeLogic.test.ts b/frontend/src/scenes/oauth/oauthAuthorizeLogic.test.tsindex 2b22491fe38f..f7b9106ec4a4 100644--- a/frontend/src/scenes/oauth/oauthAuthorizeLogic.test.ts+++ b/frontend/src/scenes/oauth/oauthAuthorizeLogic.test.ts@@ -118,7 +118,9 @@ describe('oauthAuthorizeLogic', () => {// Privileged/hidden objects are never grantable via /authorize; including them// would make the server reject the whole submit.expect(scopes).not.toContain('llm_gateway:read')- expect(scopes).not.toContain('metrics:read')+ expect(scopes).not.toContain('wizard_session:read')+ // metrics is OAuth-grantable, so the fallback keeps it.+ expect(scopes).toContain('metrics:read')})it('uses the server-computed read set when expanding the wildcard', () => {diff --git a/frontend/src/scenes/oauth/oauthAuthorizeLogic.ts b/frontend/src/scenes/oauth/oauthAuthorizeLogic.tsindex 24d68ec3e38c..e6c07219daf2 100644--- a/frontend/src/scenes/oauth/oauthAuthorizeLogic.ts+++ b/frontend/src/scenes/oauth/oauthAuthorizeLogic.ts@@ -7,6 +7,7 @@ import { router, urlToAction } from 'kea-router'import api from 'lib/api'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'+import { OAUTH_SCOPES_SUPPORTED } from 'lib/oauthScopes.generated'import {API_SCOPE_GROUPS,API_SCOPES,@@ -143,19 +144,14 @@ const requiredLevelsFromScopes = (requiredScopes: string[]): Map<string, Requirereturn levels}-// Mirrors PRIVILEGED_SCOPES + OAUTH_HIDDEN_SCOPE_OBJECTS in posthog/scopes.py: objects-// /authorize can never grant, so the wildcard expansion must skip them or the server-// would reject the whole submit with invalid_scope.-const OAUTH_UNGRANTABLE_OBJECTS: ReadonlySet<string> = new Set(['llm_gateway', 'metrics', 'wizard_session'])-// `*` grants read+write to everything; its read-only form is every grantable object's read-// scope. The server-computed list is authoritative — the local API_SCOPES list both lags-// behind new backend scopes (under-granting) and contains ungrantable ones (over-granting,-// which the server rejects). The local fallback only covers a missing app context.+// scope. The server-computed list is authoritative, because it applies the app's ceiling.+// The fallback only covers a missing app context, and takes the read scopes OAuth advertises+// so it never names a scope the server would reject with invalid_scope.const wildcardReadScopes = (oauthApplication: OAuthApplicationPublicMetadata | null): string[] =>oauthApplication?.wildcard_read_scopes?.length? oauthApplication.wildcard_read_scopes- : API_SCOPES.filter(({ key }) => !OAUTH_UNGRANTABLE_OBJECTS.has(key)).map(({ key }) => `${key}:read`)+ : OAUTH_SCOPES_SUPPORTED.filter((scope) => scope.endsWith(':read'))const isNativeProtocol = (url: string): boolean => {try {diff --git a/posthog/scopes.py b/posthog/scopes.pyindex 7a7601e9b9be..b5c4687d14df 100644--- a/posthog/scopes.py+++ b/posthog/scopes.py@@ -15,10 +15,10 @@ from typing import Literal, get_args# `GRANTABLE_API_SCOPE_OBJECTS` below, through the `resource` choice fields of the access# control serializers.#-# The MCP `OAUTH_SCOPES_SUPPORTED` list at-# `services/mcp/src/lib/oauth-scopes.generated.ts` is generated from-# `get_scope_descriptions()` below via `posthog/scopes_projection.py`. Run-# `hogli build:projections` to regenerate after editing this file.+# The `OAUTH_SCOPES_SUPPORTED` and `OAUTH_SCOPES_HIDDEN` lists at+# `services/mcp/src/lib/oauth-scopes.generated.ts` and `frontend/src/lib/oauthScopes.generated.ts`+# are generated from this file via `posthog/scopes_projection.py`. Run+# `hogli build:projections` to regenerate after editing it.APIScopeObject = Literal["action","access_control",diff --git a/posthog/scopes_projection.py b/posthog/scopes_projection.pyindex 7ca377504fa1..112d55217022 100755--- a/posthog/scopes_projection.py+++ b/posthog/scopes_projection.py@@ -1,6 +1,8 @@-"""Project the MCP server's view of the OAuth scope universe from posthog/scopes.py.+"""Project the OAuth scope universe from posthog/scopes.py into TypeScript.-Emits two constants into `services/mcp/src/lib/oauth-scopes.generated.ts`:+Writes the same file to two trees: `services/mcp/src/lib/oauth-scopes.generated.ts`+for the MCP server and `frontend/src/lib/oauthScopes.generated.ts` for the web app.+Each carries two constants:- OAUTH_SCOPES_SUPPORTED (from `get_oauth_scopes_supported()`): the MCP serverpublishes RFC 9728 protected-resource metadata at@@ -8,11 +10,15 @@ Emits two constants into `services/mcp/src/lib/oauth-scopes.generated.ts`:Code) read `scopes_supported` from there and pass every entry to theauthorization server's `/oauth/authorize`. If the resource list contains ascope the AS does not recognize, sign-in fails with `?error=invalid_scope`,- so this list must stay a subset of the AS's.+ so this list must stay a subset of the AS's. The web app's consent screen+ expands a wildcard grant to the read scopes in this list when the server+ sends no computed list.- OAUTH_SCOPES_HIDDEN: PAT-grantable scopes deliberately excluded from thelist above (staff-only surfaces like `batch_import_support`). The MCP serveruses this at runtime to gate tool discovery (`src/lib/staff-only-tools.ts`)and in tests to allow tools to require a non-advertised scope on purpose.+ The web app's scope pickers never show these objects, and scopes.test.ts+ exempts them from the picker rows and groups every other object needs.Generating both from `posthog/scopes.py` keeps that module the singleauthority for scope classification; the TS side is a projection of it.@@ -28,7 +34,10 @@ import runpyfrom pathlib import PathSCOPES_PY = Path(__file__).resolve().parent / "scopes.py"-OUTPUT = "services/mcp/src/lib/oauth-scopes.generated.ts"+OUTPUTS = (+ "services/mcp/src/lib/oauth-scopes.generated.ts",+ "frontend/src/lib/oauthScopes.generated.ts",+)def render_oauth_scopes() -> str:@@ -46,11 +55,13 @@ def render_oauth_scopes() -> str:"// AUTO-GENERATED by posthog/scopes_projection.py from posthog/scopes.py.\n""// Regenerate with `hogli build:projections`. Do not edit.\n""//\n"- "// Published as `scopes_supported` in MCP protected-resource metadata\n"- "// (RFC 9728). The OAuth authorization server publishes the same list\n"- "// from get_oauth_scopes_supported() at `/.well-known/oauth-authorization-server`.\n"- "// Keeping them aligned is what stops spec-compliant clients (e.g. Claude\n"- "// Code) from hitting `invalid_scope` at sign-in.\n"+ "// The OAuth scopes a client can request, from get_oauth_scopes_supported().\n"+ "// The MCP server publishes this list as `scopes_supported` in its\n"+ "// protected-resource metadata (RFC 9728). The web app's consent screen\n"+ "// expands a wildcard grant to the read scopes in this list when the server\n"+ "// sends no computed list. The OAuth authorization server publishes the same\n"+ "// list at `/.well-known/oauth-authorization-server`. If the lists differ, a\n"+ "// spec-compliant client (e.g. Claude Code) fails sign-in with `invalid_scope`.\n""\n""export const OAUTH_SCOPES_SUPPORTED = [\n"f"{body},\n"@@ -60,8 +71,9 @@ def render_oauth_scopes() -> str:"\n""// PAT-grantable but deliberately absent from OAUTH_SCOPES_SUPPORTED, so OAuth\n""// clients can never request them (mirrors OAUTH_SCOPES_HIDDEN in posthog/scopes.py).\n"- "// Tools requiring one of these only surface for staff users whose personal API key\n"- "// explicitly carries it (plus `user:read` for the staff lookup); `*` does not match.\n"+ "// The MCP server shows a tool that requires one of these only to a staff user\n"+ "// whose personal API key carries it (plus `user:read` for the staff lookup);\n"+ "// `*` does not match. The web app's scope pickers never show these objects.\n""export const OAUTH_SCOPES_HIDDEN = [\n"f"{hidden_body},\n""] as const\n"@@ -70,4 +82,5 @@ def render_oauth_scopes() -> str:def render() -> dict[str, str]:- return {OUTPUT: render_oauth_scopes()}+ output = render_oauth_scopes()+ return dict.fromkeys(OUTPUTS, output)diff --git a/services/mcp/src/lib/oauth-scopes.generated.ts b/services/mcp/src/lib/oauth-scopes.generated.tsindex dff4913c0b03..7a29cbf5383a 100644--- a/services/mcp/src/lib/oauth-scopes.generated.ts+++ b/services/mcp/src/lib/oauth-scopes.generated.ts@@ -1,11 +1,13 @@// AUTO-GENERATED by posthog/scopes_projection.py from posthog/scopes.py.// Regenerate with `hogli build:projections`. Do not edit.//-// Published as `scopes_supported` in MCP protected-resource metadata-// (RFC 9728). The OAuth authorization server publishes the same list-// from get_oauth_scopes_supported() at `/.well-known/oauth-authorization-server`.-// Keeping them aligned is what stops spec-compliant clients (e.g. Claude-// Code) from hitting `invalid_scope` at sign-in.+// The OAuth scopes a client can request, from get_oauth_scopes_supported().+// The MCP server publishes this list as `scopes_supported` in its+// protected-resource metadata (RFC 9728). The web app's consent screen+// expands a wildcard grant to the read scopes in this list when the server+// sends no computed list. The OAuth authorization server publishes the same+// list at `/.well-known/oauth-authorization-server`. If the lists differ, a+// spec-compliant client (e.g. Claude Code) fails sign-in with `invalid_scope`.export const OAUTH_SCOPES_SUPPORTED = ['openid',@@ -238,8 +240,9 @@ export type OAuthScope = (typeof OAUTH_SCOPES_SUPPORTED)[number]// PAT-grantable but deliberately absent from OAUTH_SCOPES_SUPPORTED, so OAuth// clients can never request them (mirrors OAUTH_SCOPES_HIDDEN in posthog/scopes.py).-// Tools requiring one of these only surface for staff users whose personal API key-// explicitly carries it (plus `user:read` for the staff lookup); `*` does not match.+// The MCP server shows a tool that requires one of these only to a staff user+// whose personal API key carries it (plus `user:read` for the staff lookup);+// `*` does not match. The web app's scope pickers never show these objects.export const OAUTH_SCOPES_HIDDEN = ['batch_import_support:read','batch_import_support:write',diff --git a/tools/hogli-commands/hogli_commands/projections.py b/tools/hogli-commands/hogli_commands/projections.pyindex c2e2b2e6548e..7e6c24364a6c 100644--- a/tools/hogli-commands/hogli_commands/projections.py+++ b/tools/hogli-commands/hogli_commands/projections.py@@ -84,10 +84,13 @@ PROJECTIONS: tuple[Projection, ...] = (),),Projection(- name="mcp-oauth-scopes",+ name="oauth-scopes",renderer="posthog/scopes_projection.py",inputs=("posthog/scopes.py",),- outputs=("services/mcp/src/lib/oauth-scopes.generated.ts",),+ outputs=(+ "services/mcp/src/lib/oauth-scopes.generated.ts",+ "frontend/src/lib/oauthScopes.generated.ts",+ ),),)