Skip to content

fix(mcp): default get-llm-total-costs-for-project to active project - #73593

Merged
Radu-Raicea merged 1 commit into
masterfrom
posthog-code/fix-llm-costs-default-project
Jul 24, 2026
Merged

fix(mcp): default get-llm-total-costs-for-project to active project#73593
Radu-Raicea merged 1 commit into
masterfrom
posthog-code/fix-llm-costs-default-project

Conversation

@Radu-Raicea

Copy link
Copy Markdown
Member

Problem

The get-llm-total-costs-for-project MCP tool declares projectId as a required input. Agents don't know the numeric project id, so a large share of this tool's calls fail validation with missing required parameter: projectId (visible in the MCP tool-call analytics). Every other tool in the server resolves the project from context via context.stateManager.getProjectId().

Changes

  • Make projectId optional on AIObservabilityGetCostsSchema, with a description noting it defaults to the active project.
  • In the handler, fall back to context.stateManager.getProjectId() when projectId is omitted, dropping the now-redundant String() wrap. This aligns the tool with the getProjectId() convention documented in src/tools/README.md.
  • Regenerated the shared schema/tool-inputs.json and the get-llm-total-costs-for-project tool-schema snapshot from the Zod source (not hand-edited).

How did you test this code?

  • Added an integration test case asserting the tool falls back to the active project when projectId is omitted (aiObservability.integration.test.ts).
  • Regenerated schema/tool-inputs.json and 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, projectId removed from required).
  • I (an agent) could not run the full tsgo typecheck, oxfmt/oxlint across 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() returns Promise<string> and String(params.projectId) is a string, matching context.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/mcp repo; on discovering the code now lives in this monorepo under services/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

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
@Radu-Raicea Radu-Raicea self-assigned this Jul 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey @Radu-Raicea! 👋

It looks like your git author email on this PR isn't your @posthog.com address (radu@raicea.com). Since you're on the PostHog team, it's worth pointing your local git author email at your @posthog.com address. Why it matters:

  • Consistent work identity in git history — internal tooling that attributes commits to team members keys off your @posthog.com address.
  • Keeps team contributions easy to tell apart from external community ones when scanning history.

You can fix it for this repo with:

git config user.email "you@posthog.com"

Or set it globally with git config --global user.email "you@posthog.com". No need to redo this PR — just a nudge for next time. 🙂

@Radu-Raicea
Radu-Raicea marked this pull request as ready for review July 24, 2026 17:45
@pr-assigner-resolver-posthog
pr-assigner-resolver-posthog Bot requested a review from a team July 24, 2026 17:46
@greptile-apps

greptile-apps Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(mcp): default get-llm-total-costs-fo..." | Re-trigger Greptile

@Radu-Raicea Radu-Raicea added the stamphog Request AI approval (no full review) label Jul 24, 2026
@Radu-Raicea
Radu-Raicea enabled auto-merge (squash) July 24, 2026 17:48

@stamphog stamphog Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@Radu-Raicea
Radu-Raicea merged commit a5d244e into master Jul 24, 2026
331 of 334 checks passed
@Radu-Raicea
Radu-Raicea deleted the posthog-code/fix-llm-costs-default-project branch July 24, 2026 17:58
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 24, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-24 18:25 UTC Run
prod-us ✅ Deployed 2026-07-24 18:46 UTC Run
prod-eu ✅ Deployed 2026-07-24 18:48 UTC Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stamphog Request AI approval (no full review)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant