Skip to content

✨ feat(gateway): add explicit type discriminator to tunneled tool calls#15473

Merged
arvinxx merged 2 commits into
canaryfrom
feat/gateway-tunnel-type-discriminator
Jun 4, 2026
Merged

✨ feat(gateway): add explicit type discriminator to tunneled tool calls#15473
arvinxx merged 2 commits into
canaryfrom
feat/gateway-tunnel-type-discriminator

Conversation

@arvinxx

@arvinxx arvinxx commented Jun 4, 2026

Copy link
Copy Markdown
Member

πŸ’» Change Type

  • ✨ feat

πŸ”— Related Issue

Follow-up to #15469 (stdio MCP tunnel). Hardens the device routing before the desktop receiver (#15470) lands.

πŸ”€ Description of Change

The device-gateway relays both builtin local-system calls and tunneled stdio MCP calls over one tool-call channel. The device was meant to distinguish them by sniffing whether toolCall.params exists β€” fragile: any future builtin tool that grows a params field would be misrouted to the MCP client.

This adds an explicit toolCall.type discriminator ('builtin' | 'mcp'):

  • GatewayHttpClient.executeToolCall stamps type: 'builtin'; executeMcpCall stamps type: 'mcp'.
  • The device routes on type, never on payload shape.
  • Optional + back-compatible: an older server that omits type is treated as 'builtin'.

params remains the MCP payload, but is no longer the routing signal.

πŸ§ͺ How to Test

  • Added/updated tests

bun run type-check clean; device-gateway-client 25 tests pass (asserts toolCall.type === 'mcp' for MCP calls and 'builtin' for builtin calls).

πŸ“ Additional Information

Layering: this is the shared-package/server-contract change and should merge & deploy first. The desktop receiver (#15470) is rebased on top of this branch and switches its routing from toolCall.params presence to toolCall.type === 'mcp'.

πŸ€– Generated with Claude Code

@vercel

vercel Bot commented Jun 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lobehub Ready Ready Preview, Comment Jun 4, 2026 1:05pm

Request Review

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. feature:mcp MCP relative issue feature:tool Tool calling and function execution labels Jun 4, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We've reviewed this pull request using the Sourcery rules engine

The device-gateway relays builtin local-system calls and tunneled stdio MCP
calls over one `tool-call` channel. The device was meant to tell them apart by
sniffing whether `toolCall.params` exists β€” fragile: any future builtin tool
that grows a `params` field would be misrouted to the MCP client.

Add an explicit `toolCall.type` discriminator (`'builtin' | 'mcp'`). The HTTP
client stamps it: `executeToolCall` β†’ `'builtin'`, `executeMcpCall` β†’ `'mcp'`.
The device routes on `type`, never on payload shape. Optional + back-compatible:
an older server that omits it is treated as `'builtin'`.

The desktop receiver switches to this discriminator in a follow-up.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…15470)

Receiving half of the gateway stdio-MCP work. When the cloud server tunnels a
stdio MCP tool call to this device (a `tool_call_request` carrying
`mcpParams`), run it locally instead of falling through to the builtin
local-system tool switch (which keys on apiName and has no MCP context, so it
rejected these as "not available on this device").

- `gatewayConnectionSrv`: add a dedicated `mcpCallHandler` + `setMcpCallHandler`;
  `handleToolCallRequest` routes on the presence of `toolCall.mcpParams`,
  sharing the existing response-envelope path.
- `GatewayConnectionCtr`: wire `setMcpCallHandler` β†’ `executeMcpCall`, which
  maps the wire payload to `McpCtr.runStdioMcpTool`.
- `McpCtr`: extract `runStdioMcpTool` core from the `callTool` IPC method so
  both the renderer and the gateway tunnel share one stdio execution path
  (no SuperJSON round-trip for the in-process caller).

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 4, 2026
@arvinxx arvinxx merged commit 2bb39f4 into canary Jun 4, 2026
44 of 45 checks passed
@arvinxx arvinxx deleted the feat/gateway-tunnel-type-discriminator branch June 4, 2026 13:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature:mcp MCP relative issue feature:tool Tool calling and function execution size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant