Skip to content

refactor(web): migrate self builtin-tool calls to the typed studio-tools client#3933

Open
viktormarinho wants to merge 1 commit into
mainfrom
viktormarinho/typed-studio-tools-fanout
Open

refactor(web): migrate self builtin-tool calls to the typed studio-tools client#3933
viktormarinho wants to merge 1 commit into
mainfrom
viktormarinho/typed-studio-tools-fanout

Conversation

@viktormarinho

@viktormarinho viktormarinho commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #3932 (the RestSelfClient backbone). Migrates 34 web hooks/components from the in-browser MCP self-client to the typed studio-tools client:

- const client = useMCPClient({ connectionId: SELF_MCP_ALIAS_ID, orgId, orgSlug });
- const r = (await client.callTool({ name: "TAGS_LIST", arguments: {} })) as { structuredContent?: ... };
- return (r.structuredContent ?? r).tags;
+ const studio = useStudioTools();
+ const { tags } = await studio.call("TAGS_LIST", {});
+ return tags;

Behavior-preserving — same tool names, arguments, React Query keys, optimistic updates and error handling; only the transport-call shape + the now-redundant structuredContent/isError envelope unwrap change. Net −674 lines. Self traffic already ran over REST via the backbone; this adds compile-time type-safety (tool name + input/output inferred from CORE_TOOLS via ToolIO).

How it was done

A per-file migration (one agent per candidate, each only touching confirmed self calls) + a 4-dimension adversarial review of the diff. Then centrally verified.

Intentionally left for a follow-up (still on RestSelfClient, working over REST)

  • Generic collection consumers whose React Query key is the client instance (KEYS.collectionList(client, …)) — can't key on a typed call: github-repo-picker, import-from-deco-dialog, tool-set-selector, add-connection-dialog, use-ai-providers.
  • Looser-than-UI output schemas — files where the tool's output schema is less precise than the UI's local types (so a clean typed migration needs the schemas tightened first, not suppression casts): use-automations (+ automation-detail), use-monitor, ai-providers connect dialogs, org-brand-context, sandbox-lifecycle.

Testing

  • bun run check (all workspaces), knip, lint, Biome format — all green.
  • Adversarial review (connection-call leakage, React Query semantics, leftover envelope unwrap, plugin-tool/import misuse) — clean after fixing one leftover unwrap (use-group-show-more).
  • Runtime parity is already covered by the merged tools-rest.spec.ts e2e; these call sites are behavior-preserving swaps over the same endpoint.

🤖 Generated with Claude Code


Summary by cubic

Migrates self builtin-tool calls in the web app to the typed studio-tools client over REST, replacing useMCPClient calls with useStudioTools().call(...). Behavior is unchanged; adds compile-time typing and removes ~674 LOC.

  • Refactors
    • Updated 34 components/hooks (chat, settings, registry, monitoring, virtual MCP) to use useStudioTools().call(name, input).
    • Removed structuredContent/isError envelopes; standardized thrown-error handling while preserving tool names, args, React Query keys, and optimistic updates.
    • Builds on the RestSelfClient backbone with I/O types inferred from CORE_TOOLS via ToolIO. Follow-ups remain on RestSelfClient for client-keyed collection consumers and files with looser tool output schemas (e.g., use-automations, use-monitor, ai-provider connect dialogs, org-brand-context, sandbox-lifecycle).

Written for commit f1644bb. Summary will update on new commits.

Review in cubic

…ols client

Convert 34 web hooks/components from the in-browser MCP self-client
(client.callTool({name, arguments}) + manual envelope unwrap) to the typed
studio.call(name, input) over REST. Behavior-preserving: same tool names,
arguments, React Query keys, optimistic updates and error handling — only the
transport call shape + the now-redundant structuredContent/isError unwrap
change. Net -674 lines.

Builds on the RestSelfClient backbone (#3932): self traffic already runs over
REST, so this adds compile-time type-safety (tool name + input/output inferred
from CORE_TOOLS schemas via ToolIO).

Left on RestSelfClient as a follow-up:
- generic mesh-sdk collection consumers whose React Query key is the client
  instance (5 files skipped: github-repo-picker, import-from-deco-dialog,
  tool-set-selector, add-connection-dialog, use-ai-providers).
- files whose tool output schema is looser than the UI's local types
  (use-automations + automation-detail, use-monitor, ai-providers connect
  dialogs, org-brand-context, sandbox-lifecycle) — need the tool output schemas
  tightened before a clean typed migration.

Verified: bun run check (all workspaces), knip, lint, biome format. Adversarial
review of the diff (4 dimensions) clean after fixing one leftover unwrap.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant