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.

fix(mcp): bake analytics token into ui app bundles (#111324)

Sam Pennington5d8fac6bc0c8
diff --git a/.github/workflows/cd-mcp-image.yml b/.github/workflows/cd-mcp-image.yml
index 8eaebf727f15..97d4acf46fb4 100644
--- a/.github/workflows/cd-mcp-image.yml
+++ b/.github/workflows/cd-mcp-image.yml
@@ -85,7 +85,10 @@ jobs:
labels: ${{ steps.docker-meta.outputs.labels }}
annotations: ${{ steps.docker-meta.outputs.annotations }}
platforms: linux/arm64,linux/amd64
- build-args: COMMIT_HASH=${{ github.sha }}
+ build-args: |
+ COMMIT_HASH=${{ github.sha }}
+ POSTHOG_UI_APPS_TOKEN=sTMFPsFhdP1Ssg
+ POSTHOG_MCP_APPS_ANALYTICS_BASE_URL=https://us.i.posthog.com
deploy:
name: Trigger MCP deployment
diff --git a/services/mcp/Dockerfile b/services/mcp/Dockerfile
index 4f6c4775a4a1..14d2c4b4cee1 100644
--- a/services/mcp/Dockerfile
+++ b/services/mcp/Dockerfile
@@ -53,6 +53,10 @@ COPY tools/openapi-codegen/ tools/openapi-codegen/
# so the whole `products/` tree needs to be in the build context.
COPY products/ products/
WORKDIR /code/services/mcp
+ARG POSTHOG_UI_APPS_TOKEN
+ARG POSTHOG_MCP_APPS_ANALYTICS_BASE_URL
+ENV POSTHOG_UI_APPS_TOKEN=${POSTHOG_UI_APPS_TOKEN} \
+ POSTHOG_MCP_APPS_ANALYTICS_BASE_URL=${POSTHOG_MCP_APPS_ANALYTICS_BASE_URL}
RUN pnpm exec tsx scripts/build-hono.ts && pnpm run build:ui-apps
#
@@ -72,8 +76,10 @@ COPY --from=build --chown=node:node /code/services/mcp/dist/hono-server.mjs.map
# UI app static assets — served at `/ui-apps/<app>/...` by `serveStatic` in app.ts.
COPY --from=build --chown=node:node /code/services/mcp/public/ ./public/
+ARG POSTHOG_MCP_APPS_ANALYTICS_BASE_URL
ENV NODE_ENV=production \
- PORT=3001
+ PORT=3001 \
+ POSTHOG_MCP_APPS_ANALYTICS_BASE_URL=${POSTHOG_MCP_APPS_ANALYTICS_BASE_URL}
EXPOSE 3001
diff --git a/services/mcp/src/ui-apps/analytics/posthog.ts b/services/mcp/src/ui-apps/analytics/posthog.ts
index bdb73a9d6dfe..9b4481a49da6 100644
--- a/services/mcp/src/ui-apps/analytics/posthog.ts
+++ b/services/mcp/src/ui-apps/analytics/posthog.ts
@@ -12,9 +12,8 @@ declare const __POSTHOG_MCP_APPS_ANALYTICS_BASE_URL__: string | undefined
const POSTHOG_TOKEN = typeof __POSTHOG_UI_APPS_TOKEN__ !== 'undefined' ? __POSTHOG_UI_APPS_TOKEN__ : undefined
const POSTHOG_HOST =
- typeof __POSTHOG_MCP_APPS_ANALYTICS_BASE_URL__ !== 'undefined'
- ? __POSTHOG_MCP_APPS_ANALYTICS_BASE_URL__
- : 'https://us.posthog.com'
+ (typeof __POSTHOG_MCP_APPS_ANALYTICS_BASE_URL__ !== 'undefined' && __POSTHOG_MCP_APPS_ANALYTICS_BASE_URL__) ||
+ undefined
let client: PostHog | null = null
let currentDistinctId: string | null = null
diff --git a/services/mcp/vite.ui-apps.config.ts b/services/mcp/vite.ui-apps.config.ts
index 4005a804eaee..1553ef5338f8 100644
--- a/services/mcp/vite.ui-apps.config.ts
+++ b/services/mcp/vite.ui-apps.config.ts
@@ -10,8 +10,7 @@ const POSTHOG_UI_APPS_TOKEN = process.env.POSTHOG_UI_APPS_TOKEN || ''
// Analytics base URL for MCP Apps - where events are sent
// For local development, set to http://localhost:8010
-const POSTHOG_MCP_APPS_ANALYTICS_BASE_URL =
- process.env.POSTHOG_MCP_APPS_ANALYTICS_BASE_URL || 'https://us.i.posthog.com'
+const POSTHOG_MCP_APPS_ANALYTICS_BASE_URL = process.env.POSTHOG_MCP_APPS_ANALYTICS_BASE_URL || ''
// Apps directory - each .tsx file is an app
const APPS_DIR = resolve(__dirname, 'src/ui-apps/apps')