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(mcp-analytics): add internal users toggle to missing capabilities (#125299)

Carles Salvadord9819e4d5731
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index a2750ae65b06..ebfb6011a31f 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -32954,6 +32954,10 @@
"dateRange": {
"$ref": "#/definitions/DateRange"
},
+ "filterTestAccounts": {
+ "description": "Exclude reports from the project's internal and test users.",
+ "type": "boolean"
+ },
"kind": {
"const": "MCPMissingCapabilitiesQuery",
"type": "string"
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index 90b5a0c740e8..01cc4c39123b 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -4172,6 +4172,8 @@ export interface MCPMissingCapabilitiesQueryResponse extends AnalyticsQueryRespo
export interface MCPMissingCapabilitiesQuery extends DataNode<MCPMissingCapabilitiesQueryResponse> {
kind: NodeKind.MCPMissingCapabilitiesQuery
dateRange?: DateRange
+ /** Exclude reports from the project's internal and test users. */
+ filterTestAccounts?: boolean
/** Case-insensitive substring match over the report text. */
search?: string
/** Page size; defaults to 100, capped at 500. */
diff --git a/posthog/schema.py b/posthog/schema.py
index 87acca0b0ae1..9ec592437b31 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -29768,6 +29768,10 @@ class MCPMissingCapabilitiesQuery(BaseModel):
extra="forbid",
)
dateRange: DateRange | None = None
+ filterTestAccounts: bool | None = Field(
+ default=None,
+ description="Exclude reports from the project's internal and test users.",
+ )
kind: Literal["MCPMissingCapabilitiesQuery"] = "MCPMissingCapabilitiesQuery"
limit: int | None = Field(default=None, description="Page size; defaults to 100, capped at 500.")
modifiers: HogQLQueryModifiers | None = Field(default=None, description="Modifiers used when performing the query")
diff --git a/products/mcp_analytics/backend/hogql_queries/missing_capabilities.py b/products/mcp_analytics/backend/hogql_queries/missing_capabilities.py
index af85895732d8..34cdf8761a9c 100644
--- a/products/mcp_analytics/backend/hogql_queries/missing_capabilities.py
+++ b/products/mcp_analytics/backend/hogql_queries/missing_capabilities.py
@@ -32,6 +32,7 @@ from products.mcp_analytics.backend.hogql_queries.base import (
CONVERSATION_ID_SQL,
display_person_properties,
mcp_query_date_range,
+ shared_filter_exprs,
validate_mcp_analytics_access,
)
@@ -81,6 +82,7 @@ class MCPMissingCapabilitiesQueryRunner(AnalyticsQueryRunner[MCPMissingCapabilit
"timestamp >= {date_from}", placeholders={"date_from": self.query_date_range.date_from_as_hogql()}
),
parse_expr("timestamp <= {date_to}", placeholders={"date_to": self.query_date_range.date_to_as_hogql()}),
+ *shared_filter_exprs(self.team, None, self.query.filterTestAccounts),
]
term = (self.query.search or "").strip()
if term:
diff --git a/products/mcp_analytics/backend/tests/test_missing_capabilities.py b/products/mcp_analytics/backend/tests/test_missing_capabilities.py
index 6df50e486488..136088a20cbf 100644
--- a/products/mcp_analytics/backend/tests/test_missing_capabilities.py
+++ b/products/mcp_analytics/backend/tests/test_missing_capabilities.py
@@ -83,6 +83,24 @@ class TestMCPMissingCapabilitiesQueryRunner(_MCPAnalyticsTeamScopedTestMixin, Cl
assert [row.intent for row in self._run(search=term)] == expected
+ @parameterized.expand(
+ [
+ ("excluded", True, ["external ask"]),
+ ("included", False, ["internal ask", "external ask"]),
+ ]
+ )
+ def test_filter_test_accounts(self, _name: str, filter_test_accounts: bool, expected: list[str]) -> None:
+ self.team.test_account_filters = [
+ {"key": "$mcp_client_name", "value": ["internal-agent"], "operator": "is_not", "type": "event"}
+ ]
+ self.team.save()
+ now = datetime.now(tz=UTC)
+ self._emit(intent="external ask", timestamp=now - timedelta(hours=2))
+ self._emit(intent="internal ask", client_name="internal-agent", timestamp=now - timedelta(hours=1))
+ flush_persons_and_events()
+
+ assert [row.intent for row in self._run(filterTestAccounts=filter_test_accounts)] == expected
+
def test_labels_unidentified_and_self_reported_clients(self) -> None:
self._emit(intent="no client identity", client_name=None)
self._emit(intent="self-reported client", client_name="some-inhouse-agent")
diff --git a/products/mcp_analytics/frontend/missingCapabilities/MCPAnalyticsMissingCapabilities.tsx b/products/mcp_analytics/frontend/missingCapabilities/MCPAnalyticsMissingCapabilities.tsx
index 55d968688b31..0eeed2fc4c1c 100644
--- a/products/mcp_analytics/frontend/missingCapabilities/MCPAnalyticsMissingCapabilities.tsx
+++ b/products/mcp_analytics/frontend/missingCapabilities/MCPAnalyticsMissingCapabilities.tsx
@@ -13,6 +13,7 @@ import { MCPMissingCapabilitiesItem } from '~/queries/schema/schema-general'
import { PersonDisplay } from 'products/persons/frontend/components/PersonDisplay'
import { McpDateFilter } from '../components/McpDateFilter'
+import { McpInternalUsersFilter } from '../components/McpInternalUsersFilter'
import { HarnessLogo } from '../dashboard/harness'
import { useMCPAnalyticsWizardCommand } from '../onboarding/MCPAnalyticsInstall'
import { isUnidentifiedClient, mcpMissingCapabilitiesLogic, parsePersonProperties } from './mcpMissingCapabilitiesLogic'
@@ -43,6 +44,7 @@ function FilterBar(): JSX.Element {
onChange={(dateFrom, dateTo) => setDateFilter(dateFrom, dateTo)}
dataAttr="mcp-missing-capabilities-date-filter"
/>
+ <McpInternalUsersFilter dataAttr="mcp-missing-capabilities-test-account-filter" />
</div>
)
}
diff --git a/products/mcp_analytics/frontend/missingCapabilities/mcpMissingCapabilitiesLogic.test.ts b/products/mcp_analytics/frontend/missingCapabilities/mcpMissingCapabilitiesLogic.test.ts
index 20f47c1bdfc6..ef1b48a09e48 100644
--- a/products/mcp_analytics/frontend/missingCapabilities/mcpMissingCapabilitiesLogic.test.ts
+++ b/products/mcp_analytics/frontend/missingCapabilities/mcpMissingCapabilitiesLogic.test.ts
@@ -91,6 +91,11 @@ describe('mcpMissingCapabilitiesLogic', () => {
(l) => l.actions.setDateFilter('-7d', null),
{ dateRange: { date_from: '-7d', date_to: null }, offset: 0 },
],
+ [
+ 'the internal users toggle',
+ (l) => l.actions.setFilterTestAccounts(true),
+ { filterTestAccounts: true, offset: 0 },
+ ],
])('reloads from the first page on %s', async (_label, act, expected) => {
const mounted = mountLogic()
await expectLogic(mounted).toDispatchActions(['loadReportsSuccess'])
diff --git a/products/mcp_analytics/frontend/missingCapabilities/mcpMissingCapabilitiesLogic.ts b/products/mcp_analytics/frontend/missingCapabilities/mcpMissingCapabilitiesLogic.ts
index b9cb7dabbd0b..2cf527df0d7e 100644
--- a/products/mcp_analytics/frontend/missingCapabilities/mcpMissingCapabilitiesLogic.ts
+++ b/products/mcp_analytics/frontend/missingCapabilities/mcpMissingCapabilitiesLogic.ts
@@ -1,4 +1,4 @@
-import { MakeLogicType, actions, afterMount, kea, listeners, path, reducers } from 'kea'
+import { MakeLogicType, actions, afterMount, connect, kea, listeners, path, reducers } from 'kea'
import { loaders } from 'kea-loaders'
import { actionToUrl, router, urlToAction } from 'kea-router'
@@ -6,6 +6,9 @@ import api from 'lib/api'
import { urls } from 'scenes/urls'
import { MCPMissingCapabilitiesItem, NodeKind } from '~/queries/schema/schema-general'
+import { AnyPropertyFilter } from '~/types'
+
+import { mcpAnalyticsFiltersLogic } from '../mcpAnalyticsFiltersLogic'
export interface MCPMissingCapabilitiesDateFilter {
dateFrom: string | null
@@ -45,6 +48,7 @@ export function parsePersonProperties(raw: string): Record<string, unknown> {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface mcpMissingCapabilitiesLogicValues {
+ filterTestAccounts: boolean // mcpAnalyticsFiltersLogic
dateFilter: MCPMissingCapabilitiesDateFilter
hasNext: boolean
reports: MCPMissingCapabilitiesItem[]
@@ -55,6 +59,16 @@ export interface mcpMissingCapabilitiesLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface mcpMissingCapabilitiesLogicActions {
+ hydrateFilters: (
+ filterTestAccountsOverride: boolean | null,
+ propertyFilters: AnyPropertyFilter[]
+ ) => {
+ filterTestAccountsOverride: boolean | null
+ propertyFilters: AnyPropertyFilter[]
+ } // mcpAnalyticsFiltersLogic
+ setFilterTestAccounts: (filterTestAccounts: boolean | null) => {
+ filterTestAccounts: boolean | null
+ } // mcpAnalyticsFiltersLogic
loadMoreReports: () => {
value: true
}
@@ -125,6 +139,12 @@ export type mcpMissingCapabilitiesLogicType = MakeLogicType<
export const mcpMissingCapabilitiesLogic = kea<mcpMissingCapabilitiesLogicType>([
path(['products', 'mcp_analytics', 'frontend', 'missingCapabilities', 'mcpMissingCapabilitiesLogic']),
+ // The internal users toggle is shared with the other tabs, so it keeps its value across them.
+ connect(() => ({
+ values: [mcpAnalyticsFiltersLogic, ['filterTestAccounts']],
+ actions: [mcpAnalyticsFiltersLogic, ['hydrateFilters', 'setFilterTestAccounts']],
+ })),
+
actions({
// These declarations keep the generated loader actions callable without placeholder arguments.
loadReports: true,
@@ -138,7 +158,7 @@ export const mcpMissingCapabilitiesLogic = kea<mcpMissingCapabilitiesLogicType>(
reports: [
[] as MCPMissingCapabilitiesItem[],
{
- // First page / reset (a search or date change). Replaces the list.
+ // First page / reset (a filter change). Replaces the list.
loadReports: async (_, breakpoint) => {
if (values.search) {
await breakpoint(SEARCH_DEBOUNCE_MS)
@@ -146,6 +166,7 @@ export const mcpMissingCapabilitiesLogic = kea<mcpMissingCapabilitiesLogicType>(
const response = (await api.query({
kind: NodeKind.MCPMissingCapabilitiesQuery,
dateRange: { date_from: values.dateFilter.dateFrom, date_to: values.dateFilter.dateTo },
+ filterTestAccounts: values.filterTestAccounts,
search: values.search || undefined,
limit: MISSING_CAPABILITIES_PAGE_SIZE,
offset: 0,
@@ -156,21 +177,23 @@ export const mcpMissingCapabilitiesLogic = kea<mcpMissingCapabilitiesLogicType>(
},
// Load more: append the next page at offset = current length.
loadMoreReports: async () => {
- // Snapshot the list and the query before the await: if a reset (search or
- // date change) lands while this page is in flight, merging against the
+ // Snapshot the list and the query before the await: if a reset (a filter
+ // change) lands while this page is in flight, merging against the
// post-await list would corrupt it, so we both offset and merge from the
// snapshot and drop the page entirely if the query moved underneath us.
const baseReports = values.reports
- const { search, dateFilter } = values
+ const { search, dateFilter, filterTestAccounts } = values
const response = (await api.query({
kind: NodeKind.MCPMissingCapabilitiesQuery,
dateRange: { date_from: dateFilter.dateFrom, date_to: dateFilter.dateTo },
+ filterTestAccounts,
search: search || undefined,
limit: MISSING_CAPABILITIES_PAGE_SIZE,
offset: baseReports.length,
})) as { results?: MCPMissingCapabilitiesItem[]; has_next?: boolean }
if (
search !== values.search ||
+ filterTestAccounts !== values.filterTestAccounts ||
dateFilter.dateFrom !== values.dateFilter.dateFrom ||
dateFilter.dateTo !== values.dateFilter.dateTo
) {
@@ -219,13 +242,19 @@ export const mcpMissingCapabilitiesLogic = kea<mcpMissingCapabilitiesLogicType>(
}),
listeners(({ actions }) => ({
- // Both filters change the result set, so each reloads the first page.
+ // Each filter changes the result set, so each reloads the first page.
setSearch: () => {
actions.loadReports()
},
setDateFilter: () => {
actions.loadReports()
},
+ setFilterTestAccounts: () => {
+ actions.loadReports()
+ },
+ hydrateFilters: () => {
+ actions.loadReports()
+ },
})),
// Mirror the filters to the URL so they survive a refresh. date_from / date_to are the
diff --git a/products/mcp_analytics/mcp/tools.yaml b/products/mcp_analytics/mcp/tools.yaml
index e1c55d8b0b8e..e49aa83bb9af 100644
--- a/products/mcp_analytics/mcp/tools.yaml
+++ b/products/mcp_analytics/mcp/tools.yaml
@@ -339,8 +339,9 @@ wrappers:
$mcp_missing_capability report from the SDK's get_more_tools tool, including the report text, timestamp,
client label, conversation id, and person. Results are chronological because exact-text grouping would split
similar free-form requests. The query accepts a dateRange, case-insensitive text search, limit, and offset.
- The response's has_next field indicates whether more results remain. Use this tool to identify capabilities
- that agents need or to prioritize new MCP tools.
+ Set filterTestAccounts to true to exclude the project's internal and test users. The response's has_next
+ field indicates whether more results remain. Use this tool to identify capabilities that agents need or to
+ prioritize new MCP tools.
system_prompt_hint: MCP missing capabilities that agents reported, newest first
exclude_properties:
- response
diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.json
index f27fe63bcda9..546276098c73 100644
--- a/services/mcp/schema/generated-tool-definitions.json
+++ b/services/mcp/schema/generated-tool-definitions.json
@@ -12004,7 +12004,7 @@
"system_prompt_hint": "MCP client/harness breakdown — calls, error rate, sessions per harness"
},
"query-mcp-missing-capabilities": {
- "description": "Return capabilities that agents asked this MCP server for but could not access. Each row contains one $mcp_missing_capability report from the SDK's get_more_tools tool, including the report text, timestamp, client label, conversation id, and person. Results are chronological because exact-text grouping would split similar free-form requests. The query accepts a dateRange, case-insensitive text search, limit, and offset. The response's has_next field indicates whether more results remain. Use this tool to identify capabilities that agents need or to prioritize new MCP tools.",
+ "description": "Return capabilities that agents asked this MCP server for but could not access. Each row contains one $mcp_missing_capability report from the SDK's get_more_tools tool, including the report text, timestamp, client label, conversation id, and person. Results are chronological because exact-text grouping would split similar free-form requests. The query accepts a dateRange, case-insensitive text search, limit, and offset. Set filterTestAccounts to true to exclude the project's internal and test users. The response's has_next field indicates whether more results remain. Use this tool to identify capabilities that agents need or to prioritize new MCP tools.",
"category": "MCP analytics",
"feature": "mcp_analytics",
"summary": "List MCP missing-capability reports",
diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.json
index 91705934fe08..3d1255ddc454 100644
--- a/services/mcp/schema/tool-definitions-all.json
+++ b/services/mcp/schema/tool-definitions-all.json
@@ -12690,7 +12690,7 @@
"system_prompt_hint": "MCP client/harness breakdown — calls, error rate, sessions per harness"
},
"query-mcp-missing-capabilities": {
- "description": "Return capabilities that agents asked this MCP server for but could not access. Each row contains one $mcp_missing_capability report from the SDK's get_more_tools tool, including the report text, timestamp, client label, conversation id, and person. Results are chronological because exact-text grouping would split similar free-form requests. The query accepts a dateRange, case-insensitive text search, limit, and offset. The response's has_next field indicates whether more results remain. Use this tool to identify capabilities that agents need or to prioritize new MCP tools.",
+ "description": "Return capabilities that agents asked this MCP server for but could not access. Each row contains one $mcp_missing_capability report from the SDK's get_more_tools tool, including the report text, timestamp, client label, conversation id, and person. Results are chronological because exact-text grouping would split similar free-form requests. The query accepts a dateRange, case-insensitive text search, limit, and offset. Set filterTestAccounts to true to exclude the project's internal and test users. The response's has_next field indicates whether more results remain. Use this tool to identify capabilities that agents need or to prioritize new MCP tools.",
"category": "MCP analytics",
"feature": "mcp_analytics",
"summary": "List MCP missing-capability reports",
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index c73208d04f53..3a8b84b1c58b 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -56427,6 +56427,8 @@ export namespace Schemas {
export interface MCPMissingCapabilitiesQuery {
dateRange?: DateRange | null;
+ /** Exclude reports from the project's internal and test users. */
+ filterTestAccounts?: boolean | null;
kind?: 'MCPMissingCapabilitiesQuery';
/** Page size; defaults to 100, capped at 500. */
limit?: number | null;
diff --git a/services/mcp/src/tools/generated/mcp_analytics.ts b/services/mcp/src/tools/generated/mcp_analytics.ts
index 782de550961e..e905e570fc8f 100644
--- a/services/mcp/src/tools/generated/mcp_analytics.ts
+++ b/services/mcp/src/tools/generated/mcp_analytics.ts
@@ -420,6 +420,10 @@ const integer = z.coerce.number().int()
const MCPMissingCapabilitiesQuery = z.object({
dateRange: DateRange.optional(),
+ filterTestAccounts: z.coerce
+ .boolean()
+ .describe("Exclude reports from the project's internal and test users.")
+ .optional(),
kind: z.literal('MCPMissingCapabilitiesQuery').default('MCPMissingCapabilitiesQuery'),
limit: integer.describe('Page size; defaults to 100, capped at 500.').optional(),
offset: integer
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-mcp-missing-capabilities.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-mcp-missing-capabilities.json
index 3d982961b15b..6da54d4eaae5 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/query-mcp-missing-capabilities.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/query-mcp-missing-capabilities.json
@@ -95,6 +95,10 @@
},
"type": "object"
},
+ "filterTestAccounts": {
+ "description": "Exclude reports from the project's internal and test users.",
+ "type": "boolean"
+ },
"kind": {
"const": "MCPMissingCapabilitiesQuery",
"default": "MCPMissingCapabilitiesQuery",