: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-analytics): remove sessions search input (#108343)
Georgis Andonis22180de116d2
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 0797c8c1932a..c510f1d82f5a 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -11043,9 +11043,9 @@ snapshots:scenes-app-mcp-analytics--intent-clustering--light:hash: v1.k794b7964.82fd6a9108a34ff8808b23b9c1e9255dcbe4f38562bb9e99333877dd303c08b2.qjDLxTHFZT3vcTHmPeG35-orU88GSS277RR2DdXxBdwscenes-app-mcp-analytics--sessions--dark:- hash: v1.k794b7964.4844553e3c8a7420f2b616a57ec3640545c0f282bf4ecb7bcc0ef93c7e7315d1.e6ry4ctQni75OaoudOxk_vuh93h9DggNcHS__akWzpI+ hash: v1.k794b7964.b9da0424c439b93ca4cfee035f623db248bf270c2f35d67fb149913d51357021.MHRBg5VvUtimcxoRkdmXRQmmxfzUts7dkMN-IIoczzIscenes-app-mcp-analytics--sessions--light:- hash: v1.k794b7964.82d20edd75f9cb989d0cbdc1280171dbb274e6380a4d30d325bb2d4940283a32.H21JHgt3hDRHvfWnGbuwQhzPRH80oEkhfcYvhmKHnws+ hash: v1.k794b7964.71f6e90b821ebbb4bb36edc9cefae6763b0763df961c34bdcf0dc9dc94b32357.bSNLLSjjYgL1E4PwPNYD-A1AGnNbUWaYYXYl6_57Xcwscenes-app-mcp-analytics--tool-quality--dark:hash: v1.k794b7964.642dca04a5c6cb07edc0f125e9c7e0426a5a5dba0f2d121dd7b9bad9fd2709c9.a8J-gQWdL8aNFNlZuBxwf86m16C4h99rTH0vTEJE4Tcscenes-app-mcp-analytics--tool-quality--light:diff --git a/products/mcp_analytics/frontend/MCPAnalyticsToolDetail.tsx b/products/mcp_analytics/frontend/MCPAnalyticsToolDetail.tsxindex 7f21ce73ffc7..d8df66257a64 100644--- a/products/mcp_analytics/frontend/MCPAnalyticsToolDetail.tsx+++ b/products/mcp_analytics/frontend/MCPAnalyticsToolDetail.tsx@@ -1,4 +1,5 @@import { useActions, useValues } from 'kea'+import { router } from 'kea-router'import { useMemo } from 'react'import { IconArrowLeft, IconArrowRight, IconCopy, IconInfo } from '@posthog/icons'@@ -56,8 +57,9 @@ import {mcpAnalyticsToolDetailLogic,} from './mcpAnalyticsToolDetailLogic'import { mcpToolQualityUrlWithDates } from './mcpAnalyticsToolQualityLogic'+import { mcpSessionUrl } from './sessionUrls'import { CreateFixTaskButton } from './tool-quality/CreateFixTaskButton'-import { type MCPErrorContext, formatErrorContext, mcpSessionUrl } from './tool-quality/errorContext'+import { type MCPErrorContext, formatErrorContext } from './tool-quality/errorContext'export const scene: SceneExport<MCPAnalyticsToolDetailLogicProps> = {component: MCPAnalyticsToolDetail,@@ -806,6 +808,7 @@ export function MCPAnalyticsToolDetail(): JSX.Element {// Drill-down into one failure bucket: the individual errored calls, each with a// copyable, paste-ready context block for handing to a coding agent.function FailureOccurrencesModal(): JSX.Element {+ const { searchParams } = useValues(router)const { toolName, selectedFailure, failureOccurrences, failureOccurrencesLoading } =useValues(mcpAnalyticsToolDetailLogic)const { selectFailure } = useActions(mcpAnalyticsToolDetailLogic)@@ -878,7 +881,7 @@ function FailureOccurrencesModal(): JSX.Element {{occurrence.session_id ? (<LemonButtonsize="xsmall"- to={mcpSessionUrl(occurrence.session_id)}+ to={mcpSessionUrl(occurrence.session_id, searchParams)}tooltip="View the session this call belongs to">Sessiondiff --git a/products/mcp_analytics/frontend/components/ToolCallFeed.tsx b/products/mcp_analytics/frontend/components/ToolCallFeed.tsxindex 2ef41789076f..149ba3861368 100644--- a/products/mcp_analytics/frontend/components/ToolCallFeed.tsx+++ b/products/mcp_analytics/frontend/components/ToolCallFeed.tsx@@ -1,10 +1,13 @@+import { useValues } from 'kea'+import { router } from 'kea-router'+import { LemonTag, Link } from '@posthog/lemon-ui'import { QueryFeature } from '~/queries/nodes/DataTable/queryFeatures'import { Query } from '~/queries/Query/Query'import { DataTableNode } from '~/queries/schema/schema-general'-import { mcpSessionUrl } from '../tool-quality/errorContext'+import { mcpSessionUrl } from '../sessionUrls'import {MCP_ACTIVITY_ERROR_COLUMN,MCP_ACTIVITY_INTENT_COLUMN,@@ -31,11 +34,12 @@ function ErrorCell({ value }: { value: unknown }): JSX.Element {}function SessionCell({ value }: { value: unknown }): JSX.Element {+ const { searchParams } = useValues(router)if (!value) {return <span className="text-muted">—</span>}return (- <Link to={mcpSessionUrl(String(value))} data-attr="mcp-analytics-activity-session-link">+ <Link to={mcpSessionUrl(String(value), searchParams)} data-attr="mcp-analytics-activity-session-link">View session</Link>)diff --git a/products/mcp_analytics/frontend/dashboard/NotableSessionsTable.tsx b/products/mcp_analytics/frontend/dashboard/NotableSessionsTable.tsxindex 000b70e0afe7..6a5689b94c19 100644--- a/products/mcp_analytics/frontend/dashboard/NotableSessionsTable.tsx+++ b/products/mcp_analytics/frontend/dashboard/NotableSessionsTable.tsx@@ -1,5 +1,5 @@import { useValues } from 'kea'-import { combineUrl, router } from 'kea-router'+import { router } from 'kea-router'import { Link } from '@posthog/lemon-ui'import {@@ -19,19 +19,11 @@ import {} from '@posthog/quill-primitives'import { formatPercentage } from 'lib/utils/numbers'-import { urls } from 'scenes/urls'import { type NotableSession } from '../mcpDashboardOverviewLogic'+import { mcpSessionUrl, mcpSessionsUrl } from '../sessionUrls'import { formatDuration, truncateSessionId } from './formatters'-// Link to the Sessions tab, keeping the dashboard's date range so a linked session resolves in the-// same window. A sessionId becomes the search term (filtering the list to it and selecting it);-// without one, opens the full list.-function sessionsUrl(searchParams: Record<string, any>, sessionId?: string): string {- const { search: _search, ...rest } = searchParams- return combineUrl(urls.mcpAnalyticsSessions(), sessionId ? { ...rest, search: sessionId } : rest).url-}-const DESTRUCTIVE_ERROR_PCT = 5const WARNING_ERROR_PCT = 1@@ -87,7 +79,7 @@ function SessionRows({<TableRow key={entry.session.session_id}><TableCell className="whitespace-nowrap"><Link- to={sessionsUrl(searchParams, entry.session.session_id)}+ to={mcpSessionUrl(entry.session.session_id, searchParams)}className="font-mono"title={entry.session.session_id}>@@ -134,7 +126,7 @@ export function NotableSessionsTable({<SessionRows sessions={sessions} loading={loading} searchParams={searchParams} /></Table><CardFooter className="justify-end">- <Link to={sessionsUrl(searchParams)} className="text-[10px]">+ <Link to={mcpSessionsUrl(searchParams)} className="text-[10px]">Open in Sessions tab ↗</Link></CardFooter>diff --git a/products/mcp_analytics/frontend/sessionUrls.test.ts b/products/mcp_analytics/frontend/sessionUrls.test.tsnew file mode 100644index 000000000000..8963c62858f4--- /dev/null+++ b/products/mcp_analytics/frontend/sessionUrls.test.ts@@ -0,0 +1,42 @@+import { combineUrl } from 'kea-router'++import { urls } from 'scenes/urls'++import { AnyPropertyFilter, PropertyFilterType, PropertyOperator } from '~/types'++import { mcpSessionUrl, mcpSessionsUrl } from './sessionUrls'++describe('MCP session URLs', () => {+ const toolFilter: AnyPropertyFilter = {+ key: '$mcp_tool_name',+ value: ['create_insight'],+ operator: PropertyOperator.Exact,+ type: PropertyFilterType.Event,+ }+ const sessionFilter = (sessionId: string): AnyPropertyFilter => ({+ key: '$session_id',+ value: [sessionId],+ operator: PropertyOperator.Exact,+ type: PropertyFilterType.Event,+ })+ const sharedParams = {+ date_from: '-7d',+ has_errors: 'true',+ properties: [toolFilter, sessionFilter('old-session')],+ }++ it('links a session through the shared property filters', () => {+ expect(mcpSessionUrl('linked-session', { ...sharedParams, search: 'old-session' })).toBe(+ combineUrl(urls.mcpAnalyticsSessions(), {+ ...sharedParams,+ properties: [toolFilter, sessionFilter('linked-session')],+ }).url+ )+ })++ it('opens the full session list without stale session filters', () => {+ expect(mcpSessionsUrl({ ...sharedParams, search: 'old-session' })).toBe(+ combineUrl(urls.mcpAnalyticsSessions(), { ...sharedParams, properties: [toolFilter] }).url+ )+ })+})diff --git a/products/mcp_analytics/frontend/sessionUrls.ts b/products/mcp_analytics/frontend/sessionUrls.tsnew file mode 100644index 000000000000..a71b143d69c1--- /dev/null+++ b/products/mcp_analytics/frontend/sessionUrls.ts@@ -0,0 +1,36 @@+import { combineUrl } from 'kea-router'++import { urls } from 'scenes/urls'++import { AnyPropertyFilter, PropertyFilterType, PropertyOperator } from '~/types'++function sessionsUrl(searchParams: Record<string, any>, sessionId?: string): string {+ const { search: _search, properties, ...rest } = searchParams+ const otherProperties = Array.isArray(properties)+ ? properties.filter((filter) => filter?.key !== '$session_id' || filter?.type !== PropertyFilterType.Event)+ : []+ const nextProperties = sessionId+ ? [+ ...otherProperties,+ {+ key: '$session_id',+ value: [sessionId],+ operator: PropertyOperator.Exact,+ type: PropertyFilterType.Event,+ } satisfies AnyPropertyFilter,+ ]+ : otherProperties++ return combineUrl(urls.mcpAnalyticsSessions(), {+ ...rest,+ ...(nextProperties.length > 0 ? { properties: nextProperties } : {}),+ }).url+}++export function mcpSessionUrl(sessionId: string, searchParams: Record<string, any> = {}): string {+ return sessionsUrl(searchParams, sessionId)+}++export function mcpSessionsUrl(searchParams: Record<string, any> = {}): string {+ return sessionsUrl(searchParams)+}diff --git a/products/mcp_analytics/frontend/sessions/MCPSessionsPlaylist.tsx b/products/mcp_analytics/frontend/sessions/MCPSessionsPlaylist.tsxindex f6057d3b5edf..71c67c31f8b9 100644--- a/products/mcp_analytics/frontend/sessions/MCPSessionsPlaylist.tsx+++ b/products/mcp_analytics/frontend/sessions/MCPSessionsPlaylist.tsx@@ -1,13 +1,9 @@import { useActions, useValues } from 'kea'import { memo, useRef } from 'react'-import { IconBolt, IconClock, IconSearch, IconSparkles, IconWarning } from '@posthog/icons'+import { IconBolt, IconClock, IconSparkles, IconWarning } from '@posthog/icons'import {Button,- InputGroup,- InputGroupAddon,- InputGroupInput,- InputGroupText,Select,SelectContent,SelectItem,@@ -162,20 +158,7 @@ function SessionsListPanel(): JSX.Element {<div className="flex flex-col h-full min-h-0 overflow-hidden rounded border border-primary bg-surface-primary"><div className="shrink-0 flex flex-col gap-2 border-b border-primary p-2"><div className="flex flex-col gap-2" data-quill>- <div className="flex flex-wrap items-center gap-2">- <InputGroup className="min-w-40 flex-1">- <InputGroupAddon align="inline-start">- <InputGroupText>- <IconSearch />- </InputGroupText>- </InputGroupAddon>- <InputGroupInput- type="search"- placeholder="Search by session id, client, or tool"- onChange={(e) => setFilters({ search: e.target.value })}- value={filters.search}- />- </InputGroup>+ <div className="flex flex-wrap items-center justify-between gap-2"><Selectvalue={String(filters.hasErrors ?? 'all')}onValueChange={(value) => setFilters({ hasErrors: parseUrlBoolean(value) })}diff --git a/products/mcp_analytics/frontend/sessions/mcpSessionsLogic.test.ts b/products/mcp_analytics/frontend/sessions/mcpSessionsLogic.test.tsindex 3fb2c6dbc24e..d69c3db7ac18 100644--- a/products/mcp_analytics/frontend/sessions/mcpSessionsLogic.test.ts+++ b/products/mcp_analytics/frontend/sessions/mcpSessionsLogic.test.ts@@ -36,6 +36,13 @@ const TOOL_FILTER: AnyPropertyFilter = {type: PropertyFilterType.Event,}+const SESSION_FILTER: AnyPropertyFilter = {+ key: '$session_id',+ value: ['linked-session'],+ operator: PropertyOperator.Exact,+ type: PropertyFilterType.Event,+}+describe('mcpSessionsLogic', () => {let logic: ReturnType<typeof mcpSessionsLogic.build>@@ -89,9 +96,27 @@ describe('mcpSessionsLogic', () => {expect(listMock).toHaveBeenLastCalledWith(expect.anything(), expect.objectContaining({ has_errors: undefined }))})+ it('deep-links a session through the shared property filters', async () => {+ listMock.mockResolvedValue({+ results: [{ session_id: 'linked-session', session_start: '2026-01-01T00:00:00Z' }],+ has_next: false,+ })+ toolCallsMock.mockResolvedValue({ results: [], has_next: false })++ await expectLogic(logic, () => {+ router.actions.push(urls.mcpAnalyticsSessions(), {+ search: 'ignored-session',+ properties: [SESSION_FILTER],+ })+ }).toDispatchActions(['loadSessionsSuccess', 'loadToolCallsSuccess'])++ expect(logic.values.selectedSessionId).toBe('linked-session')+ expect(listMock.mock.lastCall?.[1]).toMatchObject({ properties: JSON.stringify([SESSION_FILTER]) })+ expect(listMock.mock.lastCall?.[1].search).toBeUndefined()+ })+it.each([['nothing', () => {}, false],- ['search', () => logic.actions.setFilters({ search: 'abc' }), true],['has errors', () => logic.actions.setFilters({ hasErrors: false }), true],['date range', () => logic.actions.setDateFilter('-30d', null), true],['property filter', () => mcpAnalyticsFiltersLogic.actions.setPropertyFilters([TOOL_FILTER]), true],diff --git a/products/mcp_analytics/frontend/sessions/mcpSessionsLogic.ts b/products/mcp_analytics/frontend/sessions/mcpSessionsLogic.tsindex 8d03dd3f3779..8cf7b9080778 100644--- a/products/mcp_analytics/frontend/sessions/mcpSessionsLogic.ts+++ b/products/mcp_analytics/frontend/sessions/mcpSessionsLogic.ts@@ -22,13 +22,11 @@ import {} from '../mcpAnalyticsFiltersLogic'export interface MCPSessionsFilters {- search: string// true: sessions with at least one errored call; false: sessions with none; null: both.hasErrors: boolean | null}const DEFAULT_FILTERS: MCPSessionsFilters = {- search: '',hasErrors: null,}@@ -41,8 +39,6 @@ export interface MCPSessionsDateFilter {// same window out of the box and the shared date_from/date_to URL params line up.const DEFAULT_DATE_FILTER: MCPSessionsDateFilter = { dateFrom: '-7d', dateTo: null }-const SEARCH_DEBOUNCE_MS = 300-// How many sessions to fetch per request. Each "Load more" appends the next pageexport const SESSIONS_PAGE_SIZE = 50@@ -335,17 +331,12 @@ export const mcpSessionsLogic = kea<mcpSessionsLogicType>([sessions: [[] as MCPSessionApi[],{- // First page / reset (search or sort change). Replaces the list.loadSessions: async (_, breakpoint) => {cache.sessionsGeneration = (cache.sessionsGeneration ?? 0) + 1- if (values.filters.search) {- await breakpoint(SEARCH_DEBOUNCE_MS)- }if (!values.currentProjectId) {return []}const response = await mcpAnalyticsSessionsList(String(values.currentProjectId), {- search: values.filters.search || undefined,has_errors: values.filters.hasErrors ?? undefined,order_by: orderByParam(values.sorting),date_from: values.dateFilter.dateFrom || undefined,@@ -366,11 +357,8 @@ export const mcpSessionsLogic = kea<mcpSessionsLogicType>([if (!values.currentProjectId) {return values.sessions}- // Snapshot the list and the query (search + sort) before the await. If a- // concurrent loadSessions reset (sort/search change) lands while this page- // is in flight, merging against the post-await values.sessions would corrupt- // the list — so we both offset and merge from the snapshot, and drop this- // page entirely if the query changed underneath us.+ // Keep a query snapshot because a reset can finish before this page.+ // Discard the old page instead of merging it into the new list.const baseSessions = values.sessionsconst generation = cache.sessionsGeneration ?? 0const filters = values.filters@@ -379,7 +367,6 @@ export const mcpSessionsLogic = kea<mcpSessionsLogicType>([const dateTo = values.dateFilter.dateToconst sharedFilters = values.sharedQueryFiltersconst response = await mcpAnalyticsSessionsList(String(values.currentProjectId), {- search: filters.search || undefined,has_errors: filters.hasErrors ?? undefined,order_by: orderBy,date_from: dateFrom || undefined,@@ -543,7 +530,6 @@ export const mcpSessionsLogic = kea<mcpSessionsLogicType>([dateFilter: MCPSessionsDateFilter,sharedQueryFilters: MCPSharedQueryFilters): boolean =>- !!filters.search ||filters.hasErrors !== null ||dateFilter.dateFrom !== DEFAULT_DATE_FILTER.dateFrom ||dateFilter.dateTo !== DEFAULT_DATE_FILTER.dateTo ||@@ -659,9 +645,7 @@ export const mcpSessionsLogic = kea<mcpSessionsLogicType>([},}}),- // Mirror the filters to the URL so they survive a refresh and follow across tabs (date_from /- // date_to are shared with the dashboard; search is Sessions-only and also lets the dashboard- // deep-link a session by pre-filling its id).+ // The date range follows users across MCP analytics tabs. The error filter applies only to Sessions.actionToUrl(({ values }) => {const syncUrl = (): [string, Record<string, any>, Record<string, any>, { replace: boolean }] => {const { currentLocation } = router.values@@ -669,7 +653,7 @@ export const mcpSessionsLogic = kea<mcpSessionsLogicType>([const params: Record<string, string | null> = {date_from: values.dateFilter.dateFrom,date_to: values.dateFilter.dateTo,- search: values.filters.search || null,+ search: null,has_errors: values.filters.hasErrors === null ? null : String(values.filters.hasErrors),}for (const [key, value] of Object.entries(params)) {@@ -693,14 +677,13 @@ export const mcpSessionsLogic = kea<mcpSessionsLogicType>([const dateTo = typeof searchParams.date_to === 'string' ? searchParams.date_to : nullconst dateChanged = dateFrom !== values.dateFilter.dateFrom || dateTo !== values.dateFilter.dateTo- const search = typeof searchParams.search === 'string' ? searchParams.search : ''const hasErrors = parseUrlBoolean(searchParams.has_errors)- const filtersChanged = search !== values.filters.search || hasErrors !== values.filters.hasErrors+ const filtersChanged = hasErrors !== values.filters.hasErrors// setFilters / setDateFilter each reload via their listener; only load directly when// neither changed and we haven't loaded yet.if (filtersChanged) {- actions.setFilters({ search, hasErrors })+ actions.setFilters({ hasErrors })}if (dateChanged) {actions.setDateFilter(dateFrom, dateTo)@@ -711,14 +694,13 @@ export const mcpSessionsLogic = kea<mcpSessionsLogicType>([},})),afterMount(({ actions, cache }) => {- // urlToAction owns the initial load when the sessions URL carries date or search params; this+ // urlToAction owns the initial load when the Sessions URL carries route parameters. This// is the fallback for a param-less mount (and off-route mounts in tests, where urlToAction// never fires). The cache.hasLoaded guard keeps a deep-linked load from firing twice.const { searchParams } = router.valuesconst hasUrlParams =typeof searchParams.date_from === 'string' ||typeof searchParams.date_to === 'string' ||- typeof searchParams.search === 'string' ||searchParams.has_errors !== undefinedif (!hasUrlParams && !cache.hasLoaded) {cache.hasLoaded = truediff --git a/products/mcp_analytics/frontend/tool-quality/errorContext.ts b/products/mcp_analytics/frontend/tool-quality/errorContext.tsindex d2bdba0fde8a..05a1f12193b2 100644--- a/products/mcp_analytics/frontend/tool-quality/errorContext.ts+++ b/products/mcp_analytics/frontend/tool-quality/errorContext.ts@@ -1,6 +1,8 @@import { addProjectIdIfMissing } from 'lib/utils/kea-router'import { urls } from 'scenes/urls'+import { mcpSessionUrl } from '../sessionUrls'+export interface MCPErrorContext {toolName: stringerrorType: string@@ -12,10 +14,6 @@ export interface MCPErrorContext {sessionId?: string}-export function mcpSessionUrl(sessionId: string): string {- return `${urls.mcpAnalyticsSessions()}?search=${encodeURIComponent(sessionId)}`-}-function absoluteUrl(path: string): string {return `${window.location.origin}${addProjectIdIfMissing(path)}`}