feat(MCP): Emit session and tool call events#7707
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 3 Skipped Deployments
|
Docker builds report
|
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-16)Details
Playwright Test Results (oss - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)Details
Playwright Test Results (private-cloud - depot-ubuntu-latest-16)Details
|
Visual Regression19 screenshots compared. See report for details. |
b43159c to
7298c54
Compare
Contributes to Flagsmith/flagsmith-private#152. A middleware emits structured events on the mcp domain, identifying clients by their self-declared clientInfo from the initialize handshake — User-Agents proved unreliable (most TS SDK clients send runtime defaults), and raw names beat server-side allow-lists, so classification happens downstream: - session.opened on initialize, with flagsmith.client.name/version - tool.called for every tools/call, with tool, client, status and duration A span processor annotates FastMCP's server spans with the same flagsmith.client.* attributes. The flagsmith. namespace avoids squatting on the semconv mcp. and client. namespaces; flagsmith-common already emits flagsmith.event. beep boop
Instrument the Flagsmith API httpx client (instance-only, via opentelemetry-instrumentation-httpx) so every upstream call emits a client span and carries W3C trace context and baggage. A middleware sets flagsmith.tool.name and flagsmith.client.name/version as baggage per tool call; the API's existing OTel pipeline extracts baggage and copies it onto its own events, giving per-client, per-tool visibility on both sides of the boundary. beep boop
Set the client identity and tool name once, as W3C Baggage, and copy flagsmith.* entries onto spans with a span processor — replacing the separate clientInfo span annotation. The off-the-shelf opentelemetry-processor-baggage reads baggage from the span's parent context, which FastMCP builds from the request _meta without baggage, so the processor reads the current context instead. beep boop
Write flagsmith.client.name/version as span attributes directly, and pass all of the current span's attributes — MCP method, tool, session and client identity — as W3C Baggage on outbound Flagsmith API requests via an httpx event hook scoped to the API client only. Replaces the baggage-attaching middleware: process context is never touched, and the API receives the full call context whenever tracing is enabled. beep boop
Send flagsmith.client.name=flagsmith-mcp on every span and API-bound baggage header — the API's immediate caller — and move the MCP client's self-declared identity to flagsmith.mcp.client.name/version across spans, baggage and events. Spans now record without an OTLP endpoint too (in-process only), so the API receives baggage regardless of whether telemetry export is enabled. beep boop
Thanks for submitting a PR! Please check the boxes below:
docs/if required so people know about the feature.Changes
Contributes to Flagsmith/flagsmith-private#152.
Identify MCP clients by their
initializeclientInfo (User-Agents proved unreliable; raw values, classification happens downstream) and make the identity visible on all three telemetry surfaces:mcp.session.openedandmcp.tool.called(tool, status,flagsmith.mcp.client.name/version).flagsmith.client.name=flagsmith-mcp(this service, as the API's caller) andflagsmith.mcp.client.*(the end client). Spans record even without an OTLP endpoint; export stays gated on it.traceparent, plus all current span attributes as W3Cbaggagevia a request hook — the API's OTel pipeline already copies baggage onto its events.How did you test this code?
Unit/integration tests at 100% coverage, including the exact
baggageheader on upstream requests. Verified live against a local capture server, with and withoutOTEL_EXPORTER_OTLP_ENDPOINT.