Skip to content

feat(mcp): record input_required rounds as $mcp_input_required - #387

Draft
gesh wants to merge 1 commit into
mainfrom
georgis/mcp-input-required
Draft

gesh wants to merge 1 commit into
mainfrom
georgis/mcp-input-required

Conversation

@gesh

@gesh gesh commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

💡 Motivation and Context

  • A tool that asks a 2026-07-28 client for confirmation before it runs counts as two successful calls on PostHog::MCP servers.

Changes

  • PostHog::MCP.instrument sends $mcp_input_required for each round, as the spec defines and the Go SDK does. It carries the tool name, duration and request methods only.
  • For custom dispatchers, PostHog::MCP.input_request_methods(result) reads the round's methods, and PostHog::MCP::Client#capture_input_required records them.
  • On 2025-11-25 with a session, the mcp gem answers the round inside the request, so the call stays one $mcp_tool_call.
One confirmed call Before After
Round that asks $mcp_tool_call $mcp_input_required
Retry $mcp_tool_call $mcp_tool_call

Note

Spec divergence: when the gem ends a 2025-11-25 sequence itself (no session, round cap, shim turned off), the call stays a failed $mcp_tool_call typed MCP::Server::RequestHandlerError, not input_required. Only the error text tells it apart.

Example event and custom dispatcher
{
  "event": "$mcp_input_required",
  "properties": {
    "$mcp_tool_name": "delete_project",
    "$mcp_duration_ms": 3.2,
    "$mcp_input_request_methods": ["roots/list", "elicitation/create"],
    "$mcp_protocol_version": "2026-07-28",
    "$session_id": "ses_...",
    "$mcp_source": "posthog_mcp_analytics"
  }
}
prepared = posthog.prepare_tool_call(name, args, input_schema: tool[:inputSchema])
result = run_tool(name, prepared.args)
methods = PostHog::MCP.input_request_methods(result)
if methods
  posthog.capture_input_required(name, input_request_methods: methods, duration_ms: duration_ms,
                                       session_id: session_id)
else
  posthog.capture_tool_call(name, intent: prepared.intent, duration_ms: duration_ms, session_id: session_id)
end
result

💚 How did you test it?

  • New specs cover a 2026-07-28 round and retry, a requestState-only round, and the manual API. Turning off detection turns all three red.
  • Not covered: a 2025-11-25 round the gem answers, which needs a session that can reach the client. Not run against a real MCP client.

📝 Checklist

  • All commits are signed (see Commit signing)
  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

  • Claude Code with Claude Opus 5.5 (claude-opus-5-5). Skills: debugging-mcp-analytics, writing-pr-descriptions.
More context for AI agents

🤖 Generated with Claude Code

A tool that asks a 2026-07-28 client for input returns an input_required
round, and the client retries the call with the answers. Both were
recorded as successful $mcp_tool_call events, so one confirmed call
counted twice. The round now emits $mcp_input_required with the tool
name, the round's duration and each request's method, as the
sdk-specs MCP analytics spec asks. The retry stays the tool call.

PostHog::MCP::Client#capture_input_required records a round for custom
dispatchers, and PostHog::MCP.input_request_methods reads the methods
off a tool's result.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

posthog-ruby-sync Compliance Report

Date: 2026-11-25T15:51:03.866713+00:00
Duration: 94327ms

✅ All Tests Passed!

47/47 tests passed


Capture Tests

✅ 30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields ✅ 8ms
Format Validation.Event Has Uuid ✅ 5ms
Format Validation.Event Has Lib Properties ✅ 5ms
Format Validation.Distinct Id Is String ✅ 7ms
Format Validation.Token Is Present ✅ 6ms
Format Validation.Custom Properties Preserved ✅ 6ms
Format Validation.Event Has Timestamp ✅ 6ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc ✅ 5ms
Retry Behavior.Retries On 503 ✅ 5230ms
Retry Behavior.Does Not Retry On 400 ✅ 2008ms
Retry Behavior.Does Not Retry On 401 ✅ 2007ms
Retry Behavior.Respects Retry After Header ✅ 8014ms
Retry Behavior.Implements Backoff ✅ 15284ms
Retry Behavior.Retries On 500 ✅ 5155ms
Retry Behavior.Retries On 502 ✅ 5116ms
Retry Behavior.Retries On 504 ✅ 5117ms
Retry Behavior.Max Retries Respected ✅ 15643ms
Deduplication.Generates Unique Uuids ✅ 15ms
Deduplication.Preserves Uuid On Retry ✅ 5146ms
Deduplication.Preserves Uuid And Timestamp On Retry ✅ 10292ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry ✅ 5163ms
Deduplication.No Duplicate Events In Batch ✅ 16ms
Deduplication.Different Events Have Different Uuids ✅ 8ms
Compression.Sends Gzip When Enabled ✅ 5ms
Batch Format.Uses Proper Batch Structure ✅ 6ms
Batch Format.Flush With No Events Sends Nothing ✅ 2ms
Batch Format.Synchronous Capture Delivers Each Event Immediately ✅ 15ms
Error Handling.Does Not Retry On 403 ✅ 2007ms
Error Handling.Does Not Retry On 413 ✅ 2008ms
Error Handling.Retries On 408 ✅ 5153ms

Feature_Flags Tests

✅ 17/17 tests passed

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

This branch has not been deployed

No deployments
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.

1 participant