Skip to content

fix(mcp): guide agents through exec discovery - #72403

Merged
dmarticus merged 2 commits into
masterfrom
posthog-code/fix-mcp-exec-discovery
Jul 21, 2026
Merged

fix(mcp): guide agents through exec discovery#72403
dmarticus merged 2 commits into
masterfrom
posthog-code/fix-mcp-exec-discovery

Conversation

@dmarticus

@dmarticus dmarticus commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Problem

In CLI mode, scope-gated tools can look like unknown tools when called directly through exec.

Why: Authorization failures should explain how to restore MCP access instead of looking like an unsupported capability.

Changes

  • Return explicit reconnect or reauthorization guidance when info, schema, or call targets a scope-gated tool.
  • Direct unknown tool names back to catalog search.
  • Add focused regression coverage for both recovery paths.

How did you test this code?

  • pnpm --filter @posthog/mcp exec vitest run tests/unit/exec.test.ts (99 tests passed)
  • pnpm --filter @posthog/mcp typecheck

Automatic notifications

  • Publish to changelog?
  • Alert Sales and Marketing teams?

Docs update

Not applicable. This change only improves runtime error guidance.

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

Codex implemented the runtime recovery behavior using the /implementing-mcp-tools and /writing-tests skills. The broader instruction and documentation changes were removed after the issue could not be reproduced.


Created with PostHog Code

Make CLI-mode capability discovery explicit and return actionable recovery guidance for scope-gated tools.

Generated-By: PostHog Code
Task-Id: 8f51bdaa-77c5-4d23-bf3d-85fce84aa820
@dmarticus dmarticus self-assigned this Jul 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Hey @dmarticus! 👋

It looks like your git author email on this PR isn't your @posthog.com address (dmarticus@gmail.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. 🙂

@dmarticus
dmarticus requested a review from skoob13 July 20, 2026 22:15
@dmarticus
dmarticus marked this pull request as ready for review July 20, 2026 22:15
@greptile-apps

greptile-apps Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(mcp): guide agents through exec disc..." | Re-trigger Greptile

}
const available = tools.map((t) => t.name).join(', ')
throw new Error(`Unknown tool: "${name}". Available tools: ${available}`)
const scopeGatedTool = scopeGatedTools.find((candidate) => candidate.name === name)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Totally makes sense.

@skoob13 skoob13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Trying to understand what happened here, as we're in the the caveman mode for characters in the exec tool. Can you expand a bit on how I can reproduce it?

**Commands (in order):**

```text
# 1. Find unknown tools

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These comments were reasoning steps. I'd keep them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1


- If a tool call fails, the error includes a suggestion and similar tool names. Read the suggestion before retrying.
- If a tool name doesn't exist, run `tools` again to find the correct name.
- If a tool name doesn't exist, run `search <term>` to find the current name before claiming the capability is unavailable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The changes to the prompt here are a bit confusing. It feels to me like a side effect rather than the root cause. Specifically for this line, what is the behavior you've observed? Does GPT use "list" before search?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

@dmarticus

Copy link
Copy Markdown
Contributor Author

okay, tried reproducing this in both codex and claude (a friend had reported it to me with codex), but I couldn't reproduce it. I think the changes to services/mcp/src/tools/exec.ts are worth keeping, but I'm not gonna mess with the harness.

Thanks for looking!

Generated-By: PostHog Code
Task-Id: 8f51bdaa-77c5-4d23-bf3d-85fce84aa820

@skoob13 skoob13 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

:turbostamp:

@dmarticus
dmarticus merged commit 8553c28 into master Jul 21, 2026
200 of 201 checks passed
@dmarticus
dmarticus deleted the posthog-code/fix-mcp-exec-discovery branch July 21, 2026 17:11
@deployment-status-posthog

deployment-status-posthog Bot commented Jul 21, 2026

Copy link
Copy Markdown

Deploy status

Environment Status Deployed At Workflow
dev ✅ Deployed 2026-07-21 17:45 UTC Run
prod-us ✅ Deployed 2026-07-21 18:05 UTC Run
prod-eu ✅ Deployed 2026-07-21 18:09 UTC Run

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants