DEV Community

Cover image for Desktop AI access to Shelly: MCP approval and queue isolation
RYO ITABASHI
RYO ITABASHI

Posted on

Desktop AI access to Shelly: MCP approval and queue isolation

How can desktop AI reach Shelly’s phone-side tools while keeping authentication and approval boundaries? Shelly’s 2026-09 (v8.0.1)–10 (v8.0.2) work combined a Bearer-token-authenticated local MCP server with read-only tools, approval-required exec/write tools, and a request-serialization fix. What could incoming calls access, why did approval delay unrelated requests, and what did the MCP 2026-07-28 stateless flow change?

Where desktop access met the approval boundary

On 2026-09-16, commit e578d7f77 added an opt-in MCP server through settings.mcpServerEnabled, off by default, for Claude Code / Claude Desktop clients on the same network. The first pass exposed 4 read-only tools. Terminal output, git status, registered agents, and configured repos became accessible directly for development/debugging instead of through adb/uiautomator.

The existing capability broker gated OUTGOING requests, while exposing exec/write tools required an ingress-side capability gate. On 2026-09-17, commit d0590ece6 added that incoming-call gate through an in-app approval modal. Its run_command and write_file tools sat behind mcpExecEnabled, which was off by default and had no effect unless MCP Server was also on.

Every exec/write call waited on components/McpApprovalModal.tsx. The design combined that approval wait with command classification and write-path restrictions.

Why one approval delayed unrelated requests

E2E with real Claude Code / Codex clients found bugs such as 1 pending approval blocking the entire queue. The on-device failure was found on 2026-09-17 and addressed in commit e2a8b39b6.

A touch appeared to “unstick” several queued answers at once, initially making the symptom look like Android JS-timer throttling. The recorded cause was request serialization.

Failure-chain stage Before the fix After the fix
Request dispatch drainOnce() awaited callTool() sequentially inside a for-loop over request files. Each request file was fired off without being awaited inside the loop.
Approval and later reads A run_command/write_file approval wait blocked the entire poll tick, including later list_repos and git_status calls that should have answered in milliseconds. Dispatched requests were tracked by name in a small in-flight set.

MCP generally offers no guarantees about concurrency semantics, including when a peer observes a notification relative to another request. The Go SDK handles calls such as tools/call asynchronously with respect to each other. [1]

Shelly’s recorded change concerned its request-file polling implementation. The asynchronous-call behavior described by the official API documentation belongs to the Go SDK. [1]

Authentication at the HTTP boundary

For HTTP-based MCP authorization, the specification defines transport-level access to restricted servers on behalf of resource owners. Authorization is OPTIONAL for MCP implementations; when supported, HTTP-based implementations SHOULD conform to that authorization specification. [2]

A protected MCP server acts as an OAuth 2.1 resource server, while an MCP client acts as an OAuth 2.1 client making protected requests on behalf of a resource owner. The authorization server handles user interaction when necessary and issues access tokens for use at the MCP server. [2]

In the Go SDK, RequireBearerToken wraps an HTTP handler such as NewStreamableHTTPHandler and checks every request for an Authorization header containing a bearer token. A supplied TokenVerifier parses and validates the token, while the middleware checks expiration and configured scopes. Accepting only tokens issued for the server remains the responsibility of that TokenVerifier. [1]

The application must wrap RequireBearerToken around all HTTP handlers needing its inbound-request verification. When RequireBearerTokenOptions.ResourceMetadataURL is set and verification fails, the middleware sets the WWW-Authenticate header as required by the Protected Resource Metadata specification. [1]

For scope selection, clients MUST treat the scopes in a WWW-Authenticate challenge as authoritative for the current operation. During initial authorization, clients SHOULD use that challenge’s scope parameter when provided, with additional permissions requested incrementally through step-up authorization. [2]

What the stateless flow changed

Shelly’s 2026-09 (v8.0.1)–10 (v8.0.2) work included support for the MCP spec 2026-07-28 stateless flow. That protocol revision introduced self-describing requests and optional discovery, allowing requests to reach different server instances. [3]

The initialize / initialized exchange and Mcp-Session-Id header were retired in that revision. [3] For 2026-07-28 or later, the Go SDK requires io.modelcontextprotocol/protocolVersion and io.modelcontextprotocol/clientCapabilities in each request’s _meta; io.modelcontextprotocol/clientInfo is optional, although clients SHOULD include their identity on every request. [1]

The server processes the first stateless request when it arrives and validates the per-request metadata. [1] A client wanting capabilities before another operation can use server/discover, although that discovery call is optional. [3] Servers implementing 2026-07-28 MUST implement server/discover. [1]

For routing and authorization at gateways, Mcp-Method and Mcp-Name carry the method and tool names in HTTP headers. [3] The Go SDK also mirrors the body’s protocol version through Mcp-Protocol-Version. [1]

Application state can still travel across calls through an explicit handle returned by a tool and passed back as an argument. [3] Under 2026-07-28, a broken response stream loses the in-flight request, and the client must re-issue it with a new ID. The Go SDK retains EventStore and Last-Event-ID paths for backward compatibility with 2025-11-25 and earlier. [1]

Other approaches to confirmation and credentials

For a tool needing confirmation or a missing parameter mid-call, Multi Round-Trip Requests return resultType: "input_required", followed by a client retry with answers attached in inputResponses. MRTR replaces server-initiated elicitation/create, sampling/createMessage, and roots/list requests that previously required a held-open stream. [3]

STDIO implementations SHOULD retrieve credentials from the environment rather than follow the HTTP authorization specification. That credential path applies to STDIO, whereas the authorization flow described above applies to HTTP-based transports. [2]

Checklist for access, approval, and request failures

  • If read calls pause behind an approval, inspect the request dispatcher’s await placement: the Shelly failure chain above occurred in drainOnce() while an exec/write call waited for a decision.

  • If an approval remains unanswered, check whether Shelly is foregrounded and whether the deadline has elapsed: the modal was shown while Shelly was foregrounded, and the design failed closed through automatic denial after a 90s timeout.

  • If an approved command is refused, check its classification in lib/command-safety.ts: run_command hard-refused commands classified CRITICAL regardless of approval.

  • If a file write is refused, check its target against the configured path boundary: write_file was scoped to the home dir or a Sidebar-configured repo path, matching git_status’s existing scoping.

  • If HTTP authentication fails, inspect every request for Authorization: Bearer <access-token>: authorization MUST accompany every HTTP request, and access tokens MUST NOT appear in URI query strings. [2]

  • If a Go SDK streamable HTTP handler rejects a 2026-07-28 request, check StreamableHTTPOptions.Stateless: that version requires Stateless = true, and requests against a non-stateless handler are rejected. [1]

  • If a request produces CodeHeaderMismatch (-32020), compare Mcp-Method, Mcp-Name, and Mcp-Protocol-Version with the JSON-RPC body: mismatches between those mirrored headers and body fields produce that error. [1]

  • If a Go SDK server needs to make a client request in stateless mode, check the temporary-session constraint: the server cannot make client requests because the client’s response has no way to reach that session. [1]

Sources


AI disclosure: this post was researched, written and reviewed by AI tools.
Publishing: a post that passes automated checks may be published automatically, before the author reads it.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The drainOnce() bug is the part that stuck with me — one pending exec/write approval silently stalling unrelated read-only calls like git_status and list_repos is exactly the kind of failure that looks like a UI freeze on the phone. Firing each request file without awaiting it and tracking in-flight requests by name is a neat fix. I also liked that the fail-closed design (90s timeout, auto-denial) pairs with the MCP server being off by default behind settings.mcpServerEnabled. When the approval modal is waiting and Shelly is in the background, does the request stay queued until you foreground it, or does the 90s clock keep running from the moment the desktop client sent the call?