: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): point dev oauth at the dev instance (#93672)
Ben Whitebc53f02e8a48
diff --git a/services/mcp/src/lib/oauth-constants.ts b/services/mcp/src/lib/oauth-constants.tsindex 966f9c7c5748..c384ee5e441a 100644--- a/services/mcp/src/lib/oauth-constants.ts+++ b/services/mcp/src/lib/oauth-constants.ts@@ -89,7 +89,23 @@ export const isCloudApi = (): boolean => {export const isLocalApi = (): boolean => !!getCustomApiBaseUrl()?.includes('localhost')+const isCloudHost = (url: string): boolean => {+ try {+ return CLOUD_HOSTS.has(new URL(url).hostname)+ } catch {+ return false+ }+}+export const resolveAuthorizationServerUrl = (): string => {+ // Every k8s deployment shares a cluster-internal `POSTHOG_API_BASE_URL` that a browser+ // cannot reach, so it cannot double as the authorization server. Cloud sends clients to+ // the region proxy, which only knows US and EU. Non-cloud environments (dev) authorize+ // against their own public instance instead, named by `POSTHOG_PUBLIC_URL`.+ const publicUrl = env.POSTHOG_PUBLIC_URL+ if (publicUrl && !isCloudHost(publicUrl)) {+ return publicUrl+ }if (isCloudApi()) {return OAUTH_PROXY_URL}diff --git a/services/mcp/tests/unit/oauth-region.test.ts b/services/mcp/tests/unit/oauth-region.test.tsindex e904dbb9edab..b822c37e4ab2 100644--- a/services/mcp/tests/unit/oauth-region.test.ts+++ b/services/mcp/tests/unit/oauth-region.test.ts@@ -136,6 +136,20 @@ describe('OAuth Region Routing', () => {delete process.env.POSTHOG_API_BASE_URLexpect(getAuthorizationServerUrl()).toBe('https://oauth.posthog.com')})++ it.each([+ {+ name: 'dev',+ publicUrl: 'https://app.dev.posthog.dev',+ expected: 'https://app.dev.posthog.dev',+ },+ { name: 'prod-us', publicUrl: 'https://us.posthog.com', expected: 'https://oauth.posthog.com' },+ { name: 'prod-eu', publicUrl: 'https://eu.posthog.com', expected: 'https://oauth.posthog.com' },+ ])('returns $expected for the $name cluster deployment', ({ publicUrl, expected }) => {+ process.env.POSTHOG_API_BASE_URL = 'http://posthog-web-django.posthog.svc.cluster.local:8000'+ process.env.POSTHOG_PUBLIC_URL = publicUrl+ expect(getAuthorizationServerUrl()).toBe(expected)+ })})describe('401 Response Metadata URL (RFC 9728)', () => {