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): avoid repeated info calls (#70354)

Georgiy Tarasov3547a5381aa8
diff --git a/services/mcp/src/templates/sections/cli-examples.md b/services/mcp/src/templates/sections/cli-examples.md
index 45178ddb4b09..1fa238c4c50c 100644
--- a/services/mcp/src/templates/sections/cli-examples.md
+++ b/services/mcp/src/templates/sections/cli-examples.md
@@ -27,13 +27,13 @@ Assistant: Now I have both schemas. Let me start by searching for existing reven
<bad-example>
User: Show me our feature flags
Assistant: [Directly calls posthog:exec({ "command": "call feature-flag-get-all {}" }) with guessed parameters]
-WRONG — You must run `info feature-flag-get-all` FIRST to check the schema
+WRONG: Run `info feature-flag-get-all` once when its schema is missing.
</bad-example>
<bad-example>
User: Query our events
Assistant: [Calls three tools in parallel without any `info` calls first]
-WRONG — You must run `info` for ALL tools before making ANY `call` commands
+WRONG: Run `info` once for each missing schema.
</bad-example>
<bad-example>
diff --git a/services/mcp/src/templates/sections/exec-tool-blurb.md b/services/mcp/src/templates/sections/exec-tool-blurb.md
index 911466645ff7..9466eb343913 100644
--- a/services/mcp/src/templates/sections/exec-tool-blurb.md
+++ b/services/mcp/src/templates/sections/exec-tool-blurb.md
@@ -4,27 +4,27 @@ PostHog: dashboards, insights, funnels, SQL, experiments, surveys, replay, error
Pass CLI-style commands in the `command` parameter for all PostHog interactions.
-**MANDATORY — HARD REQUIREMENTS**
+**Requirements**
-1. Discover tools first with `search` or `tools`.
-2. Run `info <tool_name>` BEFORE every `call <tool_name> <json>`.
+1. Find unknown tools with `search` or `tools`.
+2. Run `info <tool_name>` once if its schema is not in context. Reuse it unless the tool changes or a schema error occurs.
-BLOCKING, like reading a file before editing it. Tool names and schemas are NOT predictable — never assume.
+Never guess a schema or run `info` before every call.
**Commands (in order):**
```text
-# 1. Discover (preferred: focused regex over name/title/description)
+# 1. Find unknown tools
posthog:exec({ "command": "search <regex>" })
posthog:exec({ "command": "tools" }) # fallback: list all
-# 2. Check description + top-level schema (REQUIRED before call)
+# 2. Inspect once if the schema is missing
posthog:exec({ "command": "info <tool_name>" })
# 3. Drill into complex fields — REQUIRED for any field with a `hint`
posthog:exec({ "command": "schema <tool_name> <field_path>" })
-# 4. Call the tool
+# 4. Call; reuse the schema
posthog:exec({ "command": "call <tool_name> <json_input>" })
posthog:exec({ "command": "call --json <tool_name> <json_input>" })
```
diff --git a/services/mcp/tests/unit/__snapshots__/instructions/exec-command-reference-full.txt b/services/mcp/tests/unit/__snapshots__/instructions/exec-command-reference-full.txt
index 406a9427c07e..e58bbdb58364 100644
--- a/services/mcp/tests/unit/__snapshots__/instructions/exec-command-reference-full.txt
+++ b/services/mcp/tests/unit/__snapshots__/instructions/exec-command-reference-full.txt
@@ -67,13 +67,13 @@ Assistant: Now I have both schemas. Let me start by searching for existing reven
<bad-example>
User: Show me our feature flags
Assistant: [Directly calls posthog:exec({ "command": "call feature-flag-get-all {}" }) with guessed parameters]
-WRONG — You must run `info feature-flag-get-all` FIRST to check the schema
+WRONG: Run `info feature-flag-get-all` once when its schema is missing.
</bad-example>
<bad-example>
User: Query our events
Assistant: [Calls three tools in parallel without any `info` calls first]
-WRONG — You must run `info` for ALL tools before making ANY `call` commands
+WRONG: Run `info` once for each missing schema.
</bad-example>
<bad-example>
diff --git a/services/mcp/tests/unit/__snapshots__/instructions/exec-tool-description.txt b/services/mcp/tests/unit/__snapshots__/instructions/exec-tool-description.txt
index d2e193f02802..8767ed882eaa 100644
--- a/services/mcp/tests/unit/__snapshots__/instructions/exec-tool-description.txt
+++ b/services/mcp/tests/unit/__snapshots__/instructions/exec-tool-description.txt
@@ -4,27 +4,27 @@ PostHog: dashboards, insights, funnels, SQL, experiments, surveys, replay, error
Pass CLI-style commands in the `command` parameter for all PostHog interactions.
-**MANDATORY — HARD REQUIREMENTS**
+**Requirements**
-1. Discover tools first with `search` or `tools`.
-2. Run `info <tool_name>` BEFORE every `call <tool_name> <json>`.
+1. Find unknown tools with `search` or `tools`.
+2. Run `info <tool_name>` once if its schema is not in context. Reuse it unless the tool changes or a schema error occurs.
-BLOCKING, like reading a file before editing it. Tool names and schemas are NOT predictable — never assume.
+Never guess a schema or run `info` before every call.
**Commands (in order):**
```text
-# 1. Discover (preferred: focused regex over name/title/description)
+# 1. Find unknown tools
posthog:exec({ "command": "search <regex>" })
posthog:exec({ "command": "tools" }) # fallback: list all
-# 2. Check description + top-level schema (REQUIRED before call)
+# 2. Inspect once if the schema is missing
posthog:exec({ "command": "info <tool_name>" })
# 3. Drill into complex fields — REQUIRED for any field with a `hint`
posthog:exec({ "command": "schema <tool_name> <field_path>" })
-# 4. Call the tool
+# 4. Call; reuse the schema
posthog:exec({ "command": "call <tool_name> <json_input>" })
posthog:exec({ "command": "call --json <tool_name> <json_input>" })
```
diff --git a/services/mcp/tests/unit/instructions-formatter.test.ts b/services/mcp/tests/unit/instructions-formatter.test.ts
index 7f5a4b63133f..d44d2abf5270 100644
--- a/services/mcp/tests/unit/instructions-formatter.test.ts
+++ b/services/mcp/tests/unit/instructions-formatter.test.ts
@@ -146,7 +146,7 @@ describe('InstructionsFormatter', () => {
const formatter = new InstructionsFormatter()
const result = formatter.buildExecToolDescription()
expect(result).toContain('Using the `posthog` tool')
- expect(result).toContain('MANDATORY — HARD REQUIREMENTS')
+ expect(result).toContain('Run `info <tool_name>` once if its schema is not in context.')
expect(result).not.toContain('### Basic functionality')
expect(result).not.toContain('### Examples')
})