Skip to content

feat(mcp): send $mcp_unknown_tool and $mcp_input_required from posthogmcpsdk - #347

Merged
lucasheriques merged 3 commits into
mainfrom
lucas/mcp-go-adapter-optional-events
Oct 2, 2026
Merged

lucasheriques merged 3 commits into
mainfrom
lucas/mcp-go-adapter-optional-events

Conversation

@lucasheriques

@lucasheriques lucasheriques commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

posthogmcpsdk counted a call naming an unregistered tool, and an input_required round, as $mcp_tool_call. The SDK spec says neither is a tool call (PostHog/sdk-specs#87, "Tool call event" and "Optional events"). The adapter now sends $mcp_unknown_tool and $mcp_input_required through the manual API added in #345.

  • Unknown tool: recognised by go-sdk's own unknown-tool error (jsonrpc.CodeInvalidParams, message unknown tool ...), not by the cached tool list, which is stale in both directions on a server that sends no list_changed. An echoed conversation handle still joins the event; one is never minted.
  • input_required: a round the client receives (go-sdk v1.8, 2026-07-28 clients) sends $mcp_input_required with the request methods, never their content. The retry that completes the call sends the $mcp_tool_call.
  • Legacy shim exhaustion: a legacy-revision call whose handler keeps asking after go-sdk's one re-entry is a failed $mcp_tool_call with $mcp_error_type input_required.

Stack

Last of four: #345, #344 and #346 are merged and released in v1.30.0. posthogmcpsdk/go.mod requires v1.30.0.

Testing

In posthogmcpsdk, on go-sdk v1.6.1 and v1.8.0 (the round tests skip on v1.6.1): go vet and go test -race -count=1 ./... pass. Root go vet ./... and bin/api-diff pass. Probe cases X1 (unknown tool) and C15 (input_required) across the e1 to e4 eras give one $mcp_unknown_tool with no $mcp_tool_call, and $mcp_input_required then one $mcp_tool_call on v1.8.0. Two independent reviewers (Opus and Sonnet) found nine issues in the first version; all but one cosmetic duplication are fixed, with tests that failed first.

@lucasheriques
lucasheriques added this pull request to stack #348 October 1, 2026 22:38
@lucasheriques lucasheriques changed the title lucas/mcp go adapter optional events feat(mcp): send $mcp_unknown_tool and $mcp_input_required from posthogmcpsdk Oct 1, 2026
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

posthog-go Compliance Report

Date: 2026-10-02 12:36:00 UTC
Duration: 169254ms

✅ All Tests Passed!

111/111 tests passed


Capture_V1 Tests

✅ 94/94 tests passed

View Details
Test Status Duration
Endpoint And Method.Targets V1 Endpoint ✅ 23ms
Endpoint And Method.Does Not Use Legacy Endpoints ✅ 7ms
Required Headers.Has Authorization Bearer Header ✅ 6ms
Required Headers.Has Content Type Json ✅ 6ms
Required Headers.Has Posthog Sdk Info Format ✅ 6ms
Required Headers.Has Posthog Attempt Header ✅ 7ms
Required Headers.Has Posthog Request Id ✅ 6ms
Required Headers.Has Posthog Request Timestamp ✅ 7ms
Required Headers.Has User Agent ✅ 7ms
Body Format.Body Has Created At And Batch ✅ 7ms
Body Format.No Api Key In Body ✅ 6ms
Body Format.No Sent At In Body ✅ 7ms
Event Format.Event Has Required Root Fields ✅ 6ms
Event Format.Event Uuid Is Valid ✅ 6ms
Event Format.Event Timestamp Is Rfc3339 ✅ 8ms
Event Format.Distinct Id Is String ✅ 7ms
Event Format.Distinct Id At Root Not Properties ✅ 6ms
Event Format.Custom Properties Preserved ✅ 7ms
Event Format.Set Properties Preserved ✅ 7ms
Event Format.Set Once Properties Preserved ✅ 6ms
Event Format.Groups Properties Preserved ✅ 7ms
Event Format.Sdk Generates Uuid If Not Provided ✅ 6ms
Event Format.Event Has Required Root Fields Batch ✅ 9ms
Event Format.Event Uuid Is Valid Batch ✅ 10ms
Event Format.Event Timestamp Is Rfc3339 Batch ✅ 8ms
Event Format.Distinct Id Is String Batch ✅ 9ms
Event Format.Distinct Id At Root Not Properties Batch ✅ 9ms
Event Format.Custom Properties Preserved Batch ✅ 10ms
Event Format.Set Properties Preserved Batch ✅ 9ms
Event Format.Set Once Properties Preserved Batch ✅ 10ms
Event Format.Groups Properties Preserved Batch ✅ 9ms
Event Format.Sdk Generates Uuid If Not Provided Batch ✅ 9ms
Batch Behavior.Multiple Events In Single Batch ✅ 32ms
Batch Behavior.Batch Envelope Smoke ✅ 11ms
Batch Behavior.Flush With No Events Sends Nothing ✅ 3ms
Batch Behavior.Flush At Triggers Batch ✅ 1008ms
Batch Behavior.Created At Reflects Batch Creation Time ✅ 18ms
Deduplication.Generates Unique Uuids ✅ 15ms
Deduplication.Different Events Same Content Different Uuids ✅ 9ms
Deduplication.Preserves Uuid On Retry ✅ 5135ms
Deduplication.Preserves Timestamp On Retry ✅ 5136ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5134ms
Deduplication.No Duplicate Events In Batch ✅ 32ms
Header Behavior On Retry.Attempt Header Starts At One ✅ 6ms
Header Behavior On Retry.Attempt Header Increments On Retry ✅ 10141ms
Header Behavior On Retry.Request Id Preserved On Retry ✅ 5136ms
Header Behavior On Retry.Different Requests Have Different Request Ids ✅ 2014ms
Header Behavior On Retry.Request Timestamp Changes On Retry ✅ 5138ms
Response Format Validation.Success Response Has Uuid Keyed Results ✅ 7ms
Response Format Validation.Success Response Has Ok For Each Event ✅ 28ms
Response Format Validation.Success No Retry After When All Ok ✅ 29ms
Response Format Validation.Success Retry After Present When Retry Events ✅ 130ms
Response Format Validation.Success No Retry After When Drop Only ✅ 27ms
Response Format Validation.Response Echoes Request Id ✅ 8ms
Retry Behavior.Retries On 408 ✅ 5132ms
Retry Behavior.Retries On 500 ✅ 5136ms
Retry Behavior.Retries On 503 ✅ 5137ms
Retry Behavior.Retries On 504 ✅ 5136ms
Retry Behavior.Retryable Errors Have Retry After ✅ 2133ms
Retry Behavior.Respects Retry After On Retryable Error ✅ 8140ms
Retry Behavior.Does Not Retry On 400 ✅ 2133ms
Retry Behavior.Does Not Retry On 401 ✅ 2133ms
Retry Behavior.Does Not Retry On 402 ✅ 2134ms
Retry Behavior.Does Not Retry On 413 ✅ 2133ms
Retry Behavior.Does Not Retry On 415 ✅ 2133ms
Retry Behavior.Non Retryable Errors Have No Retry After ✅ 2134ms
Retry Behavior.Implements Backoff ✅ 15143ms
Retry Behavior.Max Retries Respected ✅ 15145ms
Partial Batch Handling.Handles 200 Full Success ✅ 2009ms
Partial Batch Handling.Handles 200 With All Ok ✅ 3032ms
Partial Batch Handling.Does Not Retry Dropped Events ✅ 3029ms
Partial Batch Handling.Does Not Retry Limited Events ✅ 3031ms
Partial Batch Handling.Prunes Ok Events On Partial Retry ✅ 5136ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry ✅ 5137ms
Partial Batch Handling.Retries Only Retry Events From Partial ✅ 5136ms
Partial Batch Handling.Partial Retry Preserves Uuids ✅ 5136ms
Partial Batch Handling.Partial Retry Attempt Header Increments ✅ 5137ms
Partial Batch Handling.Partial Retry Request Id Preserved ✅ 5134ms
Partial Batch Handling.Respects Retry After On Partial ✅ 5136ms
Partial Batch Handling.Unknown Result Treated As Terminal ✅ 3031ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry ✅ 3034ms
Compression.Sends Gzip Content Encoding ✅ 17ms
Compression.No Content Encoding When Disabled ✅ 7ms
Compression.Compressed Body Is Decompressible ✅ 6ms
Error Handling.Does Not Retry On Unknown 4Xx ✅ 2132ms
Event Options.Cookieless Mode Override ✅ 8ms
Event Options.Disable Skew Correction Override ✅ 7ms
Event Options.Process Person Profile Override ✅ 6ms
Event Options.Product Tour Id Override ✅ 6ms
Event Options.Unset Options Omitted ✅ 7ms
Event Options.Options Override In Batch ✅ 8ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties ✅ 7ms
Geoip And Historical Migration.Historical Migration Set In Body ✅ 6ms
Geoip And Historical Migration.Historical Migration Absent By Default ✅ 6ms

Feature_Flags Tests

✅ 17/17 tests passed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id ✅ 17ms
Request Payload.Flags Request Uses V2 Query Param ✅ 18ms
Request Payload.Flags Request Hits Flags Path Not Decide ✅ 17ms
Request Payload.Flags Request Omits Authorization Header ✅ 17ms
Request Payload.Token In Flags Body Matches Init ✅ 17ms
Request Payload.Groups Round Trip ✅ 18ms
Request Payload.Groups Default To Empty Object ✅ 18ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False ✅ 18ms
Request Payload.Disable Geoip Omitted Defaults To False ✅ 17ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key ✅ 17ms
Request Lifecycle.No Flags Request On Init Alone ✅ 3ms
Request Lifecycle.No Flags Request On Normal Capture ✅ 6ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests ✅ 31ms
Request Lifecycle.Mock Response Value Is Returned To Caller ✅ 17ms
Retry Behavior.Retries Flags On 502 ✅ 19ms
Retry Behavior.Retries Flags On 504 ✅ 19ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event ✅ 18ms

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Retrigger

[Medium risk] Adds new event types to the analytics SDK.

No new blocking issue was identified, though the stated release-version replacement remains a pre-merge step.

Reviews (2) · Last reviewed commit: "chore(mcp): pin posthog-go to the head o..."

Comment thread posthogmcpsdk/middleware.go Resolved
Comment thread posthogmcpsdk/middleware.go Resolved
@lucasheriques
lucasheriques force-pushed the lucas/mcp-go-adapter-optional-events branch from 74a3565 to c7ac66b Compare October 1, 2026 23:22
@lucasheriques
lucasheriques force-pushed the lucas/mcp-go-adapter-optional-events branch from c7ac66b to 05a0395 Compare October 1, 2026 23:52
@lucasheriques
lucasheriques force-pushed the lucas/mcp-go-adapter-optional-events branch from 05a0395 to be15306 Compare October 2, 2026 00:01
@lucasheriques
lucasheriques marked this pull request as ready for review October 2, 2026 00:16
@lucasheriques
lucasheriques requested a review from a team as a code owner October 2, 2026 00:16
@lucasheriques lucasheriques added the stamphog Request AI approval (no full review) label Oct 2, 2026
stamphog[bot]

This comment was marked as outdated.

Base automatically changed from lucas/mcp-go-conversation-anchor to main October 2, 2026 00:39
@stamphog
stamphog Bot dismissed their stale review October 2, 2026 00:39

The PR was retargeted to a different base branch, so the approved diff is no longer what was reviewed. Stamphog re-reviews automatically.

@lucasheriques
lucasheriques force-pushed the lucas/mcp-go-adapter-optional-events branch from f12ed95 to 6ce1821 Compare October 2, 2026 00:39

@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.

Not approved — this change needs a human reviewer.

Re-add the stamphog label to request another review once you have addressed this.

The PR pins posthog-go to a pseudo-version of an unmerged stacked PR's head, and its own description says not to merge in that state. The go.mod change has no go.sum update in the diff, so the build may also break.

  • Author wrote 100% of the modified lines and has 2 merged PRs in these paths (familiarity STRONG).
  • 👍 on the PR from greptile-apps[bot].
  • posthogmcpsdk/go.mod pins posthog-go to a pseudo-version of #345's head, an unmerged commit. The PR description explicitly says not to merge with it.
  • No go.sum change appears in the diff for the new pseudo-version dependency, so the module may not build or verify.
  • This is the last PR in a stack (#345, #344, #346, then this one), and the release carrying #345 does not exist yet.
Gate mechanics and policy version
Gate Result
prerequisites ✓ all clear
deny-list ✓ no deny categories matched
size ✓ 248L, 4F substantive, 795L/9F incl. docs/generated/snapshots — within ceiling
tier ✓ T1-agent / T1d-complex (795L, 9F, two-areas, feat)
stamphog 2.3.1 .stamphog/policy.yml @ 6ce1821 · reviewed head 6ce1821

@stamphog stamphog Bot removed the stamphog Request AI approval (no full review) label Oct 2, 2026
…gmcpsdk

The go-sdk adapter no longer counts an unregistered-tool call or an
input_required round as $mcp_tool_call. Unknown tools are recognised by
go-sdk's own unknown tool error, an echoed conversation handle still joins
the $mcp_unknown_tool event, and a legacy call that exhausts go-sdk's shim is
a failed call with $mcp_error_type input_required.

Tested: posthogmcpsdk go vet and go test -race on go-sdk v1.6.1 and v1.8.0
(round tests skip on v1.6.1), root go vet and posthogmcp tests, bin/api-diff,
probe cases X1 and C15 across eras.

Reviewer notes: depends on the core PR (#345) being
released; the adapter's posthog-go requirement is bumped to that release
before this leaves draft.
… the real thing

A registered tool that forwards another tool's unknown tool error was
recorded as $mcp_unknown_tool, losing the failed call. The adapter now
requires go-sdk's message to name the requested tool. A result that asks for
input next to an error is a failed call, not a round the client receives.

Tested: posthogmcpsdk go vet and go test -race -count=1 ./... on go-sdk
v1.6.1 and v1.8.0 (the new cases failed first on v1.8.0); root posthogmcp
tests; bin/api-diff.
The adapter needs the manual events API from #345, released in v1.30.0.

Tested: CI's build, vet and go test -race against the release with the replace dropped; go vet and go test -race in posthogmcpsdk.
@lucasheriques
lucasheriques force-pushed the lucas/mcp-go-adapter-optional-events branch from 6ce1821 to 2a64d90 Compare October 2, 2026 12:31
@lucasheriques lucasheriques added the stamphog Request AI approval (no full review) label Oct 2, 2026

@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.

Approved.

No showstoppers: a contained change to the MCP analytics adapter, with thorough tests, from an author with strong familiarity and no unresolved concerns. The go.mod change only bumps the sibling posthog-go module to an already released version, with no scripts or hooks.

  • Author wrote 100% of the modified lines and has 2 merged PRs in these paths (familiarity STRONG).
  • 👍 on the PR from greptile-apps[bot].
Gate mechanics and policy version
Gate Result
prerequisites ✓ all clear
deny-list ✓ no deny categories matched
size ✓ 248L, 4F substantive, 795L/9F incl. docs/generated/snapshots — within ceiling
tier ✓ T1-agent / T1d-complex (795L, 9F, two-areas, feat)
stamphog 2.3.1 .stamphog/policy.yml @ 2a64d90 · reviewed head 2a64d90

@lucasheriques
lucasheriques merged commit 83bc15e into main Oct 2, 2026
48 of 50 checks passed
@lucasheriques
lucasheriques deleted the lucas/mcp-go-adapter-optional-events branch October 2, 2026 12:53
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