: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
fix(mcp): restore write-implies-read for server-mint scopes (#92045)
Andrew Maguire17c53e4e06d5
diff --git a/services/mcp/src/lib/api.ts b/services/mcp/src/lib/api.tsindex 6d2ea7a24c7a..eae62c50f9b9 100644--- a/services/mcp/src/lib/api.ts+++ b/services/mcp/src/lib/api.ts@@ -9,11 +9,12 @@ const SERVER_MINT_ONLY_SCOPE_OBJECTS = new Set([export const hasScope = (scopes: string[], requiredScope: string): boolean => {const scopeObject = requiredScope.split(':', 1)[0]- if (scopeObject && SERVER_MINT_ONLY_SCOPE_OBJECTS.has(scopeObject)) {- return scopes.includes(requiredScope)- }+ const isServerMintOnly = scopeObject !== undefined && SERVER_MINT_ONLY_SCOPE_OBJECTS.has(scopeObject)- if (scopes.includes('*')) {+ // A user-consented `*` must never reach a server-minted scope object. Only the wildcard is+ // withheld — the read/write rule below still applies, so this stays in step with the Django+ // permission layer (`posthog/permissions.py`), which authorizes the same tokens server-side.+ if (!isServerMintOnly && scopes.includes('*')) {return true}diff --git a/services/mcp/tests/unit/tool-filtering.test.ts b/services/mcp/tests/unit/tool-filtering.test.tsindex ffcc6c2e7feb..0a5fb0108dd7 100644--- a/services/mcp/tests/unit/tool-filtering.test.ts+++ b/services/mcp/tests/unit/tool-filtering.test.ts@@ -498,6 +498,37 @@ describe('server-minted scope matching', () => {expect(hasScope(['*'], 'signal_scratchpad_internal:write')).toBe(false)expect(hasScope(['signal_scratchpad_internal:write'], 'signal_scratchpad_internal:write')).toBe(true)})++ // Withholding the wildcard from these objects must not also withhold write-implies-read.+ // Scout sandbox tokens carry `signal_scout_internal:write` and never the `:read` form, so+ // dropping that rule hid `scout-members-list` from every scout's toolset and left reports+ // with nobody to route to. Django authorizes the same tokens with the rule applied.+ it.each([+ 'internal_run',+ 'loop_context_internal',+ 'mcp_builtin_agent',+ 'signal_scout_internal',+ 'signal_scout_report',+ 'signal_scratchpad_internal',+ ])('lets a %s:write token satisfy the matching :read scope', (scopeObject) => {+ expect(hasScope([`${scopeObject}:write`], `${scopeObject}:read`)).toBe(true)+ // The implication runs one way only.+ expect(hasScope([`${scopeObject}:read`], `${scopeObject}:write`)).toBe(false)+ // A wildcard still reaches neither form.+ expect(hasScope(['*'], `${scopeObject}:read`)).toBe(false)+ expect(hasScope(['*'], `${scopeObject}:write`)).toBe(false)+ })++ it('does not let a write on one internal object reach another', () => {+ expect(hasScope(['signal_scout_report:write'], 'signal_scout_internal:read')).toBe(false)+ })++ it('leaves wildcard and write-implies-read intact for user-grantable scopes', () => {+ expect(hasScope(['*'], 'insight:read')).toBe(true)+ expect(hasScope(['*'], 'insight:write')).toBe(true)+ expect(hasScope(['insight:write'], 'insight:read')).toBe(true)+ expect(hasScope(['insight:read'], 'insight:write')).toBe(false)+ })})describe('getAdvertisedOAuthScopes', () => {