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: fix lighthouse agent accessibility and discovery checks (#128055)

Paul D'Ambrafaef139b9c44
diff --git a/frontend/src/toolbar/floating/components/bar/ToolbarButton.tsx b/frontend/src/toolbar/floating/components/bar/ToolbarButton.tsx
index 5725ef726b83..233ba5fa4e15 100644
--- a/frontend/src/toolbar/floating/components/bar/ToolbarButton.tsx
+++ b/frontend/src/toolbar/floating/components/bar/ToolbarButton.tsx
@@ -15,7 +15,7 @@ export type ToolbarButtonProps = {
children: React.ReactNode
onClick?: () => void
title?: string
- titleMinimized?: JSX.Element | string
+ titleMinimized?: string
menuId?: MenuState
flex?: boolean
}
@@ -29,6 +29,7 @@ export const ToolbarButton: FunctionComponent<ToolbarButtonProps> = React.forwar
const active = visibleMenu === menuId
const theTitle = title ?? (menuId ? capitalizeFirstLetter(menuId) : undefined)
+ const label = (minimized && titleMinimized) || theTitle
// We want to delay the cancel of dragging as there is a slight race with the click handler
const delayedIsDragging = React.useRef<boolean>(false)
@@ -52,27 +53,22 @@ export const ToolbarButton: FunctionComponent<ToolbarButtonProps> = React.forwar
onClick?.()
if (menuId) {
- visibleMenu === menuId ? setVisibleMenu('none') : setVisibleMenu(menuId)
+ setVisibleMenu(visibleMenu === menuId ? 'none' : menuId)
}
}
const theButton = (
<div
className={clsx('ToolbarButton', active && 'ToolbarButton--active', flex && 'ToolbarButton--flex')}
- aria-label={theTitle}
ref={ref}
>
- <button className="ToolbarButton__button" {...props} onClick={_onClick}>
+ <button className="ToolbarButton__button" aria-label={label} {...props} onClick={_onClick}>
{children}
</button>
</div>
)
- return ((minimized && titleMinimized) || theTitle) && !isDragging ? (
- <Tooltip title={minimized ? titleMinimized : theTitle}>{theButton}</Tooltip>
- ) : (
- theButton
- )
+ return label && !isDragging ? <Tooltip title={label}>{theButton}</Tooltip> : theButton
})
ToolbarButton.displayName = 'ToolbarButton'
diff --git a/posthog/api/test/__snapshots__/test_preflight.ambr b/posthog/api/test/__snapshots__/test_preflight.ambr
index 747418c6d48e..ef7d36a1ea4f 100644
--- a/posthog/api/test/__snapshots__/test_preflight.ambr
+++ b/posthog/api/test/__snapshots__/test_preflight.ambr
@@ -183,101 +183,3 @@
LIMIT 21
'''
# ---
-# name: TestPreflight.test_cloud_preflight_limited_db_queries.2
- '''
- SELECT "posthog_team"."id",
- "posthog_team"."uuid",
- "posthog_team"."organization_id",
- "posthog_team"."parent_team_id",
- "posthog_team"."project_id",
- "posthog_team"."api_token",
- "posthog_team"."app_urls",
- "posthog_team"."name",
- "posthog_team"."slack_incoming_webhook",
- "posthog_team"."created_at",
- "posthog_team"."updated_at",
- "posthog_team"."anonymize_ips",
- "posthog_team"."completed_snippet_onboarding",
- "posthog_team"."has_completed_onboarding_for",
- "posthog_team"."onboarding_tasks",
- "posthog_team"."ingested_event",
- "posthog_team"."ingested_production_event",
- "posthog_team"."ingested_production_event_last_checked_at",
- "posthog_team"."person_processing_opt_out",
- "posthog_team"."secret_api_token",
- "posthog_team"."secret_api_token_backup",
- "posthog_team"."session_recording_opt_in",
- "posthog_team"."session_recording_sample_rate",
- "posthog_team"."session_recording_minimum_duration_milliseconds",
- "posthog_team"."session_recording_linked_flag",
- "posthog_team"."session_recording_network_payload_capture_config",
- "posthog_team"."session_recording_masking_config",
- "posthog_team"."session_recording_url_trigger_config",
- "posthog_team"."session_recording_url_blocklist_config",
- "posthog_team"."session_recording_event_trigger_config",
- "posthog_team"."session_recording_trigger_match_type_config",
- "posthog_team"."session_recording_trigger_groups",
- "posthog_team"."session_replay_config",
- "posthog_team"."session_recording_retention_period",
- "posthog_team"."event_retention_months",
- "posthog_team"."conversations_enabled",
- "posthog_team"."conversations_settings",
- "posthog_team"."proactive_tasks_enabled",
- "posthog_team"."survey_config",
- "posthog_team"."surveys_opt_in",
- "posthog_team"."product_tours_opt_in",
- "posthog_team"."capture_console_log_opt_in",
- "posthog_team"."capture_performance_opt_in",
- "posthog_team"."capture_dead_clicks",
- "posthog_team"."autocapture_opt_out",
- "posthog_team"."autocapture_web_vitals_opt_in",
- "posthog_team"."autocapture_web_vitals_allowed_metrics",
- "posthog_team"."autocapture_exceptions_opt_in",
- "posthog_team"."autocapture_exceptions_errors_to_ignore",
- "posthog_team"."logs_settings",
- "posthog_team"."llm_gateway_enabled_at",
- "posthog_team"."llm_gateway_revoked_at",
- "posthog_team"."llm_gateway_overspend_allowance_usd",
- "posthog_team"."heatmaps_opt_in",
- "posthog_team"."receive_org_level_activity_logs",
- "posthog_team"."web_analytics_pre_aggregated_tables_enabled",
- "posthog_team"."web_analytics_pre_aggregated_tables_version",
- "posthog_team"."flags_persistence_default",
- "posthog_team"."feature_flag_confirmation_enabled",
- "posthog_team"."feature_flag_confirmation_message",
- "posthog_team"."default_evaluation_environments_enabled",
- "posthog_team"."require_evaluation_environment_tags",
- "posthog_team"."default_evaluation_contexts_enabled",
- "posthog_team"."require_evaluation_contexts",
- "posthog_team"."session_recording_version",
- "posthog_team"."signup_token",
- "posthog_team"."is_demo",
- "posthog_team"."access_control",
- "posthog_team"."week_start_day",
- "posthog_team"."inject_web_apps",
- "posthog_team"."test_account_filters",
- "posthog_team"."test_account_filters_default_checked",
- "posthog_team"."path_cleaning_filters",
- "posthog_team"."timezone",
- "posthog_team"."data_attributes",
- "posthog_team"."person_display_name_properties",
- "posthog_team"."live_events_columns",
- "posthog_team"."recording_domains",
- "posthog_team"."human_friendly_comparison_periods",
- "posthog_team"."cookieless_server_hash_mode",
- "posthog_team"."primary_dashboard_id",
- "posthog_team"."default_data_theme",
- "posthog_team"."extra_settings",
- "posthog_team"."modifiers",
- "posthog_team"."session_recording_retention_period_days",
- "posthog_team"."external_data_workspace_id",
- "posthog_team"."external_data_workspace_last_synced_at",
- "posthog_team"."api_query_rate_limit",
- "posthog_team"."drop_events_older_than",
- "posthog_team"."base_currency",
- "posthog_team"."business_model"
- FROM "posthog_team"
- WHERE "posthog_team"."id" = 99999
- LIMIT 21
- '''
-# ---
diff --git a/posthog/templates/llms_txt.md b/posthog/templates/llms_txt.md
new file mode 100644
index 000000000000..3bfdd1507bf4
--- /dev/null
+++ b/posthog/templates/llms_txt.md
@@ -0,0 +1,22 @@
+{% autoescape off %}# PostHog app
+
+> This is the PostHog web app. Most pages need a login. Agents get better results from the MCP server or the API than from reading app pages.
+
+- Do not crawl the app. Shared dashboards and shared links are private to the people who got them.
+- After a person logs in, the app gives in-page tools through WebMCP. An agent in the browser can call them, so it does not need to click through the UI.
+
+## Use PostHog from an agent
+
+- Install and configure the PostHog SDK with the setup agent: `npx @posthog/wizard@latest`.
+- Add PostHog MCP to your agent: `npx @posthog/wizard mcp add`.
+- [MCP server](https://mcp.posthog.com/mcp): Connect an MCP client here to query data and manage flags, insights, experiments and more.
+- [MCP server docs](https://posthog.com/docs/model-context-protocol): How to connect and authenticate.
+- [Agent sign-up and authentication]({{ site_url }}/auth.md): Create an account or authenticate an existing user.
+- [API reference](https://posthog.com/docs/api): REST API. It uses a personal API key.
+- [Personal API keys]({{ site_url }}/settings/user-api-keys): Create a key here.
+
+## Docs
+
+- [PostHog docs](https://posthog.com/docs): Product and SDK docs.
+- [Docs for LLMs](https://posthog.com/llms.txt): The full docs index in llms.txt format.
+{% endautoescape %}
diff --git a/posthog/test/test_urls.py b/posthog/test/test_urls.py
index f584d0908861..dd3088fc3650 100644
--- a/posthog/test/test_urls.py
+++ b/posthog/test/test_urls.py
@@ -315,6 +315,33 @@ class TestLegacyDuckgresAdminUrls(SimpleTestCase):
assert response["Location"] == expected_location
+class TestAgentDiscoveryFiles(SimpleTestCase):
+ @parameterized.expand(
+ [
+ ("llms_txt_on_cloud", "/llms.txt", "US", 200),
+ ("llms_txt_on_local_dev", "/llms.txt", "LOCAL", 200),
+ ("llms_txt_on_hobby", "/llms.txt", None, 404),
+ ("ai_catalog", "/ai-catalog.json", "US", 404),
+ ("well_known_ai_catalog", "/.well-known/ai-catalog.json", "US", 404),
+ ]
+ )
+ def test_agent_discovery_files_do_not_fall_through_to_the_app(
+ self, _name: str, request_path: str, region: str | None, expected_status: int
+ ) -> None:
+ request = RequestFactory().get(request_path)
+ match = resolve(request.path)
+
+ with override_settings(CLOUD_DEPLOYMENT=region, SITE_URL="https://us.example.com"):
+ response = match.func(request, *match.args, **match.kwargs)
+
+ assert response.status_code == expected_status
+ if expected_status == 200:
+ body = response.content.decode()
+ assert body.startswith("# ")
+ assert "](https://mcp.posthog.com/mcp)" in body
+ assert "](https://us.example.com/settings/user-api-keys)" in body
+
+
class TestConditionalRoutes(SimpleTestCase):
@parameterized.expand(list(product([False, True], [False, True], ["US", "EU"])))
def test_route_gates_and_precedence(self, debug: bool, test: bool, region: str) -> None:
diff --git a/posthog/urls.py b/posthog/urls.py
index 5b3593fa9e6d..f5469962a975 100644
--- a/posthog/urls.py
+++ b/posthog/urls.py
@@ -85,8 +85,10 @@ from .utils import opt_slash_path
from .views import (
handler500 as handler500,
health,
+ llms_txt,
login_required,
metrics_view,
+ not_found,
preflight_check,
render_query,
replay_player_frame,
@@ -327,6 +329,10 @@ urlpatterns = [
# NOTE: When adding paths here that should be public make sure to update ALWAYS_ALLOWED_ENDPOINTS in middleware.py
opt_slash_path("report", report.get_csp_event), # CSP violation reports
opt_slash_path("robots.txt", robots_txt),
+ opt_slash_path("llms.txt", llms_txt),
+ # Without these, the catch-all route answers with the app's HTML page, which agents read as a broken catalog
+ opt_slash_path("ai-catalog.json", not_found),
+ opt_slash_path(".well-known/ai-catalog.json", not_found),
opt_slash_path(".well-known/security.txt", security_txt),
opt_slash_path(".well-known/http-message-signatures-directory", http_message_signatures_directory),
# auth
diff --git a/posthog/views.py b/posthog/views.py
index a0264e60396a..a8a4baa92663 100644
--- a/posthog/views.py
+++ b/posthog/views.py
@@ -16,7 +16,14 @@ from django.contrib.auth.decorators import login_required as base_login_required
from django.db import DEFAULT_DB_ALIAS, connections
from django.db.migrations.executor import MigrationExecutor
from django.db.models import Q
-from django.http import HttpRequest, HttpResponse, HttpResponseNotAllowed, HttpResponseServerError, JsonResponse
+from django.http import (
+ HttpRequest,
+ HttpResponse,
+ HttpResponseNotAllowed,
+ HttpResponseNotFound,
+ HttpResponseServerError,
+ JsonResponse,
+)
from django.shortcuts import redirect, render
from django.template import loader
from django.views.decorators.cache import never_cache
@@ -30,7 +37,7 @@ from prometheus_client import REGISTRY, CollectorRegistry, generate_latest, mult
from posthog.api.secret_revocation import NON_PERSONAL_SECRET_PREFIXES
from posthog.auth import AUTH_BRAND_COOKIE, apply_auth_brand_cookie, normalize_auth_brand
from posthog.cache_utils import cache_for
-from posthog.cloud_utils import is_cloud
+from posthog.cloud_utils import is_cloud, is_hobby
from posthog.credentials_service.callers import CredentialsCaller
from posthog.credentials_service.errors import CredentialsServiceFailure
from posthog.credentials_service.settings_fallback import get_many_or_settings
@@ -168,6 +175,17 @@ Disallow: /flags/
return HttpResponse(ROBOTS_TXT_CONTENT, content_type="text/plain")
+def llms_txt(request: HttpRequest) -> HttpResponse:
+ if is_hobby():
+ return HttpResponseNotFound()
+
+ return render(request, "llms_txt.md", {"site_url": settings.SITE_URL}, content_type="text/markdown; charset=utf-8")
+
+
+def not_found(request: HttpRequest) -> HttpResponse:
+ return HttpResponseNotFound()
+
+
def security_txt(request):
SECURITY_TXT_CONTENT = """
Contact: mailto:[email protected]