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): show failed tool calls as errors in mcp ui apps (#114563)

Sam Penningtona4b9e836d858
diff --git a/services/mcp/src/ui-apps/analytics/posthog.ts b/services/mcp/src/ui-apps/analytics/posthog.ts
index 6694cff76cbf..be2a4832e5d4 100644
--- a/services/mcp/src/ui-apps/analytics/posthog.ts
+++ b/services/mcp/src/ui-apps/analytics/posthog.ts
@@ -144,12 +144,14 @@ export function captureToolResult(params: {
hasAppData?: boolean | undefined
contentLength?: number | undefined
rendered?: boolean | undefined
+ isError?: boolean | undefined
}): void {
capture('mcp_ui_app_tool_result', {
has_structured_content: params.hasStructuredContent,
has_app_data: params.hasAppData,
content_length: params.contentLength,
rendered: params.rendered,
+ is_error: params.isError,
})
}
diff --git a/services/mcp/src/ui-apps/hooks/useToolResult.ts b/services/mcp/src/ui-apps/hooks/useToolResult.ts
index e80f17819d9c..f9f219ce4158 100644
--- a/services/mcp/src/ui-apps/hooks/useToolResult.ts
+++ b/services/mcp/src/ui-apps/hooks/useToolResult.ts
@@ -125,6 +125,8 @@ const WAIT_TIMEOUT_MESSAGES: Record<Exclude<WaitPhase, 'settled'>, string> = {
const PARSE_ERROR_MESSAGE = "Couldn't read the results for this app. Re-run the tool to try again."
+const TOOL_ERROR_MESSAGE = 'The tool call failed, so there are no results to show. Re-run the tool to try again.'
+
/**
* Parse tool result content, preferring structuredContent over the `_meta`
* fallback. Never falls back to text content.
@@ -241,7 +243,7 @@ export function useToolResult<T = unknown>({
appInstance.ontoolresult = (params) => {
try {
const meta = (params as { _meta?: Record<string, unknown> })._meta
- const parsed = parseToolResultContent<T>(params.structuredContent, meta)
+ const parsed = params.isError ? null : parseToolResultContent<T>(params.structuredContent, meta)
// Extract analytics metadata and identify the user
const analytics = extractAnalytics(parsed)
@@ -257,13 +259,14 @@ export function useToolResult<T = unknown>({
hasAppData: meta?.[APP_DATA_META_KEY] !== undefined && meta[APP_DATA_META_KEY] !== null,
contentLength: params.content?.length,
rendered: parsed !== null,
+ isError: !!params.isError,
})
if (parsed !== null) {
setData(parsed)
setParseError(null)
} else {
- const err = new Error(PARSE_ERROR_MESSAGE)
+ const err = new Error(params.isError ? TOOL_ERROR_MESSAGE : PARSE_ERROR_MESSAGE)
console.error('[PostHog MCP App UI] Parse error:', err)
setParseError(err)
}