MCP Reverse Tunnels: Secure Read-Only Access to Local Notes for Mobile AI

    Connect a mobile or web AI assistant to local notes through MCP and a self-hosted reverse tunnel. This article explains the architecture, directory allowlisting, read-only tools, authentication, audit logging, and deployment checks that keep remote access narrowly scoped.

    1. The Problem: Compute in the Cloud, Knowledge at Home

    A common mismatch limits the usefulness of mobile AI assistants: they have plenty of cloud compute—and sometimes unused usage allowances—but no access to the information you actually care about. Hundreds of reading notes, meeting minutes, and project retrospectives remain on the disk of an always-on computer at home.

    These needs fall into two categories with very different requirements:

    • Read-only discussion and writing: Looking up notes, comparing ideas from two books, or turning scattered thoughts into an outline. The AI only needs visibility into the material; its output is text.
    • Read-write changes: Renaming files in bulk, reorganizing directories, or editing file contents. These tasks require precise execution and rollback capabilities, making them better suited to a coding agent running locally.

    Using available cloud capacity for the first category is a practical way to get more value from it. The technical problem is straightforward: how can a remote model access local files with explicit authorization?

    2. Design Goals: Read-Only, Allowlisted, and Auditable

    This approach deliberately avoids general-purpose filesystem access. Its scope is narrow:

    1. Read-only tools. The toolset exposes no write, delete, or move operations, preventing accidental changes through those tools.
    2. Directory allowlisting. Only directories explicitly authorized by the user are exposed. All other paths are out of scope.
    3. Local execution. Search and file reading happen on your own machine. The model receives matching text excerpts rather than an upload of the entire directory.
    4. Auditable access. Each tool call records the timestamp, caller identifier, tool name, parameter summary, and number of bytes returned.

    Together, these constraints make spare AI capacity useful while keeping data access bounded.

    3. MCP: A Standard Interface for AI Tools

    The Model Context Protocol, or MCP, is an open protocol for exposing tools to AI applications through a standardized interface. Think of it as a common socket standard: a compatible client can discover and call capabilities such as file reading and content search without requiring a separate proprietary integration for every client.

    A typical interaction looks like this:

    1. Mobile or web client
    2. → Lists available tools (capability discovery)
    3. → Model requests search_notes("attention structure")
    4. → Server searches locally within authorized directories
    5. → Returns matching excerpts, truncated and redacted
    6. → Model generates an answer based on those excerpts

    The important distinction is that the model receives excerpts, not unrestricted access to the filesystem.

    4. Architecture: A Public Endpoint and a Reverse Tunnel

    The networking challenge is asymmetric: the model runs in a remote cloud environment, while the files live behind a home router.

    There are three possible approaches:

    Approach How it works Trade-off
    Router port forwarding Exposes the home IP address directly to public requests Opens inbound ports and increases exposure to scanning and brute-force attempts
    Third-party tunneling service Relies on an external platform for connectivity Adds third-party trust and availability dependencies
    Reverse tunnel with a self-hosted endpoint The home machine initiates an outbound connection; the public endpoint forwards requests Requires no inbound ports on the home router and keeps the connection infrastructure under your control

    The third approach is the recommended option. Its data path is:

    1. Mobile or web client ──HTTPS──> Public endpoint
    2. (small cloud VM, fixed address, always on)
    3. ▲
    4. │ Reverse tunnel
    5. │ Persistent connection initiated
    6. │ by the home machine
    7. │
    8. Always-on home computer
    9. MCP service listening only on 127.0.0.1

    A reverse tunnel reverses the connection direction. Instead of an external client opening a connection into the home network, the home computer establishes a persistent outbound connection to the public endpoint. Requests then travel back through that existing connection.

    The home router needs no open inbound ports. Both the tunnel’s forwarding port on the public endpoint and the MCP service port on the home machine listen only on loopback addresses.

    The following is illustrative configuration, not a command for a specific tunneling product:

    1. # Public endpoint: expose only one TLS port; close all other public ports
    2. listen = <public-endpoint-address>:443
    3. forward = 127.0.0.1:18080 # Tunnel termination port
    4. # Home machine: initiate an outbound reverse tunnel
    5. tunnel --server <public-endpoint-address> \
    6. --remote 18080 --local 8765 \
    7. --token <pre-shared-secret>

    5. Server Implementation: Core Building Blocks

    A minimal read-only service can be implemented in a scripting language. Three core responsibilities are tool discovery, path validation, and result truncation.

    This illustrative Python code shows those building blocks:

    1. import os
    2. ALLOWED_ROOT = os.path.realpath("/data/notes") # Only authorized directory
    3. MAX_BYTES = 200_000 # Intended per-response limit
    4. def describe_tools():
    5. return [
    6. {"name": "list_notes", "desc": "List notes in the authorized directory"},
    7. {"name": "read_note", "desc": "Read a note using a relative path"},
    8. {"name": "search_notes", "desc": "Search keywords in the authorized directory"},
    9. ]
    10. def _resolve(rel_path: str) -> str:
    11. full = os.path.realpath(os.path.join(ALLOWED_ROOT, rel_path))
    12. # Prevent directory escape: the resolved path must remain inside the root
    13. if not full.startswith(ALLOWED_ROOT + os.sep):
    14. raise PermissionError("path out of scope")
    15. return full
    16. def read_note(rel_path: str) -> str:
    17. with open(_resolve(rel_path), "r", encoding="utf-8") as f:
    18. return f.read(MAX_BYTES) # Truncate reads to limit context consumption

    Three details deserve particular attention:

    • Resolve the real path before checking it. A prefix check on the unresolved path can be bypassed using ../ or symbolic links.
    • Truncate responses. Context space is limited. Returning an entire book can crowd out the conversation. In this example, text-mode read() limits characters rather than encoded bytes, despite the constant’s name.
    • Authenticate requests at the public endpoint. Keep request authentication separate from the tunnel token so that a leaked tunnel credential does not automatically grant access to the notes.

    6. If You Do Not Write Code: Divide the Work Between Agents

    This project does not necessarily require writing every component yourself. One practical workflow is to use multiple coding agents with distinct responsibilities: one clarifies your intent in natural language and translates it into technical requirements, while another produces the code and runs tests. The coordinating layer explains implementation details in plain language.

    The key practices are:

    • Describe requirements in terms of user needs, but express acceptance criteria as executable checks—for example, “out-of-scope paths must return an error.”
    • Ask the implementation agent to write tests before implementation so that security constraints have regression coverage.
    • Advance one module at a time to avoid mixing unrelated context.

    With this division of work, a functional prototype that includes tunneling and authentication may be achievable in one to two days.

    7. Pre-Deployment Checklist

    Before making the service available, verify the following:

    • Authorization scope: Are the allowed directories the smallest necessary set? Do they accidentally contain keys or credential files?
    • Network exposure: Are home-network inbound ports closed? Do the MCP service and tunnel forwarding port listen only on loopback addresses?
    • Connection resilience and limits: Does the tunnel reconnect automatically? Does the public endpoint enforce request-body size and rate limits?
    • Logging: Are sensitive details redacted, and are tool-call audit records retained?
    • Dependencies: Are dependency versions pinned to reduce behavior changes caused by upstream updates?

    8. Boundaries and Other Uses

    This architecture is not tied to a particular model. Replacing the server-side toolset makes the same pattern useful for other tasks: querying logs for incident reviews, searching reference material in object storage, or answering on-call questions from monitoring and alert data.

    Tasks that are predominantly read-oriented and deliver conclusions as text are a good fit for this setup. They turn unused AI capacity into practical output. Work that modifies files should remain with an execution-oriented agent running locally.

    The core principle is simple: use MCP to standardize capabilities, a reverse tunnel to provide connectivity, and read-only tools with directory allowlists to enforce boundaries. Together, they make local knowledge available in a mobile AI conversation without exposing the entire filesystem.