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.

feat(mcp): add help command to exec (#108249)

Richard Solomoub493a85c6dfb
diff --git a/services/mcp/schema/exec-command-reference.md b/services/mcp/schema/exec-command-reference.md
index ac789a12c8e4..93d38bb8d859 100644
--- a/services/mcp/schema/exec-command-reference.md
+++ b/services/mcp/schema/exec-command-reference.md
@@ -5,12 +5,13 @@
In [CLI mode](/docs/model-context-protocol/faq#choosing-a-tool-mode), the default for most clients, the MCP server registers a single `exec` tool instead of one tool per endpoint. Agents pass it CLI-style command strings to list, search, inspect, and call the tools above on demand, which keeps context usage small.
```text
+help [command] — list commands or show usage for one command
learn <topic...> - load one or more learning topics
tools — list available tool names
-search <regex_pattern> — search tools by JavaScript regex (matches name, title, description)
+search <words or regex_pattern> — find tools by name, title, or description
info [--json] <tool_name> — show tool name, description, and input schema (summarized if too large). Pass `--json` for raw JSON output.
schema <tool_name> [field_path] — drill into a specific field schema (supports dot-notation, e.g. series, breakdownFilter.breakdowns)
-call [--json] [--confirm] <tool_name> <json_input> — call a tool with JSON input (--json returns JSON instead of optimized output in supported tools. Informational responses remain tagged and escaped in both MCP and the agent CLI. --confirm is required by the CLI for destructive tools.)
+call [--json] [--confirm] <tool_name> [json_input] — call a tool with JSON input (--json returns JSON instead of optimized output in supported tools. Informational responses remain tagged and escaped in both MCP and the agent CLI. --confirm is required by the CLI for destructive tools.)
```
**One command per request.** `exec` has no batch syntax. A request that stacks several commands on separate lines is rejected before any of them run. To run several commands, send several `exec` calls. You can issue them in parallel.
diff --git a/services/mcp/src/cli/index.ts b/services/mcp/src/cli/index.ts
index e544b4017dc9..4d34be6ea4d3 100644
--- a/services/mcp/src/cli/index.ts
+++ b/services/mcp/src/cli/index.ts
@@ -18,7 +18,7 @@ tools
search <regex_pattern>
info [--json] <tool_name>
schema <tool_name> [field_path]
-call [--json] [--confirm] <tool_name> <json_input>`
+call [--json] [--confirm] <tool_name> [json_input]`
interface BuiltExec {
context: Context
@@ -40,7 +40,7 @@ Usage:
posthog-cli api search <regex>
posthog-cli api info [--json] <tool>
posthog-cli api schema <tool> [field.path]
- posthog-cli api call [--json] [--dry-run] [--confirm] <tool> '<json>'
+ posthog-cli api call [--json] [--dry-run] [--confirm] <tool> ['<json>']
posthog-cli api skill list [--json]
posthog-cli api skill install [--force] <skill-id>
posthog-cli api agents-md install [--path AGENTS.md]
@@ -251,7 +251,7 @@ async function main(): Promise<void> {
const toolName = args.shift()
const jsonBody = args.length > 0 ? args.join(' ') : '{}'
if (!toolName) {
- throw new Error('Usage: posthog-cli api call [--json] [--dry-run] [--confirm] <tool> <json>')
+ throw new Error('Usage: posthog-cli api call [--json] [--dry-run] [--confirm] <tool> [json]')
}
await runExecCommand(`call ${json ? '--json ' : ''}${confirmed ? '--confirm ' : ''}${toolName} ${jsonBody}`)
return
diff --git a/services/mcp/src/templates/sections/cli-syntax.md b/services/mcp/src/templates/sections/cli-syntax.md
index 6ee77b61861c..10eb088e7bcf 100644
--- a/services/mcp/src/templates/sections/cli-syntax.md
+++ b/services/mcp/src/templates/sections/cli-syntax.md
@@ -1,11 +1,12 @@
CLI-style command string. Supported commands:
```text
+help [command] — list commands or show usage for one command
{extra_commands}tools — list available tool names
-search <regex_pattern> — search tools by JavaScript regex (matches name, title, description)
+search <words or regex_pattern> — find tools by name, title, or description
info [--json] <tool_name> — show tool name, description, and input schema (summarized if too large). Pass `--json` for raw JSON output.
schema <tool_name> [field_path] — drill into a specific field schema (supports dot-notation, e.g. series, breakdownFilter.breakdowns)
-call [--json] [--confirm] <tool_name> <json_input> — call a tool with JSON input (--json returns JSON instead of optimized output in supported tools. Informational responses remain tagged and escaped in both MCP and the agent CLI. --confirm is required by the CLI for destructive tools.)
+call [--json] [--confirm] <tool_name> [json_input] — call a tool with JSON input (--json returns JSON instead of optimized output in supported tools. Informational responses remain tagged and escaped in both MCP and the agent CLI. --confirm is required by the CLI for destructive tools.)
```
**One command per request.** `exec` has no batch syntax. A request that stacks several commands on separate lines is rejected before any of them run. To run several commands, send several `exec` calls. You can issue them in parallel.
diff --git a/services/mcp/src/tools/exec.ts b/services/mcp/src/tools/exec.ts
index eb64b8a0af42..9f41dabeff99 100644
--- a/services/mcp/src/tools/exec.ts
+++ b/services/mcp/src/tools/exec.ts
@@ -156,7 +156,7 @@ export type ExecInnerCallTracker = (toolName: string, properties: ExecInnerCallP
* question "which capability do people reach for that we don't have" unanswerable.
*/
export interface ExecCommandMeta {
- /** The verb the agent used: `search`, `info`, `schema`, `tools`, `learn`, `call`. */
+ /** The verb the agent used: `help`, `search`, `info`, `schema`, `tools`, `learn`, `call`. */
exec_verb: string
/** The raw search query. Already bounded to MAX_SEARCH_PATTERN_LENGTH by the handler. */
exec_search_query?: string
@@ -242,7 +242,7 @@ export interface ExecToolOptions {
builtInSkillHint?: BuiltInSkillHint
}
-const CALL_USAGE = 'Usage: call [--json] [--confirm] <tool_name> <json_input>'
+const CALL_USAGE = 'Usage: call [--json] [--confirm] <tool_name> [json_input]'
/**
* Plain errors out of the learn catalog are agent mistakes — unknown names, bad
@@ -275,7 +275,33 @@ function parseCommand(input: string): { verb: string; rest: string } {
/** A later line opening with one of these is what separates a batched request
* from a legitimately multi-line argument. */
-const EXEC_VERBS = new Set(['learn', 'tools', 'search', 'info', 'schema', 'call'])
+const EXEC_VERBS = new Set(['help', 'learn', 'tools', 'search', 'info', 'schema', 'call'])
+
+const EXEC_COMMAND_HELP: Record<string, string> = {
+ help: 'help [command] — list commands or show usage for one command',
+ tools: 'tools — list available tool names',
+ search: 'search <words or regex_pattern> — find tools by name, title, or description',
+ info: 'info [--json] <tool_name> — show a tool description and input schema',
+ schema: 'schema <tool_name> [field_path] — inspect a tool input schema field',
+ call: 'call [--json] [--confirm] <tool_name> [json_input] — invoke a tool',
+}
+
+const LEARN_COMMAND_HELP = 'learn <topic...> — load learning topics or list available topics'
+
+function execHelp(command: string, learnEnabled: boolean): string {
+ const commands = learnEnabled ? { ...EXEC_COMMAND_HELP, learn: LEARN_COMMAND_HELP } : EXEC_COMMAND_HELP
+ if (!command) {
+ return Object.values(commands).join('\n')
+ }
+ const help = commands[command]
+ if (typeof help !== 'string') {
+ throw new ExecCommandError(
+ `Unknown command: "${command}". Run "help" to list available commands.`,
+ 'unknown_command'
+ )
+ }
+ return help
+}
/** Bounds on the rejection message, so a long batch or a large JSON body does
* not come back as a wall of text. */
@@ -426,7 +452,7 @@ export function parseExecCallInnerArgs(command: string): Record<string, unknown>
/** Verbs the dispatcher grammar accepts. A verb outside this set is what the
* `unknown_command` rejection fires on, and is recorded as unrecognized. */
-const KNOWN_EXEC_VERBS = new Set(['learn', 'tools', 'search', 'info', 'schema', 'call'])
+const KNOWN_EXEC_VERBS = new Set(['help', 'learn', 'tools', 'search', 'info', 'schema', 'call'])
/** Verbs whose first positional argument names a tool. */
const TOOL_TARGETING_VERBS = new Set(['info', 'schema', 'call'])
@@ -1631,6 +1657,9 @@ export function createExecTool(
}
switch (verb) {
+ case 'help':
+ return execHelp(rest, options.learnCatalog !== undefined)
+
case 'learn': {
// Before the availability check, so a rejected skill command still records its form.
options.trackCommand?.({ exec_verb: verb, ...classifyLearnCommand(rest) })
@@ -2091,7 +2120,7 @@ export function createExecTool(
)
}
throw new ExecCommandError(
- `Unknown command: "${verb}". Supported commands: ${options.learnCatalog ? 'learn, ' : ''}tools, search, info, schema, call`,
+ `Unknown command: "${verb}". Run "help" to list available commands.`,
'unknown_command'
)
}
diff --git a/services/mcp/tests/unit/__snapshots__/instructions/exec-command-reference-claude-chat-skills.txt b/services/mcp/tests/unit/__snapshots__/instructions/exec-command-reference-claude-chat-skills.txt
index cfd4126bba8b..84edad9089cc 100644
--- a/services/mcp/tests/unit/__snapshots__/instructions/exec-command-reference-claude-chat-skills.txt
+++ b/services/mcp/tests/unit/__snapshots__/instructions/exec-command-reference-claude-chat-skills.txt
@@ -1,12 +1,13 @@
CLI-style command string. Supported commands:
```text
+help [command] — list commands or show usage for one command
learn <topic...> - load one or more learning topics
tools — list available tool names
-search <regex_pattern> — search tools by JavaScript regex (matches name, title, description)
+search <words or regex_pattern> — find tools by name, title, or description
info [--json] <tool_name> — show tool name, description, and input schema (summarized if too large). Pass `--json` for raw JSON output.
schema <tool_name> [field_path] — drill into a specific field schema (supports dot-notation, e.g. series, breakdownFilter.breakdowns)
-call [--json] [--confirm] <tool_name> <json_input> — call a tool with JSON input (--json returns JSON instead of optimized output in supported tools. Informational responses remain tagged and escaped in both MCP and the agent CLI. --confirm is required by the CLI for destructive tools.)
+call [--json] [--confirm] <tool_name> [json_input] — call a tool with JSON input (--json returns JSON instead of optimized output in supported tools. Informational responses remain tagged and escaped in both MCP and the agent CLI. --confirm is required by the CLI for destructive tools.)
```
**One command per request.** `exec` has no batch syntax. A request that stacks several commands on separate lines is rejected before any of them run. To run several commands, send several `exec` calls. You can issue them in parallel.
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 2c0e0bcc3f50..0b22e9554758 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
@@ -1,12 +1,13 @@
CLI-style command string. Supported commands:
```text
+help [command] — list commands or show usage for one command
learn <topic...> - load one or more learning topics
tools — list available tool names
-search <regex_pattern> — search tools by JavaScript regex (matches name, title, description)
+search <words or regex_pattern> — find tools by name, title, or description
info [--json] <tool_name> — show tool name, description, and input schema (summarized if too large). Pass `--json` for raw JSON output.
schema <tool_name> [field_path] — drill into a specific field schema (supports dot-notation, e.g. series, breakdownFilter.breakdowns)
-call [--json] [--confirm] <tool_name> <json_input> — call a tool with JSON input (--json returns JSON instead of optimized output in supported tools. Informational responses remain tagged and escaped in both MCP and the agent CLI. --confirm is required by the CLI for destructive tools.)
+call [--json] [--confirm] <tool_name> [json_input] — call a tool with JSON input (--json returns JSON instead of optimized output in supported tools. Informational responses remain tagged and escaped in both MCP and the agent CLI. --confirm is required by the CLI for destructive tools.)
```
**One command per request.** `exec` has no batch syntax. A request that stacks several commands on separate lines is rejected before any of them run. To run several commands, send several `exec` calls. You can issue them in parallel.
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 2d027f1c3b70..efd04ab706f6 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
@@ -1,11 +1,12 @@
CLI-style command string. Supported commands:
```text
+help [command] — list commands or show usage for one command
tools — list available tool names
-search <regex_pattern> — search tools by JavaScript regex (matches name, title, description)
+search <words or regex_pattern> — find tools by name, title, or description
info [--json] <tool_name> — show tool name, description, and input schema (summarized if too large). Pass `--json` for raw JSON output.
schema <tool_name> [field_path] — drill into a specific field schema (supports dot-notation, e.g. series, breakdownFilter.breakdowns)
-call [--json] [--confirm] <tool_name> <json_input> — call a tool with JSON input (--json returns JSON instead of optimized output in supported tools. Informational responses remain tagged and escaped in both MCP and the agent CLI. --confirm is required by the CLI for destructive tools.)
+call [--json] [--confirm] <tool_name> [json_input] — call a tool with JSON input (--json returns JSON instead of optimized output in supported tools. Informational responses remain tagged and escaped in both MCP and the agent CLI. --confirm is required by the CLI for destructive tools.)
```
**One command per request.** `exec` has no batch syntax. A request that stacks several commands on separate lines is rejected before any of them run. To run several commands, send several `exec` calls. You can issue them in parallel.
diff --git a/services/mcp/tests/unit/exec.test.ts b/services/mcp/tests/unit/exec.test.ts
index 67a2f3aed0de..cfc3d03e88c0 100644
--- a/services/mcp/tests/unit/exec.test.ts
+++ b/services/mcp/tests/unit/exec.test.ts
@@ -76,6 +76,35 @@ function createExec(
}
describe('exec tool', () => {
+ describe('help command', () => {
+ it('lists available commands and their argument shapes', async () => {
+ const result = await createExec().handler(mockContext, { command: 'help' })
+
+ expect(result).toContain('search <words or regex_pattern>')
+ expect(result).toContain('call [--json] [--confirm] <tool_name> [json_input]')
+ expect(result).not.toContain('learn <topic...>')
+ })
+
+ it('shows usage for one command', async () => {
+ const result = await createExec().handler(mockContext, { command: 'help search' })
+
+ expect(result).toBe('search <words or regex_pattern> — find tools by name, title, or description')
+ })
+
+ it('shows learn only when it is available', async () => {
+ const exec = createExec(undefined, undefined, { learnCatalog: new ExecLearnCatalog([], undefined) })
+
+ await expect(exec.handler(mockContext, { command: 'help learn' })).resolves.toContain('learn <topic...>')
+ })
+
+ it('directs unknown help topics to the command list', async () => {
+ await expect(createExec().handler(mockContext, { command: 'help unknown' })).rejects.toMatchObject({
+ reason: 'unknown_command',
+ message: 'Unknown command: "unknown". Run "help" to list available commands.',
+ })
+ })
+ })
+
describe('learn command', () => {
const guides = [
{
@@ -392,14 +421,14 @@ describe('exec tool', () => {
it('throws usage error for bare call', async () => {
const exec = createExec()
await expect(exec.handler(mockContext, { command: 'call' })).rejects.toThrow(
- 'Usage: call [--json] [--confirm] <tool_name> <json_input>'
+ 'Usage: call [--json] [--confirm] <tool_name> [json_input]'
)
})
it('throws usage error for call --json with no tool name', async () => {
const exec = createExec()
await expect(exec.handler(mockContext, { command: 'call --json' })).rejects.toThrow(
- 'Usage: call [--json] [--confirm] <tool_name> <json_input>'
+ 'Usage: call [--json] [--confirm] <tool_name> [json_input]'
)
})
@@ -1845,6 +1874,8 @@ describe('exec tool', () => {
// from a mistyped verb in analytics. Flag handling differs per verb, so a
// parser regression silently collapses the funnel back into one bucket.
it.each([
+ ['help', 'help', undefined],
+ ['help search', 'help', undefined],
['tools', 'tools', undefined],
['search query-', 'search', undefined],
['info execute-sql', 'info', 'execute-sql'],