Skip to content

Add desktop MCP endpoint for AI assistants with configurable port - #82

Open
j1philli wants to merge 3 commits into
mainfrom
t3code/add-desktop-mcp-endpoints
Open

j1philli wants to merge 3 commits into
mainfrom
t3code/add-desktop-mcp-endpoints

Conversation

@j1philli

Copy link
Copy Markdown
Owner

Summary

Adds an opt-in Assistant access (MCP) endpoint to the desktop app, so AI assistants on the same computer (Claude Code, Cursor, …) can read and update the budget.

  • Rust (src-tauri/src/mcp.rs): Streamable HTTP on 127.0.0.1:<port>/mcp, POST only. It requires a bearer token (constant-time compare), allows only loopback Host headers (DNS-rebinding defence), and rejects cross-site Origins. It forwards each JSON-RPC body to the web app via mcp-request / mcp_respond, with a 60s timeout and 4 MB body limit.
  • Kotlin (app/shared/.../mcp/): McpServer handles the protocol (initialize, tools/list, tools/call). McpToolbox has 18 tools: 7 reads, plus writes that go through the same repositories and use cases as the UI, so they're Store5 writes that sync like any other edit. There is deliberately no account or category deletion. McpAccess stores the toggle, port and token.
  • Settings UI: a toggle, status line, Port field, claude mcp add … command, JSON config, and token copy and regenerate (with confirmation).
  • recordAdHoc / recordAdHocTransfer now return the new posting id.

Configurable port

  • Range 1024–65535, default 47615. It's saved in Settings, and a saved value outside the range falls back to the default.
  • Changing the port while access is on restarts the endpoint on the new port. Rust stops the old server, then binds the new one, retrying for 1s so a same-port restart can reuse it.
  • A busy port shows "Port N is already in use by another app". Saving the same port again retries it; the Save button is enabled in that error state.
  • Start, stop and port/token changes are serialized with a Mutex, so a slow start can't finish after a later stop.

Fixes from merging main

  • Finance spaces (Add isolated finance spaces, memberships, and linked transfers #38): repositories are now per-space factory bindings. McpToolbox is resolved per request, so assistant tools follow the active space instead of staying on the space that was active at launch. A test covers this.
  • Test fakes updated for ReceiptFileStore.openReader and ReceiptFileStoreFactory.

Test results

  • mise run test: architecture guard passed; 246 JVM tests, 0 failures. This includes 16 MCP tests: protocol, tools including writes, space switching, and port default/persist/restart/retry/busy/range/ordering.
  • cargo test (src-tauri): 4/4, including a real-socket test that a held port reports "already in use" and binds once freed.
  • ./kotlin build: every module compiles for wasmJs, Android, iosArm64, iosSimulatorArm64, JVM and server. The only failure is perf-ios's Xcode app-bundling step: WebRTC.xcframework isn't present in app/perf-ios/Frameworks (gitignored; setup-webrtc.sh only fetches it for ios-app). That's an environment issue that comes from main, not this change.

Consent / permission screens

  • No new OS permission prompts or consent screens. Binding 127.0.0.1 on an unprivileged port needs no entitlement. The feature is off by default and only runs after the user turns it on in Settings.
  • New user-facing path: Settings → Assistant access (toggle, port, token). It can read and write budget data for any local process that has the token.

Not tested end to end

  • The port field in the running desktop app. In an earlier session, before this merge, the toggle was verified live with curl: 401 without the token, 403 for a cross-site Origin, 405 for GET, and initialize, tools/list and read tools returning data. Turning it off closed the port. The port change and rebind in the real app has not been verified live. On 2026-11-17 the app rendered, but the tauri-mcp bridge timed out on JS and IPC and native clicks had no effect, so the UI couldn't be driven.
  • Write tools against a live app: covered by JVM tests only. They weren't run on the dev DB because it syncs to real devices.
  • MCP on the merged main (hybrid logical clock Reconcile offline edits with a hybrid logical clock #81, spaces Add isolated finance spaces, memberships, and linked transfers #38): covered by JVM tests only, not run live.

🤖 Generated with Claude Code

j1philli and others added 3 commits November 17, 2026 09:13
Opt-in Settings toggle starts a loopback Streamable HTTP server
(127.0.0.1:<port>/mcp, bearer token, Host/Origin checks) in the Tauri
shell that forwards JSON-RPC to the web app's McpServer. McpToolbox
exposes budget read tools and Store5-backed write tools.

The port is configurable in Settings (1024-65535, default 47615),
persisted, and rebinds the endpoint when changed while on. Start/stop
calls are serialized, and saving the same port retries a port that was
busy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolve conflicts with finance spaces, analytics settings and the new
web schema bootstrap. MCP tools now resolve McpToolbox per request so
they follow the active finance space instead of the one active at
launch; the test platform module provides ReceiptFileStoreFactory.

Co-Authored-By: Claude Opus 5.5 <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