Repository navigation
Conversation
PR SummaryOverview Prometheus — Unauthenticated Product telemetry — Shared Usage analytics — Each MCP tool call can emit a
Docs and tests cover metrics, telemetry, usage events, tracking attribution, and stdio parity with the HTTP service. Reviewed by Cursor Bugbot for commit 577e6d6. Bugbot is set up for automated code reviews on this repo. Configure here. |
Smart test selectionpytest smoke testsMode: shadow. The selection below is computed but not applied; this PR still runs the default matrix (
Medium confidence: a wrong tag means tests are skipped, so check the tags above against what this PR touches. Selected scopes (61 files or classes, 345 tests)
Add the Playwright E2E testsThis run:
Add the commit |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Bundle ReportBundle size has no change ✅ |
ec58da1 to
f2cd1a0
Compare
057f5a0 to
c72ba73
Compare
c72ba73 to
d5fcb96
Compare
f2cd1a0 to
b7209c5
Compare
Brings the standalone mcp-server-datahub's product telemetry to the shared tools package, so the datahub-ai-service (and the coming stdio wrapper) send the same Mixpanel events through the SDK's telemetry_instance. datahub_core_mcp_tools.telemetry: - ToolCallRecorder: middleware that measures each tool call and hands a ToolCall record to sinks; a failing sink is logged, never raised. - TelemetryPing / TelemetryMiddleware: one "mcp-server-tool-call" event per call with the legacy properties (tool, source, type, method, client_name, client_version, http_user_agent, tool_result_length, duration_seconds, tool_call_cancelled, tool_call_error as the error class, tool_result_is_error) plus deployment and the GMS's server_version / server_env. tool_call_error_message is dropped: messages can carry user data. Client info comes from the initialize handshake for handshake-era clients and from each request's _meta for 2026-era stateless clients. - ping_server_start: one "mcp-server-start" event. - Sends run on a daemon thread behind a bounded queue (dropped when full), so a slow or blackholed collector, the SDK's first-event caller detection and the GMS version lookup never hold up a call. Nothing is built when the SDK's telemetry is off (DATAHUB_TELEMETRY_ENABLED=false, CI, or `datahub telemetry disable`). The service records calls once and feeds both its existing observers and the product ping; events add auth_mode (token/off, never the actor) and response_mode, the global datahub_ai_service_version, and the service sends mcp-server-start at boot. README documents what is sent and the opt-out. Tested: unit tests with a fake ping (legacy and 2026 clients, error class only, slow and broken pings, server start, SDK opt-out) and service tests for the start and per-call events under token and auth-off callers. Live against a local GMS with a recording ping: start and per-call events carry the expected properties. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Operators can now scrape datahub-ai-service directly. /metrics is
unauthenticated like /health and is not proxied by the frontend (which
forwards only /mcp). DATAHUB_AI_METRICS_ENABLED=false turns it off.
Metrics, in a registry of the service's own plus process/platform/GC:
- datahub_ai_mcp_tool_calls_total{tool, outcome=ok|error|cancelled} and
datahub_ai_mcp_tool_call_duration_seconds{tool}, fed by the shared
tool-call recorder. Only registered tool names become labels; any other
name a client sends is counted as "other".
- datahub_ai_mcp_auth_failures_total{reason}, one per refused /mcp request
(missing_token, invalid_token, datahub_unavailable, datahub_auth_off,
forbidden_host).
- datahub_ai_gms_request_duration_seconds{endpoint} and
datahub_ai_gms_request_errors_total{endpoint, kind} for the per-caller GMS
clients (timeout, connection, rejected, throttled, server_error).
- datahub_ai_usage_events_dropped_total, incremented by the usage-event
sender that follows.
Adds prometheus-client to the service and the image lock. Regenerating the
lock also picks up python-utils 4.2.1, which the lockfile check resolves
today.
Tested: app-level tests for call outcomes, the "other" label, auth refusals
and the disabled switch; client-factory test for GMS latency, 5xx and
timeouts. Live against a local GMS: get_me, search and a failing
get_entities moved the call counters (ok/ok/error), an unauthenticated
request counted as missing_token, and GMS GraphQL latency was recorded.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each tool call served at /mcp now becomes one ToolInvocation event in DataHub's own usage analytics, so admins can see who uses MCP and which tools. The service posts it to GMS's POST /openapi/v1/tracking/track with the caller's own credential. Event fields (camelCase, like the frontend's): type "ToolInvocation", surface "mcp", actorUrn, timestamp, toolServer "datahub", toolName, toolGroup (read/write, from the tool's mutation tag), clientName, clientVersion, userAgent, durationMs, resultLength, isError, errorType (the exception class; "Cancelled" for a cancelled call). Never tool arguments or results. Calls to names that aren't registered tools are not recorded, so a client can't write arbitrary toolName values. Identity: actorUrn is the identity GMS verified for the caller's token (or GMS's system user, urn:li:corpuser:__datahub_system, while GMS auth is off), never anything from tool arguments, _meta or headers. The actor and credential are captured inside the call's own request when it finishes, so a queued event can't borrow another request's identity; the token is never logged. Delivery is fire-and-forget: a bounded queue (1000) and one background sender thread per service; overflow is dropped and counted in datahub_ai_usage_events_dropped_total, and GMS errors never reach the call. The queue is flushed (briefly) at shutdown. DATAHUB_AI_USAGE_EVENTS_ENABLED=false turns it off (default on). The shared ToolCallRecorder now records each called tool's tags, and its background dispatcher takes a drop callback and can be closed. Tested: event shape, write-group and failure events, unknown tool names skipped, two concurrent callers each recorded with their own actor and token, a client spoofing the actor through _meta and headers, auth-off system actor, the off switch, queue overflow counted without blocking, and a failing GMS not affecting calls. Live against a local GMS with a PAT: GMS accepted the events (HTTP 200) and published them with the PAT owner's actorUrn; with the switch off, none were sent. GMS's usage-event indexer still drops type ToolInvocation (not in DataHubUsageEventType) until the companion GMS change adds it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
POST /openapi/v1/tracking/track used the actorUrn in the posted body when there was one, so any authenticated caller could record usage events (in the usage index, Kafka and Mixpanel) as someone else. The controller now stamps actorUrn with the actor that authenticated the request before tracking, whatever the body says. The frontend is unaffected: it proxies events with the signed-in user's credentials (or X-DataHub-Actor while GMS auth is off), so the authenticated actor is the same user. With GMS auth off and no actor header, events are the system user's; a request GMS could not authenticate, where the path is not enforced, is recorded as the anonymous actor rather than one it names. Also adds ToolInvocation to DataHubUsageEventType. datahub-ai-service posts one per MCP tool call, and the usage-event indexer drops types it doesn't know, so without it those events never reach the usage index. The tracking smoke tests still post a claimed actor and now expect the session's own actor back. Tested: TrackingControllerTest (a supplied actor is replaced, a missing one is stamped, an anonymous request can't claim one) and DataHubUsageEventTypeTest. Not live-tested: it needs a GMS rebuild. The smoke tests were not run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`uvx --from datahub-core-mcp-tools datahub-mcp-stdio` serves DataHub's MCP tools to one local user over stdin/stdout, with no service installed: the replacement for running the standalone mcp-server-datahub in stdio mode. - build_stdio_server(client, *, groups=None, server_info=None, telemetry_ping=...) builds a FastMCP server with the same register_tools registration and switches as the service (TOOLS_IS_MUTATION_ENABLED, SEMANTIC_SEARCH_ENABLED, per-tool flags), the GMS version filter, the connected GMS's version in each call's tool context, and product telemetry with deployment "stdio". Hosts can embed it (an agent, a test) on any transport. - main() (console script datahub-mcp-stdio) builds the client with the SDK's DataHubClient.from_env, as the legacy server did: DATAHUB_GMS_URL / DATAHUB_GMS_TOKEN, else ~/.datahubenv; no token needed when GMS auth is off. Sends mcp-server-start, logs at INFO to stderr (stdout carries the protocol). No usage events and no MCP settings. - README: client configuration and embedding. Tested: a subprocess round trip through the console script against a fake GMS (tool list, get_me with the token sent, writes hidden with TOOLS_IS_MUTATION_ENABLED=false); an embedded server with group selection and stdio telemetry; and, in the service's tests, the stdio server lists exactly the service's tools for GMS 1.3.0 and 1.10.0 with writes on and off. Live: the console script against a local GMS with a PAT listed 27 tools (12 with writes off), get_me returned the PAT's user and search returned results. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Move the no-replay retry policy (retry only refused connections and 429s) from datahub-ai-service's client_factory into datahub_core_mcp_tools.client_retries; the service now reuses it. - datahub-mcp-stdio builds its client with client_from_env(), which applies that policy, so a write tool is never sent twice when GMS fails with a 5xx or a read timeout after running it. - Test that the stdio client sends a POST once on a 5xx and retries 429s. - Test that stateless HTTP tool calls record the client's name and version, including a request that names its client only in _meta. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
d5fcb96 to
eef657a
Compare
b7209c5 to
577e6d6
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 577e6d6. Configure here.
| "errorType": "Cancelled" if call.cancelled else call.error_type, | ||
| } | ||
| event.update({k: v for k, v in optional.items() if v is not None}) | ||
| return event |
There was a problem hiding this comment.
Parallel usage events can collide
Medium Severity
Each ToolInvocation is indexed under type + actorUrn + timestamp (millisecond resolution). Two tool calls from the same user in the same millisecond share that id, so Elasticsearch keeps only one. Agents often invoke tools in parallel, so usage analytics silently drops calls.
Reviewed by Cursor Bugbot for commit 577e6d6. Configure here.


Stack. Part of the series that adds a built-in MCP server to DataHub Core. Based on
na--mcp-settings(#21587); review only its own commits.Stack so far:
1–22. Merged to
masteras #21332.23–34. #21435, the read tools.
35–46. #21501, the write tools (PRs 36–46 merged into it).
47–55. #21587, MCP settings: model, API and UI.
56–60. #21588, telemetry, metrics, usage events and the stdio server. ← this PR
61–64. #21589, docs, release notes and smoke tests.
65–68. #21590, settings enforcement and the tool catalog.
69–70. #21591, the home page module.
71–74. #21623, the ingestion tools.
What this does
Telemetry, metrics, usage events and the local stdio server. It combines what would have been stack PRs 56–60, one commit each.
mcp-server-datahub's Mixpanel events, sent through the SDK's telemetry. That's one event per tool call plus a start event./metrics: tool calls and their duration by tool and outcome, auth failures, GMS request timings and errors, and dropped usage events.DATAHUB_AI_METRICS_ENABLED=falseturns it off.datahub-mcp-stdio: a local stdio MCP server indatahub-core-mcp-tools, replacinguvx mcp-server-datahub.Testing
datahub-core-mcp-toolsanddatahub-ai-servicelint and testQuick: 904 and 102 tests.TrackingControllerTestandDataHubUsageEventTypeTest.Checklist
🤖 Generated with Claude Code