Skip to content

Enterprise agent platform for building, deploying, and operating AI teammates.

feat(connector-checks): check Mixpanel with the Engage call, which the Free plan answers (#3826)

xiaoleia9b36ee64b88
diff --git a/src/xagent/web/connector_checks/registry.py b/src/xagent/web/connector_checks/registry.py
index d7641ca9d..b2e01854d 100644
--- a/src/xagent/web/connector_checks/registry.py
+++ b/src/xagent/web/connector_checks/registry.py
@@ -197,6 +197,16 @@ def _declared_l3(app_id: str) -> ReadCheck:
return check
+# Mixpanel's Free plan refuses the Query API ("your plan does not allow API
+# calls") and answers only the user-profile (Engage) call, so Mixpanel's check
+# is Engage, not the L3 probe (`mixpanel_list_event_names`, a Query API call).
+_MIXPANEL_QUERY_API_NEEDS_A_PAID_PLAN = (
+ "read that the test project's Free plan refuses with 'your plan does not "
+ "allow API calls'; whether it gets a check once the project has a plan "
+ f"with the Query API is decided in {_TIER_2}"
+)
+
+
def _xero_list_check(list_field: str, *, paged: bool, capped: bool = True) -> ReadCheck:
"""A structural read check on one of Xero's list tools that take no id.
@@ -1847,6 +1857,47 @@ CONNECTOR_CHECKS: Mapping[str, ConnectorChecks] = {
writes_without_cleanup=("linear_create_issue", "linear_add_comment"),
),
),
+ "mixpanel": ConnectorChecks(
+ "mixpanel",
+ reads=(
+ ReadCheck(
+ "mixpanel.query_engage",
+ "mixpanel_query_engage",
+ {},
+ assertions=(
+ StatusSuccess(),
+ HasKeys((), ("engage", "truncated")),
+ HasKeys(("engage",), ("page", "page_size", "results", "total")),
+ IsType(("engage", "results"), "array"),
+ IsType(("engage", "total"), "number"),
+ IsType(("truncated",), "boolean"),
+ ),
+ ),
+ ),
+ exemptions=(
+ *(
+ ToolExemption(tool, _MIXPANEL_QUERY_API_NEEDS_A_PAID_PLAN)
+ for tool in (
+ "mixpanel_list_event_names",
+ "mixpanel_get_top_events",
+ "mixpanel_list_funnels",
+ )
+ ),
+ *_exemptions(
+ issue=_TIER_2,
+ reads=(
+ "mixpanel_get_event_properties",
+ "mixpanel_query_user_activity",
+ "mixpanel_query_segmentation",
+ "mixpanel_query_retention",
+ "mixpanel_query_funnel",
+ "mixpanel_list_annotations",
+ "mixpanel_export_events",
+ ),
+ writes_without_cleanup=("mixpanel_create_annotation",),
+ ),
+ ),
+ ),
"intercom": ConnectorChecks(
"intercom",
reads=(
@@ -2043,7 +2094,6 @@ LEGACY_CONNECTORS: frozenset[str] = frozenset(
"linkedin",
"magento",
"meta-ads",
- "mixpanel",
"myob",
"posthog",
"rocketlane",
diff --git a/tests/web/connector_checks/test_mixpanel_checks.py b/tests/web/connector_checks/test_mixpanel_checks.py
new file mode 100644
index 000000000..1ed5d4af1
--- /dev/null
+++ b/tests/web/connector_checks/test_mixpanel_checks.py
@@ -0,0 +1,143 @@
+"""Smoke V2 check of Mixpanel (#3573).
+
+The declaration is pinned in ``test_registry.py`` (``_TIER_2_READS``). Mixpanel's
+Free plan refuses the Query API and answers the user-profile (Engage) call, so
+the one check is Engage and the connector has left ``LEGACY_CONNECTORS``, whose
+L3 probe is a Query API call. This runs the declared call against the real tool
+with only the vendor request replaced, and judges what the tool returns with the
+check's own assertions.
+"""
+
+from __future__ import annotations
+
+import json
+from typing import Any
+
+import pytest
+
+from xagent.web.connector_checks.assertions import judge_result
+from xagent.web.connector_checks.declarations import ReadCheck
+from xagent.web.connector_checks.registry import (
+ _MIXPANEL_QUERY_API_NEEDS_A_PAID_PLAN,
+ CONNECTOR_CHECKS,
+ LEGACY_CONNECTORS,
+)
+from xagent.web.connector_checks.results import FailureClass
+from xagent.web.tools.mcp import mixpanel
+
+CHECK_ID = "mixpanel.query_engage"
+# The three Query API tools the Free plan was seen to refuse.
+REFUSED_ON_FREE = (
+ "mixpanel_list_event_names",
+ "mixpanel_get_top_events",
+ "mixpanel_list_funnels",
+)
+
+
+def _check() -> ReadCheck:
+ check = next(c for c in CONNECTOR_CHECKS["mixpanel"].reads if c.id == CHECK_ID)
+ assert isinstance(check, ReadCheck)
+ return check
+
+
+def _judge(output: str) -> tuple[FailureClass | None, str | None]:
+ check = _check()
+ raw = {
+ "content": [{"type": "text", "text": output}],
+ "structured_content": None,
+ "is_error": False,
+ }
+ return judge_result(raw, check.payload, check.assertions)
+
+
+def _engage(results: list[dict[str, Any]]) -> dict[str, Any]:
+ return {
+ "page": 0,
+ "page_size": 1000,
+ "results": results,
+ "session_id": "abc",
+ "status": "ok",
+ "total": len(results),
+ }
+
+
+def _run(monkeypatch: pytest.MonkeyPatch, answer: dict[str, Any]) -> tuple[str, list]:
+ calls: list[tuple[Any, ...]] = []
+
+ def request(method: str, host: str, path: str, **kwargs: Any) -> dict[str, Any]:
+ calls.append((method, host, path, kwargs.get("form_data")))
+ return answer
+
+ monkeypatch.setattr(mixpanel, "_request", request)
+ check = _check()
+ return getattr(mixpanel, check.tool)(**check.arguments), calls
+
+
+# --- what is declared ------------------------------------------------------------
+
+
+def test_mixpanel_declares_one_read_and_no_l3_probe() -> None:
+ checks = CONNECTOR_CHECKS["mixpanel"]
+
+ assert [c.id for c in checks.reads] == [CHECK_ID]
+ assert not checks.writes
+
+
+def test_mixpanel_has_left_the_legacy_list() -> None:
+ assert "mixpanel" not in LEGACY_CONNECTORS
+
+
+def test_the_tools_the_free_plan_refuses_say_so() -> None:
+ reasons = {e.tool: e.reason for e in CONNECTOR_CHECKS["mixpanel"].exemptions}
+
+ for tool in REFUSED_ON_FREE:
+ assert reasons[tool] == _MIXPANEL_QUERY_API_NEEDS_A_PAID_PLAN
+
+
+# --- what a check accepts ----------------------------------------------------------
+
+
+ "results", [[], [{"$distinct_id": "u1", "$properties": {"$name": "A"}}]]
+)
+def test_an_engage_output_satisfies_the_declaration(
+ monkeypatch: pytest.MonkeyPatch, results: list[dict[str, Any]]
+) -> None:
+ output, calls = _run(monkeypatch, _engage(results))
+
+ assert _judge(output) == (None, None)
+ assert [(m, p) for m, _, p, _ in calls] == [("POST", "/api/query/engage")]
+
+
+# --- what a check rejects ----------------------------------------------------------
+
+
+def test_a_check_fails_on_a_tool_error_envelope() -> None:
+ # The Free plan's refusal, a rejected credential or a missing project id: the
+ # tool reports it in its own envelope with the MCP error flag unset.
+ output = json.dumps(
+ {"status": "error", "message": "402 Your plan does not allow API calls"}
+ )
+
+ assert _judge(output) == (FailureClass.ASSERTION_FAILED, "status_success")
+
+
+def test_a_check_fails_when_the_profile_list_is_missing() -> None:
+ output = json.dumps({"status": "success", "truncated": False})
+
+ assert _judge(output) == (FailureClass.ASSERTION_FAILED, "has_keys")
+
+
+ "engage",
+ [
+ {"page": 0, "page_size": 1000, "results": "none", "total": 0},
+ {"page": 0, "page_size": 1000, "results": [], "total": "0"},
+ ],
+)
+def test_a_check_fails_on_another_shape(engage: dict[str, Any]) -> None:
+ output = json.dumps({"status": "success", "engage": engage, "truncated": False})
+
+ failure, _ = _judge(output)
+
+ assert failure is FailureClass.ASSERTION_FAILED
diff --git a/tests/web/connector_checks/test_registry.py b/tests/web/connector_checks/test_registry.py
index 68f502569..fab092ea0 100644
--- a/tests/web/connector_checks/test_registry.py
+++ b/tests/web/connector_checks/test_registry.py
@@ -320,6 +320,18 @@ def _xero_paged_pin(
# The Tier 2 read checks (issue #3573): the tool, its arguments, and every
# assertion, so dropping an item key or a whole assertion fails here.
_TIER_2_READS: Mapping[str, tuple[str, dict[str, Any], tuple[Assertion, ...]]] = {
+ "mixpanel.query_engage": (
+ "mixpanel_query_engage",
+ {},
+ (
+ StatusSuccess(),
+ HasKeys((), ("engage", "truncated")),
+ HasKeys(("engage",), ("page", "page_size", "results", "total")),
+ IsType(("engage", "results"), "array"),
+ IsType(("engage", "total"), "number"),
+ IsType(("truncated",), "boolean"),
+ ),
+ ),
"google-ads.list_accessible_customers": (
"google_ads_list_accessible_customers",
{},
diff --git a/tests/web/connector_checks/test_tool_coverage.py b/tests/web/connector_checks/test_tool_coverage.py
index 4ed99410b..a4062f634 100644
--- a/tests/web/connector_checks/test_tool_coverage.py
+++ b/tests/web/connector_checks/test_tool_coverage.py
@@ -45,7 +45,6 @@ _PINNED_LEGACY = frozenset(
"linkedin",
"magento",
"meta-ads",
- "mixpanel",
"myob",
"posthog",
"rocketlane",