Skip to content

feat: Let search-actors take a use case, except for Claude clients - #1715

Merged
MQ37 merged 2 commits into
masterfrom
feat/search-use-case-field
Oct 27, 2026
Merged

MQ37 merged 2 commits into
masterfrom
feat/search-use-case-field

Conversation

@MQ37

@MQ37 MQ37 commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Why

Part of apify/ai-team#272, follows #1650 (merged). The Store search takes _useCase (why the user is searching). #1650 sends it only for Apify AI through _meta. This makes it an optional search-actors argument that any client's model can fill, so no per-client code is needed. Anthropic clients are not offered it, pending the directory review.

What changed

  • search-actors and its widget take an optional useCase, for clients that declare a name outside ANTHROPIC_CLIENT_NAMES (also not on ?client=claude), with telemetry on. Field and tool description say: never send personal information or secrets, respect the user's privacy.
  • prepareToolCall strips useCase from these tools' arguments for every client before logging, validation and the call; only a client that was offered the field gets it sent as _useCase (tokens redacted, 1024 characters).
  • Removed: the _meta['com.apify/useCase'] path from feat: Send trace id and use case with Apify Store searches #1650.
  • Kept out of our logs and telemetry: dev server logs only the request method; an echoed use case in an API error is masked; Sentry drops the HTTP query string (stdio).
  • REPORT_PROBLEM_BLOCKED_CLIENTS is renamed ANTHROPIC_CLIENT_NAMES: it now gates two things.

Deliberate: Apify API access logs record the use case (it is in the URL).

Notes for reviewers (human-written)

TODO(author): where to look hardest, what you are unsure of, which AI-written parts you do not fully follow.

  • apify-ai-agent#267 sends the same _meta use case and clashes with this field; close it or reduce it to the thread id before release.
  • Limits: a stdio client that re-initializes under another name keeps its first tool list; the masking matches the verbatim text only; an old pod during a rollout ignores the argument but logs raw arguments at DEBUG and INFO.
  • Only apify_api_ tokens are filtered. A user who explicitly asks the model to put their name and email in the field gets it through (haiku 2 of 3 runs, sonnet 0 of 3).
  • No evals yet (the eval agents are Claude clients and never see the field). Metric to track: share of Store searches with a use case, and share of those with personal data.

Proof it works

  • Unit suite 3319 passed, 1 skipped; tsc, oxlint, oxfmt clean. 13 mutations of the gates, redactions and masking each fail a unit test.
  • Podman e2e, 115/115: real MCP clients (2025-11-25, 2026-07-28, stdio) against a fake Apify API, per client name, ?client=claude, telemetry off, widget mode: field listed or not, _useCase sent or not, no use case in captured logs or telemetry.
  • Real models (Claude Agent SDK, local fake API): Claude client 0 of 24 runs saw the field or sent _useCase; other client, ordinary tasks with a name, email, phone or token in the prompt: the model filled the field in 22 of 24 runs and no personal data reached the API (haiku 36 runs, sonnet 12).
  • Not run: the real Apify API or staging, and the ChatGPT directory review. The harnesses are not in this PR.

@MQ37
MQ37 force-pushed the feat/search-use-case-field branch from e68bf97 to 010486f Compare October 26, 2026 23:07
…pic clients

Optional useCase argument on search-actors and its widget twin, with a privacy warning in the description. Offered only to clients that declare a name outside the Claude/Anthropic blocklist, with telemetry on. The server takes it off the arguments before anything logs or validates them, drops it from any client that was not offered it, redacts API tokens, and sends it as the Store search _useCase. Removes the Apify-AI-only _meta path, logs only the method of a dev server request, masks an echoed use case in Store errors and drops the query from Sentry HTTP breadcrumbs.
@MQ37
MQ37 force-pushed the feat/search-use-case-field branch from 010486f to 5727602 Compare October 26, 2026 23:10
@MQ37
MQ37 marked this pull request as ready for review October 26, 2026 23:41
@apify-service-account apify-service-account added the tested Temporary label used only programatically for some analytics. label Oct 26, 2026
@apify-service-account apify-service-account added the t-ai Issues owned by the AI team. label Oct 26, 2026
@jirispilka jirispilka added the adhoc Ad-hoc unplanned task added during the sprint. label Oct 27, 2026
…e-field

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jirispilka

jirispilka commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-ups in #1720 (draft, targets this branch, four separate commits so any subset can be taken).

@jirispilka jirispilka left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It is ok.

First I addressed some minor comments in #1720

Then I looked closely and it seems there is a simpler design that was implemented by Claude, please take a look.

@MQ37
MQ37 added this pull request to stack #1724 October 27, 2026 17:15
@MQ37
MQ37 merged commit 464b957 into master Oct 27, 2026
19 checks passed
@MQ37
MQ37 deleted the feat/search-use-case-field branch October 27, 2026 17:16
MQ37 pushed a commit that referenced this pull request Oct 27, 2026
…#1720)

## Why
Follow-ups to the review on #1715. Draft on purpose: it is your PR, so
take the commits you want. Each stands alone and is green on its own.

## What changed
1. **`fix: Match every Claude Desktop local-agent-mode client name`** —
the blocklist had the literal `local-agent-mode-apify`, but Claude
Desktop names itself `local-agent-mode-<server name>`, so
`local-agent-mode-espn-sports`, `local-agent-mode-Apify MCP server`, …
(all in Mixpanel) counted as non-Anthropic and got `report-problem`. Now
a prefix, like the other two entries.
2. **`fix: Remove the Store error masking`** — tested on the live API:
it echoes `_useCase` only over 1024 characters, which `sanitizeUseCase`
never sends, and the mask matched the full string, so it missed the
truncated echo anyway. Details in the commit message.
3. **`docs: Say where the search use case goes`** — the README sentence
now names the destination (Store search analytics; the Mixpanel `Store
search` event carries `use_case`).
4. **`refactor: Put useCase in the search schema and withhold it per
client`** — the opinionated one, below.

### About commit 4
I did not like the engine block that recognises the search tools by
name, strips `useCase` from the arguments and parks it on
`storeSearchTracking`: the engine should not know search tools exist. My
first attempt kept your design and gave the variant its own validator,
so nothing needs stripping. That works and is a fine small change on its
own (about ten lines; the engine block goes, the rest stays).

Then I tried the inverse: `useCase` as an ordinary field of the base
schema, and for clients that are not offered it, serve a copy without
the field. It turned out smaller with fewer concepts, so that is what
the commit does. Honest comparison:

| | #1715 | commit 4 |
|---|---|---|
| Where the field is defined | a second schema built from the base, plus
a description patch (`addUseCaseToSearchTool`) | one optional field in
`searchActorsBaseArgsSchema`; the widget inherits it |
| Per-client difference | swap in a variant tool for allowed clients;
map in `server.ts` | strip the field for withheld clients;
`withoutUseCaseField` in `tools_loader` (12 lines, built once per tool,
own validator) |
| How the value reaches the API | engine strips the argument, side
channel on `storeSearchTracking` | the tool passes `parsed.useCase` to
`searchAgentSafeActors`, which sanitizes it |
| Claude sends it anyway | engine drops it | the served copy's validator
drops it |
| `?client=` | gates | name only, like `report-problem` (ai-team#214
decision 4) |
| Tool-level privacy note | yes | field description only |
| Engine | knows the search tools | untouched |

What goes: the tool-level note (you tested models with it present) and
the `?client=` belt-and-braces. What stays: every guarantee in your
gating tests, which still pass unchanged in meaning, plus "Claude sends
it anyway", now on the validator.

If you would rather keep your structure, say so and I turn commit 4 into
the smaller version (own validator on the variant, engine block
removed).

## Notes for reviewers (human-written)

## Proof it works
- Unit suite green at every commit (3321 at HEAD); `tsc`, `oxlint`,
`oxfmt`, `check:agents` clean.
- Live `GET /v2/store` probe for commit 2: an over-limit `_useCase` is
echoed in the 400; 1024 UTF-16 units of ASCII, `č`, `中` and `😀` are
accepted; the removed mask left the echoed text in the message.
- Integration cases (named client gets `useCase`, `claude-ai` does not)
not run here (need `APIFY_TOKEN`). Internal's contract suite likely
needs a matching case.
- End to end with mcpc 0.6.0 against `36d8a942` (stdio, real token,
`TELEMETRY_ENV=PROD`), every use case tagged `e2e1720-1206`:
- Schema: `useCase` present for mcpc's own (non-Anthropic) name with
telemetry on, in default and apps mode (`search-actors-widget` too);
absent with telemetry off, where `report-problem` is absent as well.
- Calls, all `isError: false`: plain use case; 1200-character use case
(the API 400s above 1024, so success proves the cap); use case
containing `apify_api_…`; empty and whitespace-only use case; empty
keywords; unknown extra argument; the widget tool; a use case sent to
the telemetry-off session.
- Store search analytics (Mixpanel `Store search`, `meta_origin: MCP`):
rows for the plain, capped, widget and apps-mode use cases, and the
token one arrived as `… apify_api_***`. No row for the telemetry-off
session's value, and none for the empty-keywords call (the API does not
track searches without a term). The rows' `trace_id` equals the
sessions' `MCP Tool Call` `trace_id`, so the join works.
- Our telemetry (`MCP Tool Call`, client `mcpc`): 17 `search-actors` + 1
`search-actors-widget` events today, every one with a `trace_id`; the
event has no property that could carry a use case. The telemetry-off
session produced no event.
- Not testable with mcpc: the per-client split (`claude-ai` withheld,
`Cursor` served); mcpc cannot set `clientInfo.name`. Covered by unit
tests and by the two integration cases in `registration.cases.ts`.
- Observed, pre-existing: AJV runs with `coerceTypes`, so `useCase: 123`
is sent as `"123"` and `null` becomes an empty string (dropped), instead
of a validation error.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

adhoc Ad-hoc unplanned task added during the sprint. t-ai Issues owned by the AI team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants