Skip to content

: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.

feat(integrations): show a back-to-chat page after GitHub connect (#118858)

Rafael Audibert4e3db34651e5
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 8395a17b3301..ac122d775fda 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -15490,10 +15490,22 @@ snapshots:
hash: v1.k794b7964.fcae9b65af8160ba40bf82664dd9b5a6b9f5a1ddbdedee05bf15ec453eb7aa64.3616s9KNJancKVe-j4dQsJdo3W1CVcwWxRMA24QgU6Q
scenes-other-account-connected--github-integration-connected--light:
hash: v1.k794b7964.8b287d932c7d89e4769d4d7a79205e51310541dc0cd1591812e2f2720fcd1dcf.OwYcgNvVm3W2msQK67UA0yi6X4skN-YvuKtoTJnvb3E
+ scenes-other-account-connected--github-integration-connected-from-chat--dark:
+ hash: v1.k794b7964.535f7aeb801398ecf55500693f9ade1baf555ed733e4493101dac42b04056a45.Qed7usHliqMf7DFZcDg1LFuSUN04T1T8QeihUWgow4E
+ scenes-other-account-connected--github-integration-connected-from-chat--light:
+ hash: v1.k794b7964.c5900005fd2031973261348080f18f7dfc81da66e4b31e13ad8c48f044b36b4e.H6Meweqjpk_OBydPJ_aiPUPZ7fbLluXeBCLsVPfL9aQ
scenes-other-account-connected--github-integration-failed--dark:
hash: v1.k794b7964.d394cba800dc42d80f3b1cea7fb920d020cc2074c9e0b06e4974876b8a4cf318.K2N8s22_cesvI1EmzuVNW6fWS7uWkt1_mgBJdSgPalg
scenes-other-account-connected--github-integration-failed--light:
hash: v1.k794b7964.80ceb7909660009c7e03f12e2eacbe6a05ccd428779032966faeac8c84ad8a0e.XONQ2bh-fy2UnBPBQk0BNm_NeKsGNKgkUE2hRr4sOdE
+ scenes-other-account-connected--github-integration-failed-from-chat--dark:
+ hash: v1.k794b7964.4f68d57d3cfc6e7589b2f81b06382812e32d84d9b45eb77bba80508d4bd0cabe.HrkzbByynZUikG3LYSS8JtMmKIuG_0bQ0Mm51-MRlWk
+ scenes-other-account-connected--github-integration-failed-from-chat--light:
+ hash: v1.k794b7964.df35d0aff13d613800ece8dfee7bd97b78c54674d753732270c476654ef74460.M5tAWPwC8jqluUe00dMQpMhMK_Jryoi2lbkTgpsgWP4
+ scenes-other-account-connected--github-integration-pending-from-chat--dark:
+ hash: v1.k794b7964.f59a17f4e6940dc9d1f517d5db2a524699107090eb3af619055fb7b7b49601c0.bZ-GZ-VGWiB7hq4SA2EXMkMtawFOF6AJ8CEgDmjppMU
+ scenes-other-account-connected--github-integration-pending-from-chat--light:
+ hash: v1.k794b7964.3e09f863ec3ec65f4804c9dad2468e4204340ca2e874de8e175d0bf63b7c7128.WTl1lcIsYBtSO4z1eQxP7u5exvarTnpRq9Z2VGD5fjU
scenes-other-account-connected--github-login-failed--dark:
hash: v1.k794b7964.7d20c098085fe690be2109a71a37b40ac5fa763f0afd702aadbe9b3c712a8f7b.DAcCHbNqKQOtZ8sThEiIcQuUCYuAhp-x-nWzqDTCNqI
scenes-other-account-connected--github-login-failed--light:
diff --git a/frontend/src/scenes/authentication/account/AccountConnected.stories.tsx b/frontend/src/scenes/authentication/account/AccountConnected.stories.tsx
index 3d90b44aa0da..79303e8c3ecb 100644
--- a/frontend/src/scenes/authentication/account/AccountConnected.stories.tsx
+++ b/frontend/src/scenes/authentication/account/AccountConnected.stories.tsx
@@ -55,6 +55,39 @@ export const GithubIntegrationFailed: Story = {
},
}
+export const GithubIntegrationConnectedFromChat: Story = {
+ parameters: {
+ pageUrl: pageUrlFor(
+ 'github-integration',
+ '?connect_from=mcp&provider=github&installation_id=12345&integration_id=42'
+ ),
+ },
+ render: () => {
+ useStorybookMocks({ get: { '/_preflight': cloudPreflight } })
+ return <AccountConnected kind="github-integration" />
+ },
+}
+
+export const GithubIntegrationPendingFromChat: Story = {
+ parameters: {
+ pageUrl: pageUrlFor('github-integration', '?connect_from=mcp&provider=github&github_install_pending=1'),
+ },
+ render: () => {
+ useStorybookMocks({ get: { '/_preflight': cloudPreflight } })
+ return <AccountConnected kind="github-integration" />
+ },
+}
+
+export const GithubIntegrationFailedFromChat: Story = {
+ parameters: {
+ pageUrl: pageUrlFor('github-integration', '?connect_from=mcp&provider=github&error=invalid_state'),
+ },
+ render: () => {
+ useStorybookMocks({ get: { '/_preflight': cloudPreflight } })
+ return <AccountConnected kind="github-integration" />
+ },
+}
+
export const GithubLoginLinked: Story = {
parameters: {
pageUrl: pageUrlFor('github-login', '?provider=github'),
diff --git a/frontend/src/scenes/authentication/account/AccountConnected.tsx b/frontend/src/scenes/authentication/account/AccountConnected.tsx
index 39b31040a6d6..fd38fdb18ffa 100644
--- a/frontend/src/scenes/authentication/account/AccountConnected.tsx
+++ b/frontend/src/scenes/authentication/account/AccountConnected.tsx
@@ -2,11 +2,15 @@ import { useValues } from 'kea'
import { router } from 'kea-router'
import { useEffect } from 'react'
-import { IconCheckCircle, IconWarning } from '@posthog/icons'
+import { IconCheckCircle, IconHourglass, IconWarning } from '@posthog/icons'
import { BridgePage } from 'lib/components/BridgePage/BridgePage'
import { SSO_PROVIDER_NAMES } from 'lib/constants'
-import { describeGithubSetupError, getGithubSetupErrorCode } from 'lib/integrations/githubSetupErrors'
+import {
+ GITHUB_INSTALL_PENDING_MESSAGE,
+ describeGithubSetupError,
+ getGithubSetupErrorCode,
+} from 'lib/integrations/githubSetupErrors'
import { SceneExport } from 'scenes/sceneTypes'
import type { SSOProvider } from '~/types'
@@ -75,6 +79,16 @@ function headline(kind: Exclude<AccountConnectedKind, 'invalid'>, label: string,
return isError ? `${label} linking failed` : `${label} linked to account`
}
+function chatReturnMessage(errorCode: string, errorMessage: string | null): string {
+ if (errorCode === 'github_install_pending') {
+ return `${GITHUB_INSTALL_PENDING_MESSAGE} After it's approved, go back to your chat and tell the assistant to continue.`
+ }
+ if (errorCode) {
+ return `${describeGithubSetupError(errorCode, errorMessage)} Go back to your chat and ask the assistant for a new link.`
+ }
+ return 'Go back to your chat and tell the assistant to continue.'
+}
+
const VALID_KINDS: ReadonlyArray<Exclude<AccountConnectedKind, 'invalid'>> = [
'github-login',
'github-integration',
@@ -95,8 +109,8 @@ export const scene: SceneExport<AccountConnectedProps> = {
* Unified return page for PostHog Desktop / web: social SSO link (`github-login`), personal GitHub
* integration (`github-integration`), or team Slack integration (`slack-integration`). Navigates
* to the matching `posthog-code://…` deep link so the desktop app refreshes its integrations —
- * except when started from Slack (`connect_from=slack`), where it shows a terminal success state
- * and the user returns to Slack manually (no deep link).
+ * except when started from Slack (`connect_from=slack`) or from an AI chat through the PostHog MCP
+ * (`connect_from=mcp`), where it shows a terminal state and the user returns there manually.
*/
function isValidKind(kind: AccountConnectedKind | undefined): kind is Exclude<AccountConnectedKind, 'invalid'> {
return typeof kind === 'string' && (VALID_KINDS as readonly string[]).includes(kind)
@@ -111,16 +125,20 @@ export function AccountConnected({ kind }: AccountConnectedProps): JSX.Element {
// The Slack flow has no deep link back — the user just returns to Slack themselves, so we only
// show the success state. PostHog Desktop refreshes its integrations via a desktop deep link.
const startedFromSlack = searchParams.connect_from === 'slack'
+ // pinned: `mcp` is the `connect_from` value in the GitHub connect URL the PostHog MCP hands out.
+ const startedFromChat = searchParams.connect_from === 'mcp'
+ const opensDesktopApp = !startedFromSlack && !startedFromChat
+ const isPending = errorCode === 'github_install_pending'
// Allowlist-style check — `paramsToProps` is expected to map unknown kinds to `'invalid'`,
// but guarding directly against the valid set means a route mismatch (e.g. project-prefix
// edge case) can't crash `posthogCodeDeepUrl` with an undefined deep-link host.
const hasValidKind = isValidKind(kind)
useEffect(() => {
- if (hasValidKind && !startedFromSlack) {
+ if (hasValidKind && opensDesktopApp) {
window.location.href = posthogCodeDeepUrl(kind, searchParams)
}
- }, [hasValidKind, kind, searchParams, startedFromSlack])
+ }, [hasValidKind, kind, searchParams, opensDesktopApp])
if (!hasValidKind) {
return (
@@ -139,14 +157,25 @@ export function AccountConnected({ kind }: AccountConnectedProps): JSX.Element {
return (
<BridgePage view="account-connected">
<div className="flex flex-col items-center gap-4 text-center max-w-lg mx-auto">
- {isError ? (
+ {startedFromChat && isPending ? (
+ <IconHourglass className="text-warning text-5xl shrink-0" />
+ ) : isError ? (
<IconWarning className="text-danger text-5xl shrink-0" />
) : (
<IconCheckCircle className="text-success text-5xl shrink-0" />
)}
- <h2 className="text-xl font-semibold m-0">{headline(kind, label, isError)}</h2>
+ <h2 className="text-xl font-semibold m-0">
+ {startedFromChat && isPending ? `${label} install needs approval` : headline(kind, label, isError)}
+ </h2>
{showLoginLine && <p className="text-muted mb-0">You can now log into PostHog using {label}.</p>}
- {startedFromSlack ? (
+ {startedFromChat ? (
+ <p className="text-muted mb-0">
+ {chatReturnMessage(
+ errorCode,
+ typeof searchParams.error_message === 'string' ? searchParams.error_message : null
+ )}
+ </p>
+ ) : startedFromSlack ? (
<p className="text-muted mb-0">
{isError
? 'Something went wrong. Head back to Slack and try again.'
diff --git a/posthog/api/integration_connect.py b/posthog/api/integration_connect.py
index 33ceed9b4a50..0b12b0c29662 100644
--- a/posthog/api/integration_connect.py
+++ b/posthog/api/integration_connect.py
@@ -4,8 +4,9 @@ from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
_CONNECT_REDIRECT_ALLOWED_KINDS = {"github", "slack", "linear"}
# Surfaces allowed to start a connect flow and be returned to afterwards (see
-# posthog/api/github_callback/types.py APP_CONNECT_FROM_VALUES, plus Slack).
-_CONNECT_REDIRECT_ALLOWED_SURFACES = {"posthog_code", "posthog_mobile", "slack"}
+# posthog/api/github_callback/types.py APP_CONNECT_FROM_VALUES, plus Slack). `mcp` is the
+# link the PostHog MCP hands to a person chatting with an assistant.
+_CONNECT_REDIRECT_ALLOWED_SURFACES = {"posthog_code", "posthog_mobile", "slack", "mcp"}
def integration_connect_redirect(request: HttpRequest, kind: str) -> HttpResponse:
diff --git a/posthog/test/test_urls.py b/posthog/test/test_urls.py
index 431f2a59a3a2..015e6e0f81a7 100644
--- a/posthog/test/test_urls.py
+++ b/posthog/test/test_urls.py
@@ -83,16 +83,17 @@ class TestUrls(APIBaseTest):
self.assertEqual(response.status_code, status.HTTP_302_FOUND)
self.assertEqual(response["Location"], "https://us.posthog.com/organization/billing")
- def test_integration_connect_redirect_authenticated(self):
+ @parameterized.expand([("slack",), ("mcp",)])
+ def test_integration_connect_redirect_authenticated(self, connect_from: str):
response = self.client.get(
- f"/integrations/connect/github/?project_id={self.team.id}&connect_from=slack", follow=False
+ f"/integrations/connect/github/?project_id={self.team.id}&connect_from={connect_from}", follow=False
)
self.assertEqual(response.status_code, status.HTTP_302_FOUND)
location = response["Location"]
self.assertIn(f"/api/projects/{self.team.id}/integrations/authorize/", location)
self.assertIn("kind=github", location)
self.assertIn("account-connected", location)
- self.assertIn("connect_from%3Dslack", location)
+ self.assertIn(f"connect_from%3D{connect_from}", location)
def test_integration_connect_redirect_requires_login(self):
self.client.logout()