Skip to content

feat(mcp): enable model and conversation capture by default - #278

Open
lucasheriques wants to merge 1 commit into
mainfrom
feat/mcp-defaults
Open

lucasheriques wants to merge 1 commit into
mainfrom
feat/mcp-defaults

Conversation

@lucasheriques

Copy link
Copy Markdown

Summary

  • Enable capture_model by default for instrumented MCP servers.
  • Enable enable_conversation_id by default.
  • Match the custom-dispatcher prepare_tool_list model default.
  • Keep explicit false values as opt-outs.
  • Keep report_missing off, exception capture on, and context capture on.

Why

The latest JavaScript and Python MCP SDKs enable model capture and conversation correlation by default. Ruby should produce the same useful analytics from the one-line setup.

A valid echoed conversation handle takes precedence over transport sessions. Tests that specifically verify transport-based grouping now disable conversation correlation explicitly.

Verification

  • bundle exec rspec - 1,202 examples, 0 failures
  • bundle exec rubocop - 127 files, 0 offenses
  • bundle exec rake public_api:check - passed

Includes a minor changeset.

Match the current JavaScript and Python MCP SDK defaults for both instrumented servers and custom dispatcher tool schemas. Keep explicit false values as opt-outs and isolate transport-session tests from conversation anchoring.

Verified with:
- bundle exec rspec (1202 examples, 0 failures)
- bundle exec rubocop (127 files, 0 offenses)
- bundle exec rake public_api:check
@lucasheriques
lucasheriques requested a review from a team as a code owner September 23, 2026 12:51
@github-actions

Copy link
Copy Markdown

posthog-ruby-async Compliance Report

Date: 2026-09-23T12:53:33.643579+00:00
Duration: 98711ms

⚠️ Some Tests Failed

46/47 tests passed, 1 failed


Capture Tests

30/30 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 109ms
Format Validation.Event Has Uuid 106ms
Format Validation.Event Has Lib Properties 108ms
Format Validation.Distinct Id Is String 106ms
Format Validation.Token Is Present 106ms
Format Validation.Custom Properties Preserved 106ms
Format Validation.Event Has Timestamp 106ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc 8ms
Retry Behavior.Retries On 503 5311ms
Retry Behavior.Does Not Retry On 400 2108ms
Retry Behavior.Does Not Retry On 401 2108ms
Retry Behavior.Respects Retry After Header 8115ms
Retry Behavior.Implements Backoff 15722ms
Retry Behavior.Retries On 500 5212ms
Retry Behavior.Retries On 502 5212ms
Retry Behavior.Retries On 504 5212ms
Retry Behavior.Max Retries Respected 15722ms
Deduplication.Generates Unique Uuids 111ms
Deduplication.Preserves Uuid On Retry 5211ms
Deduplication.Preserves Uuid And Timestamp On Retry 10416ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5215ms
Deduplication.No Duplicate Events In Batch 112ms
Deduplication.Different Events Have Different Uuids 107ms
Compression.Sends Gzip When Enabled 106ms
Batch Format.Uses Proper Batch Structure 106ms
Batch Format.Flush With No Events Sends Nothing 4ms
Batch Format.Multiple Events Batched Together 109ms
Error Handling.Does Not Retry On 403 2108ms
Error Handling.Does Not Retry On 413 2108ms
Error Handling.Retries On 408 5212ms

Feature_Flags Tests

⚠️ 16/17 tests passed, 1 failed

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

Failures

request_payload.disable_geoip_omitted_defaults_to_false

Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['distinct_id', 'groups', 'person_properties', 'group_properties', 'flag_keys_to_evaluate', 'token']

@github-actions

Copy link
Copy Markdown

posthog-ruby-sync Compliance Report

Date: 2026-09-23T12:53:38.839702+00:00
Duration: 93993ms

⚠️ Some Tests Failed

45/47 tests passed, 2 failed


Capture Tests

⚠️ 29/30 tests passed, 1 failed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 9ms
Format Validation.Event Has Uuid 6ms
Format Validation.Event Has Lib Properties 6ms
Format Validation.Distinct Id Is String 9ms
Format Validation.Token Is Present 7ms
Format Validation.Custom Properties Preserved 7ms
Format Validation.Event Has Timestamp 7ms
Format Validation.Non Utc Event Timestamp Is Converted To Utc 7ms
Retry Behavior.Retries On 503 5241ms
Retry Behavior.Does Not Retry On 400 2008ms
Retry Behavior.Does Not Retry On 401 2011ms
Retry Behavior.Respects Retry After Header 8013ms
Retry Behavior.Implements Backoff 15232ms
Retry Behavior.Retries On 500 5115ms
Retry Behavior.Retries On 502 5150ms
Retry Behavior.Retries On 504 5142ms
Retry Behavior.Max Retries Respected 15592ms
Deduplication.Generates Unique Uuids 20ms
Deduplication.Preserves Uuid On Retry 5115ms
Deduplication.Preserves Uuid And Timestamp On Retry 10255ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5150ms
Deduplication.No Duplicate Events In Batch 18ms
Deduplication.Different Events Have Different Uuids 9ms
Compression.Sends Gzip When Enabled 6ms
Batch Format.Uses Proper Batch Structure 7ms
Batch Format.Flush With No Events Sends Nothing 3ms
Batch Format.Multiple Events Batched Together 17ms
Error Handling.Does Not Retry On 403 2008ms
Error Handling.Does Not Retry On 413 2010ms
Error Handling.Retries On 408 5152ms

Failures

batch_format.multiple_events_batched_together

Expected 1 requests, got 5

Feature_Flags Tests

⚠️ 16/17 tests passed, 1 failed

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

Failures

request_payload.disable_geoip_omitted_defaults_to_false

Field 'geoip_disable' not found in /flags request body at path 'geoip_disable'. Available keys: ['distinct_id', 'groups', 'person_properties', 'group_properties', 'flag_keys_to_evaluate', 'token']

@greptile-apps

greptile-apps Bot commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Retrigger

The PR should not merge until the documented custom-dispatcher model-capture opt-out also prevents call-time extraction and telemetry capture.

Reviews (1) · Last reviewed commit: "feat(mcp): enable model and conversation..."

Comment thread lib/posthog/mcp/client.rb
# @param tools [Array<Hash>] `tools/list` entries
# @return [Array<Hash>]
def prepare_tool_list(tools, context: true, report_missing: false, capture_model: false)
def prepare_tool_list(tools, context: true, report_missing: false, capture_model: true)

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.

P1 Model opt-out is bypassed

Passing capture_model: false only removes llm_model from the advertised schema. prepare_tool_call does not receive or retain that setting, so if an agent still sends llm_model, the method strips the value from the tool arguments and returns it for analytics capture. This makes the documented opt-out ineffective and differs from the wrapped-server path, which gates extraction on capture_model_enabled?. Preserve the setting through call preparation so disabling model capture also prevents extracting and recording the value.

Knowledge Base Used:

Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/posthog/mcp/client.rb
Line: 124

Comment:
**Model opt-out is bypassed**

Passing `capture_model: false` only removes `llm_model` from the advertised schema. `prepare_tool_call` does not receive or retain that setting, so if an agent still sends `llm_model`, the method strips the value from the tool arguments and returns it for analytics capture. This makes the documented opt-out ineffective and differs from the wrapped-server path, which gates extraction on `capture_model_enabled?`. Preserve the setting through call preparation so disabling model capture also prevents extracting and recording the value.

**Knowledge Base Used:**
- [MCP analytics integration](https://app.greptile.com/posthog-org-19734/-/custom-context/knowledge-base/posthog/posthog-ruby/-/docs/mcp-analytics-integration.md)
- [MCP server lifecycle instrumentation](https://app.greptile.com/posthog-org-19734/-/custom-context/knowledge-base/posthog/posthog-ruby/-/docs/mcp-server-lifecycle-instrumentation.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@marandaneto
marandaneto requested a review from a team September 24, 2026 09:55

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