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): keep claude.ai exec schema under registry cap (#87046)

Georgiy Tarasovbc6f005d387b
diff --git a/.agents/skills/implementing-mcp-tools/SKILL.md b/.agents/skills/implementing-mcp-tools/SKILL.md
index e5cc480fe337..7b1f44f4e3a4 100644
--- a/.agents/skills/implementing-mcp-tools/SKILL.md
+++ b/.agents/skills/implementing-mcp-tools/SKILL.md
@@ -79,6 +79,24 @@ Violations fail the build.
- **Length**: 52 characters or fewer
- **Convention**: `domain-action`, e.g. `cohorts-create`, `dashboard-get`, `feature-flags-list`
+#### Keep action verbs out of compact tool domains
+
+The single-exec prompt builds its compact domain index with
+`ToolDomainExtractor`. Large families can split at an intermediate segment.
+Without action trimming, `experiment-freeze-exposure` can advertise the
+redundant domain `experiment-freeze` instead of `experiment`.
+
+Whenever you add or rename an action tool, check the
+[`TRAILING_ACTIONS`](services/mcp/src/lib/instructions.ts) set in the
+same change. If a rendered domain can end in an operation verb that is not
+already present, add the verb. Cover it in
+`services/mcp/tests/unit/instructions.test.ts`. This applies even when the verb
+is not the final segment of the full tool name.
+
+Add operation verbs such as `freeze`, `publish`, or `emit`. Do not add resource
+or capability nouns such as `config`, `logs`, `stats`, or `schedule` merely to
+make the prompt shorter; those remain useful discovery domains.
+
### Feature identifiers
- **Format**: lowercase snake*case — only `[a-z0-9*]`, must start with a letter
diff --git a/services/mcp/src/lib/instructions-formatter.ts b/services/mcp/src/lib/instructions-formatter.ts
index d9b28ea05274..ac82d7211901 100644
--- a/services/mcp/src/lib/instructions-formatter.ts
+++ b/services/mcp/src/lib/instructions-formatter.ts
@@ -146,6 +146,15 @@ export class InstructionsFormatter {
})
}
+ // URL rules are task-specific and load on demand instead of consuming Claude's capped input schema.
+ entries.push({
+ id: 'urls',
+ kind: 'guide',
+ title: 'URL patterns',
+ description: 'Load before writing any PostHog app link or URL.',
+ content: this.compose([URL_PATTERNS], ctx, { compact: false }),
+ })
+
entries.push({
id: 'feedback',
kind: 'guide',
@@ -187,7 +196,6 @@ export class InstructionsFormatter {
BASIC_FUNCTIONALITY,
TOOL_SEARCH,
ENV_CONTEXT,
- URL_PATTERNS,
],
renderCtx,
{
diff --git a/services/mcp/src/lib/instructions.ts b/services/mcp/src/lib/instructions.ts
index 3eb5520d9656..e45fb299e68d 100644
--- a/services/mcp/src/lib/instructions.ts
+++ b/services/mcp/src/lib/instructions.ts
@@ -150,6 +150,29 @@ export class ToolDomainExtractor {
'retrieve',
'destroy',
'run',
+ 'archive',
+ 'calculate',
+ 'copy',
+ 'discard',
+ 'duplicate',
+ 'edit',
+ 'emit',
+ 'enable',
+ 'end',
+ 'freeze',
+ 'launch',
+ 'patch',
+ 'pause',
+ 'publish',
+ 'record',
+ 'reset',
+ 'restore',
+ 'resume',
+ 'ship',
+ 'show',
+ 'test',
+ 'unarchive',
+ 'unfreeze',
])
private readonly items: ToolItem[]
diff --git a/services/mcp/tests/unit/__snapshots__/instructions/exec-command-reference-claude-chat.txt b/services/mcp/tests/unit/__snapshots__/instructions/exec-command-reference-claude-chat.txt
index 3dbb98de3c47..d5b6f1daf97f 100644
--- a/services/mcp/tests/unit/__snapshots__/instructions/exec-command-reference-claude-chat.txt
+++ b/services/mcp/tests/unit/__snapshots__/instructions/exec-command-reference-claude-chat.txt
@@ -17,6 +17,7 @@ Load all matching topics in one `learn` command first. Topics are cumulative.
- analytics: Query or analyze PostHog data, metrics, and events.
- visualizations: Create or render a visualization.
+- urls: Load before writing any PostHog app link or URL.
- feedback: Send feedback about PostHog.
**SCHEMA DRILL-DOWN RULE — HARD REQUIREMENT**
@@ -158,16 +159,4 @@ Defined group types: organization, project
You are currently in project "My App" (id: 1, token: token_1) within organization "Acme" (id: org_1).
Project timezone: America/New_York.
-The user's name is Jane Doe ([email protected]).
-
-### URL patterns
-
-PostHog app links must be full URLs (origin + path) — bare paths aren't clickable in MCP clients like Cursor or Claude Desktop. Use Markdown with descriptive anchor text, e.g. `[Cohorts](https://us.posthog.com/project/1/cohorts)`. Never include `/-/`.
-
-Choose the link source in this order:
-
-1. If a tool result has a `*url` field (e.g. `_posthogUrl`), surface it verbatim — never rewrite or strip it.
-2. Only when you actually want to link a specific entity (or the user asks for a link) and it has no `_posthogUrl`, call `generate-app-url` and surface the `url` verbatim — don't hand-write slugs or retype IDs into paths, both are easy to get wrong. Don't fetch a link just because a result has an ID.
-3. Only for genuinely static pages not covered by `generate-app-url` (some settings / data-management pages), build the link from the Base URL in the active-environment block (don't double-prefix):
- - Project-scoped paths → Base URL + `/project/:id`: `/settings/<section-id>` (hyphenated, e.g. `/settings/environment-replay`, `/settings/user-api-keys`), `/data-management/events`, `/data-management/properties`.
- - Org-/account-level paths → Base URL only (no `/project/:id`): first segment `organization`, `me`, `account`, or `instance` — e.g. billing is `/organization/billing`.
\ No newline at end of file
+The user's name is Jane Doe ([email protected]).
\ No newline at end of file
diff --git a/services/mcp/tests/unit/instructions-formatter-snapshot.test.ts b/services/mcp/tests/unit/instructions-formatter-snapshot.test.ts
index e067c3492e3e..ae65dc2057fd 100644
--- a/services/mcp/tests/unit/instructions-formatter-snapshot.test.ts
+++ b/services/mcp/tests/unit/instructions-formatter-snapshot.test.ts
@@ -240,8 +240,7 @@ describe('InstructionsFormatter prompt snapshots', () => {
expect(rendered.length).toBeLessThanOrEqual(MCP_INSTRUCTIONS_CHAR_BUDGET)
// Domains past the old cutoff point, i.e. the ones a truncated payload lost.
- // (`workflow` singular: the extractor renders a family's shortest spelling.)
- for (const domain of ['query', 'scout', 'session-recording', 'survey', 'web-analytics', 'workflow']) {
+ for (const domain of ['query', 'scout', 'session-recording', 'survey', 'web-analytics', 'workflows']) {
expect(domains).toContain(domain)
}
})
diff --git a/services/mcp/tests/unit/instructions-formatter.test.ts b/services/mcp/tests/unit/instructions-formatter.test.ts
index d6edeabbe4b0..4ff2de4d4cd2 100644
--- a/services/mcp/tests/unit/instructions-formatter.test.ts
+++ b/services/mcp/tests/unit/instructions-formatter.test.ts
@@ -265,6 +265,7 @@ describe('InstructionsFormatter', () => {
)
expect(result).toContain('- analytics:')
expect(result).toContain('- visualizations:')
+ expect(result).toContain('- urls:')
expect(result).toContain('- feedback:')
expect(result).toContain('SCHEMA DRILL-DOWN RULE')
expect(result).toContain('**Data discovery:**')
@@ -280,12 +281,13 @@ describe('InstructionsFormatter', () => {
expect(result).not.toContain('### Retrieving data')
expect(result).not.toContain('### Examples')
expect(result).not.toContain('### Rendering visualizations')
+ expect(result).not.toContain('### URL patterns')
expect(result).not.toContain('### Sharing feedback on PostHog')
expect(result).not.toContain('- `query-trends` — time series')
expect(result).not.toMatch(/\{help_topics\}|\{query_tools\}|\{metadata\}|\{defined_groups\}|\{guidelines\}/)
})
- it('combines analytics guidance and examples in one learning topic', () => {
+ it('builds optional learning topics from their full guidance', () => {
const formatter = new InstructionsFormatter()
const entries = formatter.buildClaudeExecHelpEntries(fullCtx)
const analytics = entries.find((entry) => entry.id === 'analytics')
@@ -293,6 +295,7 @@ describe('InstructionsFormatter', () => {
expect(entries.map(({ id, kind }) => ({ id, kind }))).toEqual([
{ id: 'analytics', kind: 'guide' },
{ id: 'visualizations', kind: 'guide' },
+ { id: 'urls', kind: 'guide' },
{ id: 'feedback', kind: 'guide' },
])
expect(analytics?.content).toContain('### Retrieving data')
@@ -301,6 +304,7 @@ describe('InstructionsFormatter', () => {
expect(entries.find((entry) => entry.id === 'visualizations')?.content).toContain(
'### Rendering visualizations'
)
+ expect(entries.find((entry) => entry.id === 'urls')?.content).toContain('### URL patterns')
expect(entries.find((entry) => entry.id === 'feedback')?.content).toContain(
'### Sharing feedback on PostHog'
)
@@ -315,11 +319,13 @@ describe('InstructionsFormatter', () => {
expect(formatter.buildClaudeExecHelpEntries(ctx).map((entry) => entry.id)).toEqual([
'analytics',
+ 'urls',
'feedback',
])
const result = formatter.buildClaudeExecCommandReference(ctx)
expect(result).toContain('- analytics:')
expect(result).not.toContain('- visualizations:')
+ expect(result).toContain('- urls:')
expect(result).toContain('- feedback:')
})
})
diff --git a/services/mcp/tests/unit/instructions.test.ts b/services/mcp/tests/unit/instructions.test.ts
index 78904bebd21d..88853b519ba8 100644
--- a/services/mcp/tests/unit/instructions.test.ts
+++ b/services/mcp/tests/unit/instructions.test.ts
@@ -151,6 +151,42 @@ describe('buildToolDomainsBlock', () => {
expect(result).toContain('- feature-flag')
})
+ it('trims lifecycle and capability actions from singleton domains', () => {
+ const trailingActions = [
+ 'archive',
+ 'calculate',
+ 'copy',
+ 'discard',
+ 'duplicate',
+ 'edit',
+ 'emit',
+ 'enable',
+ 'end',
+ 'freeze',
+ 'launch',
+ 'patch',
+ 'pause',
+ 'publish',
+ 'record',
+ 'reset',
+ 'restore',
+ 'resume',
+ 'ship',
+ 'show',
+ 'test',
+ 'unarchive',
+ 'unfreeze',
+ ]
+ const tools = trailingActions.map((action, index) => ({
+ name: `resource${index}-${action}`,
+ category: 'Test',
+ }))
+
+ expect(buildToolDomainsCompact(tools).split('|')).toEqual(
+ trailingActions.map((_, index) => `resource${index}`).sort()
+ )
+ })
+
it('should return empty string for empty array', () => {
expect(buildToolDomainsBlock([])).toBe('')
})
@@ -182,10 +218,10 @@ describe('buildToolDomainsCompact', () => {
const tools = [
...Array.from({ length: 10 }, (_, i) => ({ name: `scout-config-${i}`, category: 'Signals' })),
...Array.from({ length: 10 }, (_, i) => ({ name: `scout-notes-${i}`, category: 'Signals' })),
- ...Array.from({ length: 10 }, (_, i) => ({ name: `scout-record-${i}`, category: 'Signals' })),
+ ...Array.from({ length: 10 }, (_, i) => ({ name: `scout-history-${i}`, category: 'Signals' })),
{ name: 'survey-create', category: 'Surveys' },
]
- expect(buildToolDomainsCompact(tools)).toBe('scout-config|scout-notes|scout-record|survey')
+ expect(buildToolDomainsCompact(tools)).toBe('scout-config|scout-history|scout-notes|survey')
const budgeted = buildToolDomainsCompact(tools, 20)
expect(budgeted).toBe('scout|survey')