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): expose error issue rows to text-only clients (#107135)

posthog[bot]f048c7da779d
diff --git a/docs/published/handbook/engineering/ai/implementing-mcp-tools.md b/docs/published/handbook/engineering/ai/implementing-mcp-tools.md
index 969d81d48563..cea27519f224 100644
--- a/docs/published/handbook/engineering/ai/implementing-mcp-tools.md
+++ b/docs/published/handbook/engineering/ai/implementing-mcp-tools.md
@@ -358,6 +358,13 @@ Product teams own their definitions and control which operations are exposed as
Unknown keys are rejected at build time (Zod `.strict()`) to catch typos early.
+ For list tools with a UI app, set `response.text_include` to the dot-path fields an agent
+ needs from each result row. This adds a compact text response for clients that cannot read
+ `structuredContent`, while preserving the full structured payload for the app and explicit
+ JSON output. For example, the error issue list includes issue IDs, status, severity, timestamps,
+ impact counts, and links, but leaves volume buckets to the app. Pagination metadata stays in
+ the text response, and `results[0]` explicitly identifies an empty page.
+
For generated list apps, `generate:ui-apps` also checks `detail_tool` and the
`detail_args` keys against the tool's input schema snapshot, so a wrong argument
name fails generation instead of silently dropping the argument at runtime.
diff --git a/products/error_tracking/mcp/tools.yaml b/products/error_tracking/mcp/tools.yaml
index c9294008f495..c75a76dd8cd2 100644
--- a/products/error_tracking/mcp/tools.yaml
+++ b/products/error_tracking/mcp/tools.yaml
@@ -504,3 +504,14 @@ tools:
- source
- assignee
- aggregations
+ text_include:
+ - id
+ - name
+ - status
+ - severity
+ - first_seen
+ - last_seen
+ - aggregations.occurrences
+ - aggregations.users
+ - aggregations.sessions
+ - _posthogUrl
diff --git a/services/mcp/src/lib/build-tool-result.ts b/services/mcp/src/lib/build-tool-result.ts
index ab209560438e..e355909f8aad 100644
--- a/services/mcp/src/lib/build-tool-result.ts
+++ b/services/mcp/src/lib/build-tool-result.ts
@@ -4,7 +4,7 @@ import { type DiscoveryHint, type DiscoveryHintKind, getDiscoveryHint, isEmptyTo
import { estimateTokens } from '@/lib/estimate-tokens'
import { formatResponse } from '@/lib/response'
import { isPrepareConfirmedActionResult } from '@/tools/confirmed-action-runtime'
-import { POSTHOG_FORMATTED_RESULTS_OVERRIDE_KEY, POSTHOG_META_KEY } from '@/tools/types'
+import { POSTHOG_FORMATTED_RESULTS_OVERRIDE_KEY, POSTHOG_META_KEY, POSTHOG_TEXT_PROJECTION_KEY } from '@/tools/types'
import { APP_DATA_META_KEY, type AnalyticsMetadata, type WithAnalytics } from '@/ui-apps/types'
export interface ToolResultMeta {
@@ -188,6 +188,8 @@ export function buildToolResultPayload(opts: BuildToolResultOptions): ToolResult
const effectiveOutputFormat = callerOutputFormat ?? toolMeta?.[POSTHOG_META_KEY]?.outputFormat
const useJson = effectiveOutputFormat === 'json'
const callerWantsJson = callerOutputFormat === 'json'
+ const isTextProjection =
+ !isStringResult && (handlerResult as Record<string, unknown> | null)?.[POSTHOG_TEXT_PROJECTION_KEY] === true
let structuredContent: WithAnalytics<typeof rawResult> | typeof rawResult = rawResult
if (hasUiResource && !isStringResult) {
@@ -226,7 +228,7 @@ export function buildToolResultPayload(opts: BuildToolResultOptions): ToolResult
const body = structuredContentOnly
? STRUCTURED_CONTENT_ONLY_TEXT
- : ((includeAppData && useJson ? undefined : formattedResults) ??
+ : ((useJson && (includeAppData || isTextProjection) ? undefined : formattedResults) ??
(useJson ? JSON.stringify(rawResult) : formatResponse(rawResult)))
const footers: string[] = []
diff --git a/services/mcp/src/tools/generated/error_tracking.ts b/services/mcp/src/tools/generated/error_tracking.ts
index 6bb5d39778e4..6d7228cb84cc 100644
--- a/services/mcp/src/tools/generated/error_tracking.ts
+++ b/services/mcp/src/tools/generated/error_tracking.ts
@@ -4,7 +4,7 @@ import { z } from 'zod'
import type { Schemas } from '@/api/generated'
import * as orvalSchemas from '@/generated/error_tracking/api'
import { withUiApp } from '@/resources/ui-apps'
-import { withPostHogUrl, pickResponseFields, type WithPostHogUrl } from '@/tools/tool-utils'
+import { withPostHogUrl, pickResponseFields, withTextProjection, type WithPostHogUrl } from '@/tools/tool-utils'
import type { Context, ToolBase, ZodObjectAny } from '@/tools/types'
const ErrorTrackingAssignmentRulesCreateSchema = () => {
@@ -929,17 +929,31 @@ const queryErrorTrackingIssuesList = (): ToolBase<
])
),
} as typeof result
- return await withPostHogUrl(
- context,
- {
- ...filtered,
- results: await Promise.all(
- (filtered.results ?? []).map((item) =>
- withPostHogUrl(context, item, `/error_tracking/${item.id}`)
- )
- ),
- },
- '/error_tracking'
+ return withTextProjection(
+ await withPostHogUrl(
+ context,
+ {
+ ...filtered,
+ results: await Promise.all(
+ (filtered.results ?? []).map((item) =>
+ withPostHogUrl(context, item, `/error_tracking/${item.id}`)
+ )
+ ),
+ },
+ '/error_tracking'
+ ),
+ [
+ 'id',
+ 'name',
+ 'status',
+ 'severity',
+ 'first_seen',
+ 'last_seen',
+ 'aggregations.occurrences',
+ 'aggregations.users',
+ 'aggregations.sessions',
+ '_posthogUrl',
+ ]
)
},
})
diff --git a/services/mcp/src/tools/tool-utils.ts b/services/mcp/src/tools/tool-utils.ts
index 22353aed744d..86a817ab858b 100644
--- a/services/mcp/src/tools/tool-utils.ts
+++ b/services/mcp/src/tools/tool-utils.ts
@@ -1,5 +1,10 @@
import { formatResponse } from '@/lib/response'
-import { POSTHOG_FORMATTED_RESULTS_OVERRIDE_KEY, POSTHOG_INFORMATIONAL_RESPONSE_KEY, type Context } from '@/tools/types'
+import {
+ POSTHOG_FORMATTED_RESULTS_OVERRIDE_KEY,
+ POSTHOG_INFORMATIONAL_RESPONSE_KEY,
+ POSTHOG_TEXT_PROJECTION_KEY,
+ type Context,
+} from '@/tools/types'
/**
* Adds a _posthogUrl field to a result. For object results it's a sibling field; for raw
@@ -114,6 +119,7 @@ export function withTextProjection<T>(result: T, fields: string[]): T {
return result
}
const wrappedResult = { ...source }
+ Object.defineProperty(wrappedResult, POSTHOG_TEXT_PROJECTION_KEY, { value: true, enumerable: false })
let formattedResult: string | undefined
Object.defineProperty(wrappedResult, POSTHOG_FORMATTED_RESULTS_OVERRIDE_KEY, {
enumerable: false,
diff --git a/services/mcp/src/tools/types.ts b/services/mcp/src/tools/types.ts
index 02bf21d49159..30992824be8f 100644
--- a/services/mcp/src/tools/types.ts
+++ b/services/mcp/src/tools/types.ts
@@ -187,6 +187,7 @@ export type ToolUiMeta = {
export const POSTHOG_META_KEY = 'com.posthog.mcp' as const
export const POSTHOG_FORMATTED_RESULTS_OVERRIDE_KEY = '__formatted_results_override' as const
export const POSTHOG_INFORMATIONAL_RESPONSE_KEY = '__informational_response' as const
+export const POSTHOG_TEXT_PROJECTION_KEY = '__text_projection' as const
export type PostHogToolMeta = {
/**
diff --git a/services/mcp/tests/unit/exec.test.ts b/services/mcp/tests/unit/exec.test.ts
index 361fd5761388..d9ecbb11f6d3 100644
--- a/services/mcp/tests/unit/exec.test.ts
+++ b/services/mcp/tests/unit/exec.test.ts
@@ -1,5 +1,5 @@
import guidelines from '@shared/guidelines.md'
-import { describe, expect, it } from 'vitest'
+import { describe, expect, it, vi } from 'vitest'
import { parse as parseYaml } from 'yaml'
import { z } from 'zod'
@@ -80,6 +80,65 @@ function createExec(
}
describe('exec tool', () => {
+ describe('error issue rows for text-only callers', () => {
+ const issue = {
+ id: '00000000-0000-4000-8000-000000000123',
+ name: 'ExampleError',
+ status: 'active',
+ severity: 'high',
+ first_seen: '2026-01-02T12:00:00Z',
+ last_seen: '2026-01-03T12:00:00Z',
+ aggregations: { occurrences: 12, users: 4, sessions: 5, volumeRange: [3, 9] },
+ }
+
+ it.each([false, true])('exposes issue rows and pagination through exec (empty=%s)', async (empty) => {
+ const rows = empty ? [] : [issue]
+ const request = vi.fn().mockResolvedValue({
+ results: rows,
+ hasMore: !empty,
+ limit: 1,
+ offset: 0,
+ ...(!empty ? { nextOffset: 1 } : {}),
+ })
+ const context = {
+ ...mockContext,
+ stateManager: { getProjectId: async () => '1' },
+ api: { request, getProjectBaseUrl: () => 'https://example.com/project/1' },
+ } as unknown as Context
+ const tool = makeMockTool(GENERATED_TOOL_MAP['query-error-tracking-issues-list']!())
+ const exec = createExecTool([tool], context, '', '', 'posthog-code')
+ const params = { limit: 1 }
+ const result = (await exec.handler(context, {
+ command: `call query-error-tracking-issues-list ${JSON.stringify(params)}`,
+ })) as ToolResultPayload
+ const text = result.content.map((block) => block.text).join('\n')
+
+ expect(request).toHaveBeenCalledWith(expect.objectContaining({ body: expect.objectContaining(params) }))
+ expect(text).not.toContain(STRUCTURED_CONTENT_ONLY_TEXT)
+ expect(text).toContain(`results[${rows.length}]`)
+ expect(text).toContain(`hasMore: ${!empty}`)
+ expect(text).toContain('offset: 0')
+ if (!empty) {
+ expect(text).toContain(issue.id)
+ expect(text).toContain(issue.name)
+ expect(text).toContain('occurrences: 12')
+ expect(text).toContain('users: 4')
+ expect(text).toContain('sessions: 5')
+ expect(text).toContain(issue.last_seen)
+ expect(text).toContain('nextOffset: 1')
+ expect(text).not.toContain('volumeRange')
+ }
+ expect(result.structuredContent).toBeUndefined()
+ expect(result._meta?.[APP_DATA_META_KEY]).toMatchObject({ results: rows })
+ expect(result._meta?.ui).toEqual(tool._meta?.ui)
+
+ const jsonResult = (await exec.handler(context, {
+ command: `call --json query-error-tracking-issues-list ${JSON.stringify(params)}`,
+ })) as ToolResultPayload
+ expect(JSON.parse(jsonResult.content[0]!.text)).toMatchObject({ results: rows })
+ })
+ })
+
describe('help command', () => {
it('lists available commands and their argument shapes', async () => {
const result = await createExec().handler(mockContext, { command: 'help' })