Add event_tags and event_properties callbacks#29
Open
kashishhora wants to merge 1 commit intomainfrom
Open
Conversation
Port the event tags & properties feature from the TypeScript SDK. Two new callbacks on MCPCatOptions attach customer-defined metadata to every auto-captured event (initialize, tools/list, tools/call): - event_tags: dict[str, str], validated client-side (max 50 entries, key regex [a-zA-Z0-9$_.:\- ] <=32 chars, value <=200 chars, no newlines). Invalid entries dropped with warning. - event_properties: dict[str, Any], flexible JSON, no validation. Both fields are top-level on the published event and bypass the redaction/sanitization/truncation pipeline. Callbacks accept sync or async callables; async results are awaited transparently. Exporter updates: - Every outbound event now carries source=mcpcat (via new MCPCAT_SOURCE constant) so consumers can filter by provenance. - Customer tags are namespaced under mcpcat.* in Datadog ddtags, Sentry tags, and as mcpcat.tag.* OTLP span attributes to avoid collisions with each platform's reserved tag keys. - Sentry properties moved from deprecated `extra` into a `contexts.mcpcat` entry via a new build_contexts() helper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two new callbacks on
MCPCatOptions—event_tagsandevent_properties— that let customers attach custom metadata to every auto-captured event (initialize, tools/list, tools/call). Ports the equivalent feature from the TypeScript SDK (PR #32 there).event_tags:dict[str, str], validated client-side (regex on keys, length caps, max 50 entries, no newlines in values). Invalid entries are dropped with a warning.event_properties:dict[str, Any], arbitrary JSON-serializable metadata, no validation.Why
Customers want to filter/group events by structured metadata they control — trace IDs, environments, deployment regions, feature flags. Until now there's no way to attach that kind of data through the SDK.
Exporter changes worth flagging
source=mcpcat(newMCPCAT_SOURCEconstant). Makes MCPcat events distinguishable from other telemetry flowing into the customer's observability backend.mcpcat.<key>in Datadog ddtags and Sentry tags,mcpcat.tag.<key>as OTLP span attributes. Prevents collisions with reserved tag keys (environment,release,host,service, etc.).extrafield intocontexts.mcpcat.Test plan
uv run python -m pytest tests/test_event_tags_properties.py tests/test_tag_validation.py -v— 34 tests passuv run python -m pytest— full regression greenEventSerializer.Notes
RedactionFunction. If the callback returns a coroutine, the resolver awaits it; otherwise passes through.validate_tagsexactly, so client- and server-side drop behavior is consistent.identifyremains sync-only for now — making it async-compatible is a separate (small) change.