Repository navigation
feat(cli): add agentic api tools - #61178
Conversation
|
| ? (error as { code?: unknown }).code | ||
| : undefined | ||
| } | ||
|
|
There was a problem hiding this comment.
AGENTS_MD_PROMPT and AGENTS_MD_SNIPPET are assigned the same value on consecutive lines. Callers inside this file use AGENTS_MD_SNIPPET; the test file imports AGENTS_MD_PROMPT. Exporting both names for the same string violates OnceAndOnlyOnce and leaves future readers uncertain which name to reach for.
Prompt To Fix With AI
This is a comment left during a code review.
Path: services/mcp/src/cli/agents-md.ts
Line: 14
Comment:
**Duplicate export aliases**
`AGENTS_MD_PROMPT` and `AGENTS_MD_SNIPPET` are assigned the same value on consecutive lines. Callers inside this file use `AGENTS_MD_SNIPPET`; the test file imports `AGENTS_MD_PROMPT`. Exporting both names for the same string violates OnceAndOnlyOnce and leaves future readers uncertain which name to reach for.
How can I resolve this? If you propose a fix, please make it concise.
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 2 · PR risk: 0/10 |
skoob13
left a comment
There was a problem hiding this comment.
This looks great. Some feedback:
api --helpis empty now. Should probably be populated for humans.posthog-cli api --agent-helpseems to be working very well (example). Alternatively, we can also detect when Claude Code/Codex is running and swap theapi --helpcontent with the prompt.
The guide is composed from the same exec-tool templates the MCP server serves (tool blurb, command reference, schema drill-down rules, tool-domain index, query-tool catalog), with posthog:exec invocations rewritten to posthog-cli api syntax so there is a single source of truth. Also populates the clap-side `api --help` with the full command list so humans get useful help without the node bundle. Co-authored-by: Georgiy Tarasov <georgiy@posthog.com>
The installed snippet is now delimited by <posthog>...</posthog> tags, which gives agents a clearly bounded section and lets reinstalls replace stale content in place instead of skipping or duplicating it. The snippet also steers agents to load `posthog-cli api --agent-help` into context first, and falls back to `npx -y @posthog/cli@latest` when the binary is not installed.
Resolve two conflicts from merging latest master: - services/mcp/src/tools/exec.ts: keep both scopeGatedTools (master) and ExecToolOptions (our branch) parameters on createExecTool - exec-tool.json snapshot: accept master's deletion Adapt to master's version-param removal: - Drop version from getCliTools(), buildAgentHelp(), and their callers - Remove mcpVersion filtering in CLI tool loader - Update test assertions to match current snippet content
|
Size Change: 0 B Total Size: 62.3 MB ℹ️ View Unchanged
|
|
Dependency limit exceeded — report not shown. This pull request scan exceeded the 10,000-dependency limit applied to this scan, so the results are incomplete and may be inaccurate. To avoid reporting false positives, Socket has not posted a report. Upgrade your plan to raise the dependency limit and get complete reports, or view the partial scan in the dashboard. Socket is always free for open source. If this is a non-commercial open source project, contact us to request a free Team account. |
| if let Some(path) = env::var_os("POSTHOG_API_CLI_PATH") { | ||
| if path.is_empty() { | ||
| bail!("POSTHOG_API_CLI_PATH is set but empty."); |
There was a problem hiding this comment.
Empty environment variable value is incorrectly rejected. When POSTHOG_API_CLI_PATH is set to an empty string, the check if path.is_empty() will trigger and bail with an error. However, in Unix shells, unsetting a variable is different from setting it to empty. Users might set POSTHOG_API_CLI_PATH= to explicitly unset the override, expecting fallback behavior. Instead, this code treats empty string as an error rather than falling through to the default search paths.
if let Some(path) = env::var_os("POSTHOG_API_CLI_PATH") {
// Skip the empty check - if it's set but empty, just proceed
let path = PathBuf::from(path);
let resolved = path.canonicalize().with_context(|| {Alternatively, treat empty as "not set":
if let Some(path) = env::var_os("POSTHOG_API_CLI_PATH") {
if path.is_empty() {
// Fall through to default search instead of error
} else {
let path = PathBuf::from(path);
// ... rest of validation
}
}| if let Some(path) = env::var_os("POSTHOG_API_CLI_PATH") { | |
| if path.is_empty() { | |
| bail!("POSTHOG_API_CLI_PATH is set but empty."); | |
| if let Some(path) = env::var_os("POSTHOG_API_CLI_PATH").filter(|p| !p.is_empty()) { | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.



Problem
Coding agents need shell-friendly access to the same broad PostHog product surface area that the MCP server exposes. The existing CLI has a small hand-written command set, so agents cannot reliably discover tools, inspect schemas, install PostHog skills, or execute generated product operations from a local repo checkout.
Changes
posthog-cli apias an agent-first command surface backed by the generated MCP tool catalog.tools,search,info,schema,call,skill list,skill install, andagents-md installsupport in the MCP CLI bundle.--dry-runvalidation for CLI calls and an opt-in--confirmguard for destructive tools.posthog-cli logincredentials when proxying from the Rust CLI into the MCP CLI bundle.posthog-cli apifor PostHog interactions.--confirmhandling and the AGENTS.md snippet installer.How did you test this code?
pnpm exec tsx scripts/copy-instructions.ts && pnpm exec vitest run --project unit tests/unit/exec.test.ts tests/unit/cli-agents-md.test.tspnpm --filter=@posthog/mcp build:clicargo check --all-targetscargo run -- api search feature-flagDocs update
Yes, in PR here: PostHog/posthog.com#17337
🤖 Agent context
This PR was authored with Codex in the local PostHog checkout.
The implementation follows the MCP server's generated tool infrastructure rather than duplicating product-specific CLI commands by hand. The Rust CLI acts as a thin proxy that locates the generated MCP CLI bundle, forwards existing
posthog-cli logincredentials through environment variables, and preserves host overrides.A destructive-operation confirmation layer was added at the shared exec-tool level so the standalone CLI can require
--confirmfor destructive generated tools while preserving MCP server behavior for existing clients. Skills are installed from the Context Mill resource archive into.agents/skills, and the AGENTS.md installer writes a managed, idempotent section.The first version intentionally ships through
posthog-cli, but release packaging still needs follow-up work to bundleservices/mcp/dist/posthog-api-cli.mjsinto cargo-dist/npm artifacts before this can be published as a complete standalone CLI experience.