Skip to content

feat(mcp): add tool-call telemetry, metrics, usage events and the stdio server - #21588

Open
nwadams wants to merge 6 commits into
na--mcp-settingsfrom
na--mcp-telemetry-and-stdio
Open

nwadams wants to merge 6 commits into
na--mcp-settingsfrom
na--mcp-telemetry-and-stdio

Conversation

@nwadams

@nwadams nwadams commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

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 master as #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.

  • Anonymous tool-call telemetry: the standalone mcp-server-datahub's Mixpanel events, sent through the SDK's telemetry. That's one event per tool call plus a start event.
    • Error messages are left out, since they can carry user data.
    • Sends happen on a background thread behind a bounded queue, so they never hold up a call.
    • Off when the SDK's telemetry is off.
  • Prometheus metrics at /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=false turns it off.
  • Usage events: MCP tool calls are recorded as DataHub usage events.
  • GMS tracking-event attribution: tracking events are now attributed to the authenticated actor.
  • datahub-mcp-stdio: a local stdio MCP server in datahub-core-mcp-tools, replacing uvx mcp-server-datahub.

Testing

  • Python: datahub-core-mcp-tools and datahub-ai-service lint and testQuick: 904 and 102 tests.
  • Java: TrackingControllerTest and DataHubUsageEventTypeTest.

Checklist

🤖 Generated with Claude Code

@github-actions github-actions Bot added devops PR or Issue related to DataHub backend & deployment smoke_test Contains changes related to smoke tests labels Nov 24, 2026
@cursor

cursor Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Summary

Overview
Adds observability and local MCP around the HTTP datahub-ai-service and shared datahub-core-mcp-tools stack.

Prometheus — Unauthenticated /metrics with counters/histograms for MCP tool outcomes, auth refusals, GMS latency/errors, and dropped usage-event queue items (DATAHUB_AI_METRICS_ENABLED).

Product telemetry — Shared ToolCallRecorder / TelemetryPing in datahub-core-mcp-tools sends anonymous mcp-server-start and mcp-server-tool-call events via the DataHub SDK on a bounded background queue (no arguments, results, or caller identity).

Usage analytics — Each MCP tool call can emit a ToolInvocation usage event to GMS /openapi/v1/tracking/track using the caller's token (DATAHUB_AI_USAGE_EVENTS_ENABLED); GMS now stamps actorUrn from the authenticated session, ignoring client-supplied actors.

datahub-mcp-stdio — New CLI entry point serving the same tools over stdin/stdout with shared no-replay GMS retry policy.

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.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Smart test selection

pytest smoke tests

Mode: shadow. The selection below is computed but not applied; this PR still runs the default matrix (p0).

  • Selection: smart: tests for the tagged features, plus always-run modules, this PR's changed tests, and the plumbing sample if the PR changes the pytest harness
  • Size: 345 of 845 tests in 2 batches, predicted longest batch ~6 min
  • Tags: change-type: build, docs, test-infra; feature-dev: authentication, executor, feature-flags, semantic-search, system-metadata; feature-user: analytics, authorization, search; technical-layer: cli, openapi
  • Confidence: MEDIUM (29 changed files)
  • Classifier reasoning: Changes add ToolInvocation usage events and tracking controller actor stamping (analytics, openapi), MCP service auth/metrics/telemetry and stdio tooling (authentication, executor-like client retries, cli), plus lockfile/pyproject dependency bumps and tests as build and test-infra.

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)
  • tests/e2e/actions/doc_propagation/test_propagation.py
  • tests/e2e/actions/test_actions_shutdown.py
  • tests/e2e/analytics/test_analytics.py
  • tests/e2e/analytics/test_highlights.py
  • tests/e2e/authorization/test_aspect_write_auth.py
  • tests/e2e/authorization/test_container_view_auth.py
  • tests/e2e/authorization/test_credential_aspect_read_auth.py
  • tests/e2e/authorization/test_domain_scoped_create_entity_auth.py
  • tests/e2e/authorization/test_domain_scoped_create_entity_auth.py::TestDomainScopedCreateEntityAuth
  • tests/e2e/authorization/test_privilege_constraints_writes.py
  • tests/e2e/authorization/test_privilege_grant_auth.py
  • tests/e2e/authorization/test_query_entity_read_auth.py
  • tests/e2e/authorization/test_self_entity_auth.py
  • tests/e2e/authorization/test_view_entity_queries_privilege.py
  • tests/e2e/browse/browse_test.py
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchBasic
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchDiagnose
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchDryRun
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchErrorHandling
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchFilterCombinations
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchFiltersByEntityType
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchFiltersByPlatform
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchPagination
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchProjectionLive
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchWhereFilter
  • tests/e2e/dev_tooling/test_dev_tooling.py
  • tests/e2e/frontend/test_static_asset_encodings.py
  • tests/e2e/managed_ingestion/managed_ingestion_test.py
  • tests/e2e/mcp/mcp_test.py
  • tests/e2e/openapi/v1/test_tracking.py
  • tests/e2e/platform_resources/test_platform_resource.py
  • tests/e2e/policies/test_policies.py
  • tests/e2e/policies/test_policy_eval_perf.py
  • tests/e2e/privileges/test_privileges.py
  • tests/e2e/query_projection/test_query_projection_smoke.py
  • tests/e2e/read_only/test_analytics.py
  • tests/e2e/read_only/test_policies.py
  • tests/e2e/read_only/test_search.py
  • tests/e2e/read_only/test_services_up.py
  • tests/e2e/search/test_lineage_search_index_fields.py
  • tests/e2e/search/test_search_projection.py::TestSearchProjection
  • tests/e2e/semantic/test_classical_embedding_provider.py::TestClassicalEmbeddingProvider
  • tests/e2e/semantic/test_config_fingerprint.py::TestConfigFingerprint
  • tests/e2e/semantic/test_current_offset_api.py
  • tests/e2e/semantic/test_event_driven_docs.py::TestEventDrivenDocumentIngestion
  • tests/e2e/semantic/test_event_mode_fallback.py::TestEventModeFallback
  • tests/e2e/semantic/test_local_embedding_provider.py::TestLocalEmbeddingProvider
  • tests/e2e/semantic/test_semantic_search.py::TestSemanticSearchWithIngestion
  • tests/e2e/semantic/test_source_type_filtering.py::TestSourceTypeFiltering
  • tests/e2e/semantic/test_stateful_ingestion.py::TestStatefulIngestion
  • tests/e2e/service_accounts/test_service_accounts.py
  • tests/e2e/siblings/siblings_search_batching_test.py
  • tests/e2e/status/test_lifecycle_state.py::TestLifecycleStageAPIs
  • tests/e2e/telemetry/telemetry_test.py
  • tests/e2e/test_authentication_e2e.py
  • tests/e2e/test_e2e.py
  • tests/e2e/test_system_info.py
  • tests/e2e/timeline/timeline_change_history_auth_test.py
  • tests/e2e/tokens/revokable_access_token_test.py
  • tests/e2e/tokens/session_access_token_test.py
  • tests/e2e/trace/test_api_trace.py

Add the run-all-tests:pytest label to run the full pytest suite on this PR.

Playwright E2E tests

This run: p0

  • Selection: p0: P0 tests plus the tests the change affects
  • Smart selection (shadow, not run): smart, 19 spec files (~14 min predicted on 2 shard(s)): specs tagged analytics, authentication, authorization, executor, feature-flags, search, semantic-search, system-metadata plus the tests the change affects
  • Size: 144 tests in 78 spec files, ~32 min predicted on 5 shard(s)
  • Baseline: 78 spec files run for every PR (@p0)
  • No spec was selected because of this PR's changes.

Add the run-all-tests:playwright label to run the full Playwright suite on this PR.

commit 577e6d6 · workflow run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@codecov

codecov Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@nwadams
nwadams force-pushed the na--mcp-telemetry-and-stdio branch from f2cd1a0 to b7209c5 Compare November 25, 2026 14:40

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

nwadams and others added 6 commits November 25, 2026 10:23
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>
@nwadams
nwadams force-pushed the na--mcp-telemetry-and-stdio branch from b7209c5 to 577e6d6 Compare November 25, 2026 17:26

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 577e6d6. Configure here.

This branch was successfully deployed

1 active deployment
Preview — 577e6d69 Deployed Nov 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devops PR or Issue related to DataHub backend & deployment smoke_test Contains changes related to smoke tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants