: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(webmcp): stop agent tool failures from filing error tracking issues (#118913)
posthog[bot]377fe09ed434
diff --git a/frontend/src/loadPostHogJS.tsx b/frontend/src/loadPostHogJS.tsxindex a2eeb64b9350..e1c8755634be 100644--- a/frontend/src/loadPostHogJS.tsx+++ b/frontend/src/loadPostHogJS.tsx@@ -14,6 +14,8 @@ import { getAppContext, isHobbyDeployment } from 'lib/utils/getAppContext'import { redactMetricVariableUrls } from 'lib/utils/metricVariableUrlRedaction'import { identifyInstanceInPostHog, identifyUserInPostHog } from 'lib/utils/posthogIdentity'+import { dropWebMCPToolErrors } from 'products/webmcp/frontend/webmcpToolError'+import { startDetachedElementTracking } from './detachedElementTracker'export const SDK_DEFAULTS_DATE = '2026-05-30'@@ -131,6 +133,7 @@ export function loadPostHogJS(): void {dropHandledAuthGateExceptions,dropUnactionableNetworkExceptions,dropInjectedScriptReferenceErrors,+ dropWebMCPToolErrors,redactMetricVariableUrls,// A page in a frame counts its own pageviews, so its events say so and analysis can filter them.// `register` would persist the property in storage the main window shares, so it is stamped per event.diff --git a/products/webmcp/frontend/logics/webmcpLogic.test.ts b/products/webmcp/frontend/logics/webmcpLogic.test.tsindex 90c14e7703c3..5b5d76c481e3 100644--- a/products/webmcp/frontend/logics/webmcpLogic.test.ts+++ b/products/webmcp/frontend/logics/webmcpLogic.test.ts@@ -10,6 +10,7 @@ import { useMocks } from '~/mocks/jest'import { initKeaTests } from '~/test/init'import type { TeamType } from '~/types'+import { WebMCPToolError } from '../webmcpToolError'import { webmcpLogic } from './webmcpLogic'interface RegisteredTool {@@ -66,7 +67,9 @@ describe('webmcpLogic', () => {expect(tool.name).toEqual('exec')await expect(tool.execute({ command: 'search insights' })).resolves.toEqual('insight-get')- await expect(tool.execute({ command: 'call broken-tool {}' })).rejects.toThrow('Tool failed')+ const failedCall = tool.execute({ command: 'call broken-tool {}' })+ await expect(failedCall).rejects.toThrow('Tool failed')+ await expect(failedCall).rejects.toBeInstanceOf(WebMCPToolError)expect(postedCommands).toEqual(['search insights', 'call broken-tool {}'])})diff --git a/products/webmcp/frontend/logics/webmcpLogic.ts b/products/webmcp/frontend/logics/webmcpLogic.tsindex 7c8c90294230..f29cf539b71a 100644--- a/products/webmcp/frontend/logics/webmcpLogic.ts+++ b/products/webmcp/frontend/logics/webmcpLogic.ts@@ -9,6 +9,7 @@ import type { PreflightStatus, UserType } from '~/types'import { webmcpExecCreate, webmcpToolRetrieve } from '../generated/api'import type { WebMCPExecResultApi } from '../generated/api.schemas'+import { WebMCPToolError } from '../webmcpToolError'interface WebMCPToolAnnotations {readOnlyHint?: boolean@@ -130,7 +131,7 @@ export const webmcpLogic = kea<webmcpLogicType>([)const text = formatExecResult(result)if (result.is_error) {- throw new Error(text)+ throw new WebMCPToolError(text)}return text},diff --git a/products/webmcp/frontend/webmcpToolError.test.ts b/products/webmcp/frontend/webmcpToolError.test.tsnew file mode 100644index 000000000000..ef612d60e495--- /dev/null+++ b/products/webmcp/frontend/webmcpToolError.test.ts@@ -0,0 +1,41 @@+import type { CaptureResult } from 'posthog-js'++import { WebMCPToolError, dropWebMCPToolErrors } from './webmcpToolError'++function exceptionEvent(properties: Record<string, unknown>): CaptureResult {+ return { uuid: 'uuid', event: '$exception', properties }+}++const toolCallException = {+ $exception_source: 'mcp.tool_call',+ $mcp_interface: 'webmcp',+}++describe('dropWebMCPToolErrors', () => {+ test.each([+ {+ name: 'a failed PostHog command',+ properties: {+ ...toolCallException,+ $exception_list: [{ type: new WebMCPToolError('Not found').name, value: 'Not found' }],+ },+ dropped: true,+ },+ {+ name: 'a transport failure in a tool call',+ properties: {+ ...toolCallException,+ $exception_list: [{ type: 'TypeError', value: 'Failed to read response body' }],+ },+ dropped: false,+ },+ {+ name: 'an app exception with the same error type',+ properties: { $exception_list: [{ type: new WebMCPToolError('Not found').name, value: 'Not found' }] },+ dropped: false,+ },+ ])('handles $name', ({ properties, dropped }) => {+ const event = exceptionEvent(properties)+ expect(dropWebMCPToolErrors(event)).toEqual(dropped ? null : event)+ })+})diff --git a/products/webmcp/frontend/webmcpToolError.ts b/products/webmcp/frontend/webmcpToolError.tsnew file mode 100644index 000000000000..5e4ec1bc1c83--- /dev/null+++ b/products/webmcp/frontend/webmcpToolError.ts@@ -0,0 +1,28 @@+import type { BeforeSendFn } from 'posthog-js'++// posthog-js reads the name, and minification would rename the class.+const WEBMCP_TOOL_ERROR_NAME = 'WebMCPToolError'++/** A PostHog command that failed, for example bad HogQL or a missing resource. The agent gets the message. */+export class WebMCPToolError extends Error {+ constructor(message: string) {+ super(message)+ this.name = WEBMCP_TOOL_ERROR_NAME+ }+}++/**+ * posthog-js `capture_webmcp` captures an exception for each failed tool call. A failed command is an agent+ * mistake, not an app error, and the `$mcp_tool_call` event already records it. Transport failures still pass.+ */+export const dropWebMCPToolErrors: BeforeSendFn = (event) => {+ if (+ event.event === '$exception' &&+ event.properties?.$exception_source === 'mcp.tool_call' &&+ event.properties.$mcp_interface === 'webmcp' &&+ event.properties.$exception_list?.[0]?.type === WEBMCP_TOOL_ERROR_NAME+ ) {+ return null+ }+ return event+}