fix(mcp): default get-llm-total-costs-for-project to active project - #73593
Conversation
Make projectId optional on AIObservabilityGetCostsSchema and fall back to context.stateManager.getProjectId() when it is omitted, matching the convention used by every other tool in the server. Regenerated the shared JSON schema and tool-schema snapshot. Generated-By: PostHog Code Task-Id: 0be03756-dcf9-4808-aae0-5d4bc3bf5170
|
Hey @Radu-Raicea! 👋 It looks like your git author email on this PR isn't your
You can fix it for this repo with: git config user.email "you@posthog.com"Or set it globally with |
|
Reviews (1): Last reviewed commit: "fix(mcp): default get-llm-total-costs-fo..." | Re-trigger Greptile |
There was a problem hiding this comment.
Small, focused fix by an owning-team author with fresh familiarity in these paths; makes an MCP param optional with a type-consistent fallback matching the codebase convention, has test coverage, and a bot reviewer already signaled no concerns. Not risky territory.
- Author wrote 33% of the modified lines and has 16 merged PRs in these paths (familiarity MODERATE).
- 👍 on the PR from greptile-apps[bot], hex-security-app[bot].
Gate mechanics and policy version
| Gate | Result | |
|---|---|---|
| prerequisites | ✓ | all clear |
| deny-list | ✓ | no deny categories matched |
| size | ✓ | 16L, 3F substantive, 25L/5F incl. docs/generated/snapshots — within ceiling |
| tier | ✓ | T1-agent / T1b-small (25L, 5F, single-area, fix) |
| stamphog 2.0.0b3 | .stamphog/policy.yml @ 484770e · reviewed head ab8e3eb |
Problem
The
get-llm-total-costs-for-projectMCP tool declaresprojectIdas a required input. Agents don't know the numeric project id, so a large share of this tool's calls fail validation withmissing required parameter: projectId(visible in the MCP tool-call analytics). Every other tool in the server resolves the project from context viacontext.stateManager.getProjectId().Changes
projectIdoptional onAIObservabilityGetCostsSchema, with a description noting it defaults to the active project.context.stateManager.getProjectId()whenprojectIdis omitted, dropping the now-redundantString()wrap. This aligns the tool with thegetProjectId()convention documented insrc/tools/README.md.schema/tool-inputs.jsonand theget-llm-total-costs-for-projecttool-schema snapshot from the Zod source (not hand-edited).How did you test this code?
projectIdis omitted (aiObservability.integration.test.ts).schema/tool-inputs.jsonand the tool-schema snapshot with the repo's own generator + oxfmt so they match what CI produces; the resulting diffs are confined to this one schema (description added,projectIdremoved fromrequired).tsgotypecheck,oxfmt/oxlintacross the whole package, or the live integration test here, since that needs a full monorepo install and live PostHog credentials. The change is type-safe by inspection:getProjectId()returnsPromise<string>andString(params.projectId)is astring, matchingcontext.api.query({ projectId }). Please let CI run these.🤖 Agent context
Autonomy: Human-driven (agent-assisted)
Requested from a Slack thread and implemented by the PostHog Slack app (Claude). The fix was originally scoped against the archived
posthog/mcprepo; on discovering the code now lives in this monorepo underservices/mcp, I re-applied it here and regenerated the derived schema artifacts to match. No repo skills were invoked.Created with PostHog from a Slack thread