Skip to content

Navigation Menu

Sign in
Sign up

chore(mcp): enable model capture and conversation correlation by default - #944

Open
lucasheriques wants to merge 2 commits into
main from
codex/mcp-analytics-defaults
Open

chore(mcp): enable model capture and conversation correlation by default #944
lucasheriques wants to merge 2 commits into
main from
codex/mcp-analytics-defaults

Conversation

@lucasheriques

@lucasheriques lucasheriques commented Sep 11, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Motivation and changes

Model capture and conversation correlation currently require separate opt-ins. This enables both existing features by default, preserves explicit opt-outs, and leaves missing-capability reporting and feedback collection disabled for Gesh's work.

Fresh low-level server instances previously advertised analytics arguments but lacked the schema ownership information needed to capture them. A bounded lookup of the original tool catalog now resolves ownership before dispatch, follows up to 16 pages, and stops waiting after 250 ms. Lookup failures leave the tool's arguments intact. The lookup does not inject virtual tools or emit a synthetic tools/list event. Catalog handlers can therefore be invoked during a cold tool call; high-level registries and existing listing metadata avoid this fallback.

Conversation IDs add a handle to eligible tool responses. Clients must echo it to correlate later calls; callers that want existing transport session grouping and unchanged result content can explicitly disable conversation correlation. Model metadata remains unverified analytics attribution.

capture_model is also enabled on PostHogMCP; custom dispatchers continue supplying their own session IDs. Both MCP major versions resolve model ownership on fresh low-level instances. Standalone FastMCP keeps its existing version-aware registry path. Includes documentation, the updated public API snapshot, and a Sampo minor changeset.

Validation

  • MCP v1: 485 passed, 1 version-specific skip.
  • MCP v2 with standalone FastMCP 4: 432 passed, 21 version-specific skips.
  • Tests cover omitted options, explicit opt-outs, cold instances, pagination, repeated cursors, bounds, timeout, failure, and application-owned model fields; existing real ASGI wire tests also pass.
  • Ruff lint/format, mypy baseline (237 files), public API snapshot, warning-as-error import smoke test, and wheel build passed.
  • CodeScene pre-commit checks passed for the implementation and test cleanup; no new findings in the cleanup.

One feedback test still reports the existing nextCursor deprecation warning; feedback behavior is outside this change. No live model-compliance or production-ingestion test was performed.

Release

.sampo/changesets/mcp-analytics-defaults.md requests a minor release. Review and merge, then approve the normal release workflow; no package has been published from this branch.

Agent context

Autonomy: Human-driven (agent-assisted), directed by Lucas Faria.

Implemented with Codex using local shell, GitHub CLI, and CodeScene MCP. Fresh-instance failures were reproduced before implementation. Defaults changed on the existing API; no new option was introduced. Human review required.

greptile-apps[bot] reacted with thumbs up emoji
Enable both existing instrumentation features and model capture on PostHogMCP,
with explicit opt-outs. Missing-capability reporting and feedback stay disabled.
Resolve model argument ownership from bounded raw catalog lookups on fresh
low-level instances. Do not emit synthetic tools/list events, alter application
model arguments, or block dispatch when catalog resolution fails.
Validation: 486 MCP v1 tests passed (1 skipped), 433 MCP v2 tests passed
(21 skipped); Ruff lint/format, mypy baseline for 237 files, public API snapshot,
warning-as-error import and wheel build passed. CodeScene gate passed.
One feedback cursor deprecation warning remains outside the requested scope.
Include a Sampo minor changeset and document changed defaults and opt-outs.

greptile-apps Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
### Issue 1
posthog/mcp/_tool_schema.py:23-25
**Ownership lookup is not cached**
The fallback returns the resolved ownership without storing it. On a cold low-level server, each direct tool call therefore invokes the original `tools/list` handler again, potentially traversing 16 pages, repeating handler side effects, and adding up to 250 ms of latency. Cache the result in `data.tool_model_parameter_injected` before returning it.
```suggestion
 owns_model = await asyncio.wait_for(
 _find_model_ownership(name, list_page), timeout=0.25
 )
 data.tool_model_parameter_injected[name] = owns_model
 return owns_model
```
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "chore(mcp): enable model capture and con..." | Re-trigger Greptile

Comment on lines +23 to +25
return await asyncio.wait_for(
_find_model_ownership(name, list_page), timeout=0.25
)

@greptile-apps greptile-apps Bot Sep 11, 2026

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.

P2 Ownership lookup is not cached

The fallback returns the resolved ownership without storing it. On a cold low-level server, each direct tool call therefore invokes the original tools/list handler again, potentially traversing 16 pages, repeating handler side effects, and adding up to 250 ms of latency. Cache the result in data.tool_model_parameter_injected before returning it.

Suggested change
return await asyncio.wait_for(
_find_model_ownership(name, list_page), timeout=0.25
)
owns_model = await asyncio.wait_for(
_find_model_ownership(name, list_page), timeout=0.25
)
data.tool_model_parameter_injected[name] = owns_model
return owns_model

Knowledge Base Used:

Prompt To Fix With AI
This is a comment left during a code review.
Path: posthog/mcp/_tool_schema.py
Line: 23-25
Comment:
**Ownership lookup is not cached**
The fallback returns the resolved ownership without storing it. On a cold low-level server, each direct tool call therefore invokes the original `tools/list` handler again, potentially traversing 16 pages, repeating handler side effects, and adding up to 250 ms of latency. Cache the result in `data.tool_model_parameter_injected` before returning it.
```suggestion
 owns_model = await asyncio.wait_for(
 _find_model_ownership(name, list_page), timeout=0.25
 )
 data.tool_model_parameter_injected[name] = owns_model
 return owns_model
```
**Knowledge Base Used:**
- [MCP analytics instrumentation](https://app.greptile.com/posthog-org-19734/-/custom-context/knowledge-base/posthog/posthog-python/-/docs/mcp-analytics-instrumentation.md)
- [MCP framework instrumentation](https://app.greptile.com/posthog-org-19734/-/custom-context/knowledge-base/posthog/posthog-python/-/docs/mcp-framework-instrumentation.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

github-actions Bot commented Sep 11, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

posthog-python Compliance Report

Date: 2026年09月11日 19:01:20 UTC
Duration: 256382ms

✅ 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 517ms
Endpoint And Method.Does Not Use Legacy Endpoints 510ms
Required Headers.Has Authorization Bearer Header 510ms
Required Headers.Has Content Type Json 511ms
Required Headers.Has Posthog Sdk Info Format 510ms
Required Headers.Has Posthog Attempt Header 512ms
Required Headers.Has Posthog Request Id 510ms
Required Headers.Has Posthog Request Timestamp 510ms
Required Headers.Has User Agent 511ms
Body Format.Body Has Created At And Batch 509ms
Body Format.No Api Key In Body 511ms
Body Format.No Sent At In Body 510ms
Event Format.Event Has Required Root Fields 510ms
Event Format.Event Uuid Is Valid 509ms
Event Format.Event Timestamp Is Rfc3339 510ms
Event Format.Distinct Id Is String 510ms
Event Format.Distinct Id At Root Not Properties 510ms
Event Format.Custom Properties Preserved 509ms
Event Format.Set Properties Preserved 510ms
Event Format.Set Once Properties Preserved 510ms
Event Format.Groups Properties Preserved 510ms
Event Format.Sdk Generates Uuid If Not Provided 510ms
Event Format.Event Has Required Root Fields Batch 513ms
Event Format.Event Uuid Is Valid Batch 513ms
Event Format.Event Timestamp Is Rfc3339 Batch 513ms
Event Format.Distinct Id Is String Batch 513ms
Event Format.Distinct Id At Root Not Properties Batch 513ms
Event Format.Custom Properties Preserved Batch 513ms
Event Format.Set Properties Preserved Batch 514ms
Event Format.Set Once Properties Preserved Batch 513ms
Event Format.Groups Properties Preserved Batch 513ms
Event Format.Sdk Generates Uuid If Not Provided Batch 513ms
Batch Behavior.Multiple Events In Single Batch 517ms
Batch Behavior.Batch Envelope Smoke 515ms
Batch Behavior.Flush With No Events Sends Nothing 506ms
Batch Behavior.Flush At Triggers Batch 1011ms
Batch Behavior.Created At Reflects Batch Creation Time 511ms
Deduplication.Generates Unique Uuids 517ms
Deduplication.Different Events Same Content Different Uuids 512ms
Deduplication.Preserves Uuid On Retry 6517ms
Deduplication.Preserves Timestamp On Retry 6518ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 6522ms
Deduplication.No Duplicate Events In Batch 518ms
Header Behavior On Retry.Attempt Header Starts At One 510ms
Header Behavior On Retry.Attempt Header Increments On Retry 13522ms
Header Behavior On Retry.Request Id Preserved On Retry 6518ms
Header Behavior On Retry.Different Requests Have Different Request Ids 3019ms
Header Behavior On Retry.Request Timestamp Changes On Retry 6516ms
Response Format Validation.Success Response Has Uuid Keyed Results 510ms
Response Format Validation.Success Response Has Ok For Each Event 514ms
Response Format Validation.Success No Retry After When All Ok 512ms
Response Format Validation.Success Retry After Present When Retry Events 1516ms
Response Format Validation.Success No Retry After When Drop Only 513ms
Response Format Validation.Response Echoes Request Id 510ms
Retry Behavior.Retries On 408 6519ms
Retry Behavior.Retries On 500 6519ms
Retry Behavior.Retries On 503 8522ms
Retry Behavior.Retries On 504 6520ms
Retry Behavior.Retryable Errors Have Retry After 3517ms
Retry Behavior.Respects Retry After On Retryable Error 11523ms
Retry Behavior.Does Not Retry On 400 2513ms
Retry Behavior.Does Not Retry On 401 2514ms
Retry Behavior.Does Not Retry On 402 2514ms
Retry Behavior.Does Not Retry On 413 2511ms
Retry Behavior.Does Not Retry On 415 2514ms
Retry Behavior.Non Retryable Errors Have No Retry After 2512ms
Retry Behavior.Implements Backoff 22535ms
Retry Behavior.Max Retries Respected 22536ms
Partial Batch Handling.Handles 200 Full Success 2513ms
Partial Batch Handling.Handles 200 With All Ok 3518ms
Partial Batch Handling.Does Not Retry Dropped Events 3514ms
Partial Batch Handling.Does Not Retry Limited Events 3516ms
Partial Batch Handling.Prunes Ok Events On Partial Retry 6521ms
Partial Batch Handling.Prunes Dropped Events On Partial Retry 6522ms
Partial Batch Handling.Retries Only Retry Events From Partial 6522ms
Partial Batch Handling.Partial Retry Preserves Uuids 6521ms
Partial Batch Handling.Partial Retry Attempt Header Increments 6522ms
Partial Batch Handling.Partial Retry Request Id Preserved 6521ms
Partial Batch Handling.Respects Retry After On Partial 8521ms
Partial Batch Handling.Unknown Result Treated As Terminal 3513ms
Partial Batch Handling.Mixed Ok Drop Limited No Retry 3518ms
Compression.Sends Gzip Content Encoding 511ms
Compression.No Content Encoding When Disabled 510ms
Compression.Compressed Body Is Decompressible 510ms
Error Handling.Does Not Retry On Unknown 4Xx 2512ms
Event Options.Cookieless Mode Override 510ms
Event Options.Disable Skew Correction Override 510ms
Event Options.Process Person Profile Override 510ms
Event Options.Product Tour Id Override 510ms
Event Options.Unset Options Omitted 509ms
Event Options.Options Override In Batch 513ms
Geoip And Historical Migration.Geoip Disable Injected Into Properties 510ms
Geoip And Historical Migration.Historical Migration Set In Body 509ms
Geoip And Historical Migration.Historical Migration Absent By Default 510ms

Feature_Flags Tests

17/17 tests passed

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

Remove the duplicate custom-dispatcher default and opt-out test. The
existing parameterized prepare-and-capture test already covers both.
Keep the fresh-instance regressions and bounded catalog lookup coverage.
Validation: MCP v1: 485 passed, 1 skipped. MCP v2: 432 passed, 21 skipped.
Ruff lint/format and CodeScene pre-commit checks passed. The existing
feedback nextCursor deprecation warning remains outside this change.
Runtime behavior is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@greptile-apps greptile-apps[bot] greptile-apps[bot] left review comments

At least 1 approving review is required to merge this pull request.

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

1 participant

AltStyle によって変換されたページ (->オリジナル) /