How to Let Mobile LLMs Read Your Local Knowledge Base
This article explains a practical architecture for connecting a remote large language model running in a mobile app to text files stored on your own machine. It covers treating tool-calling protocols as a standard interface, a three-part setup of phone, cloud relay, and home host, using a reverse tunnel instead of port forwarding, and security practices such as directory allowlists, path traversal protection, type and size limits, auditing, and on-demand access. It also outlines an implementation path, common pitfalls, observability and operations, and which tasks fit this read-only design versus a local coding agent.
1. The Problem: Powerful Models Cannot See Your Files
Many people have the same experience: a large model’s official app sits on their phone, ready to chat at any time, with more than enough usage quota. But when they actually want help reading notes, book excerpts, or meeting records accumulated over years, they find they have to copy and paste manually, feeding the model one segment at a time. The data is local, the model is remote, and what is missing in between is not intelligence but a controlled data channel.
An always-on device at home (for example, a low-power host), a small cloud server with a fixed address, and the official app on your phone already form a usable three-part structure. The only missing piece is the layer that reliably and securely connects the three. This article discusses a general approach: using a standardized tool-calling protocol to let a remote model read text content from a specified local directory under explicit authorization.
First, it helps to draw the capability boundary. This kind of setup is suited to “reading” and “chatting”: browsing notes, organizing structure, summarizing key points, and generating text. Tasks that genuinely involve “hands-on” work—batch rewriting files, running builds, operating version repositories—are better handed to a coding agent running locally, because it naturally has a low-latency file system and command execution environment. Separating reading from writing is the premise for this design to run stably over the long term.
2. The Core Abstraction: Treat the Tool-Calling Protocol as a Socket Standard
To let a model use external capabilities, the common industry practice is to introduce a standardized tool integration protocol. You can think of it as a socket standard for the AI world: the plug (model side) and the socket (tool side) follow the same specification, so any compliant “appliance” can be plugged in and used immediately.
This abstraction brings three direct benefits.
- Decoupling: the model does not need to know which directory a file is in or how to access it; it only sees a tool named “read file” or “search content.”
- Replaceability: today it connects to a local notes directory; tomorrow it can be swapped for a log directory or a document repository, with the conversation on the model side unchanged.
- Auditability: all tool calls pass through your server, which is a natural place to log and intercept them.
A minimal tool declaration looks roughly like this (illustrative, not a specific product interface):
{"tools": [{"name": "read_note","description": "Read a single text file under the authorized directory","input_schema": {"type": "object","properties": {"path": { "type": "string", "description": "Path relative to the authorized root directory" }},"required": ["path"]}},{"name": "search_notes","description": "Search for keywords within the authorized directory and return snippets","input_schema": {"type": "object","properties": {"query": { "type": "string" },"limit": { "type": "integer", "default": 5 }},"required": ["query"]}}]}
The key point: the model returns a “tool call intent,” and the actual execution happens on your own machine. What the model sees is the result text, not your hard drive.
3. Overall Architecture: Phone, Gatekeeper, and Local Host
The whole chain can be split into three parts with clear responsibilities.
- Client (phone or web app): the user mentions a configured tool endpoint with @ in the chat input box, selects it, and starts a call. This consumes ordinary conversation quota and requires no integrated development environment.
- Relay layer (small cloud server, the “gatekeeper”): it has a fixed public address and stays online long term, doing only one thing—receiving encrypted requests from the public internet and forwarding them to the local service.
- Local service (home host): it runs the tool service process, listens on the machine’s loopback address, and handles authentication, path validation, reading and searching, returning results per the protocol.
The data flow can be summarized as:
Phone/Web --HTTPS--> Cloud relay <--reverse tunnel-- Local tool service --> Authorized directory
The point most easily misunderstood here: you are not uploading the folder to the cloud. What gets uploaded is a single request and its corresponding text result; the files themselves always stay on the local disk.
4. Reaching the Public Internet: A Reverse Tunnel, Not Port Forwarding
For a remote model to access local files, the first practical obstacle is network reachability. Home broadband usually has no stable public address, and the router sits behind multiple layers of address translation. The traditional approach is port forwarding, but that means opening inbound ports to the outside, with a large exposure surface and high risk.
A more robust option is a reverse tunnel: the local host initiates a persistent connection to the cloud relay, and requests “flow back” along this established connection to the local side. Its security benefits are clear.
- The home router needs no inbound ports open.
- Both the local service and the relay’s forwarding port listen only on loopback, unreachable directly from outside.
- The connection direction is inside-out, naturally suited to dynamic addresses and carrier restrictions.
Once the tunnel is up, you still need an access control layer; otherwise the “gatekeeper” becomes a door anyone can knock on. A common combination: the relay exposes only one entry with a strong password or token check, with the token passed in a request header; the local service validates again, forming double confirmation; and rate limiting is applied by source to avoid scanning and brute-force attempts.
5. Security Design: Least Privilege Is the Baseline
Letting a model read local files essentially opens a data outlet between you and the remote side, so permission design cannot be skipped.
- Directory allowlist: expose only one dedicated authorized root directory and reject all other paths.
- Path traversal protection: normalize incoming paths and reject access containing relative backtracking or symlink escapes.
import osROOT = os.path.realpath(os.path.expanduser("~/notes_authorized"))def safe_path(rel: str) -> str:target = os.path.realpath(os.path.join(ROOT, rel))if not (target == ROOT or target.startswith(ROOT + os.sep)):raise PermissionError("path escapes authorized root")if not os.path.isfile(target):raise FileNotFoundError(rel)return target
- Type and size limits: allow only plain-text formats, with caps on both per-file and per-response size, to avoid reading out large binaries or key files.
- Sensitive information isolation: do not include directories holding credentials or keys in the authorized scope; redact with regular expressions before returning when necessary.
- Full auditability: log call time, source identifier, requested path, and returned byte count so abnormal calls are traceable.
- On demand: shut down the local service or disconnect the tunnel when not needed, keeping the exposure window as short as possible.
6. Implementation Path: You Can Do It Without Writing Code
The barrier to implementing this is lower than you might think. A class of aggregated intelligent coding tools has already appeared that can orchestrate multiple underlying coding agents to work together in the same session: one understands requirements in natural language and breaks down tasks, another produces the actual code, and the former relays the results back. For people unfamiliar with code details, this “translation layer” structure significantly lowers communication cost.
A practical order of work:
- Define the protocol and tool list: first specify which tools exist and what their inputs and outputs are; this step determines all subsequent implementation.
- Establish the tunnel: first verify the local service can be reached stably by the relay, then add authentication.
- Implement authentication and path validation: write security checks as an independent module for easy standalone testing.
- Connect the client: add the endpoint in an official app that supports tool calls, invoke it with @, and try a read.
- Add logging and rate limiting: complete observability before going live to avoid being stuck when problems arise.
Three pitfalls are easiest to hit in self-development: no automatic reconnection after the tunnel drops; path validation done only with string prefix comparison and thus bypassed; and responses too large, causing the conversation to fail outright. These are solved respectively by a daemon for reconnection, comparison after normalization, and pagination with truncation.
7. Observability and Day-to-Day Operations
For a long-running service, the main operational cost comes from “not knowing whether it is working right now.” It is recommended to cover at least three kinds of signals: tunnel connectivity (heartbeat and disconnect count), call metrics (count, failure rate, average response size), and security events (authentication failures, unauthorized path attempts). Logs should record only metadata, not file contents, so the logs themselves do not become a new leak point.
For deployment, run the local service under a process manager with auto-restart configured; keep the relay minimal, running only forwarding and validation components; and use a controlled key rotation mechanism on both sides, replacing tokens periodically.
8. Suitable and Unsuitable Scenarios
Tasks suited to this chain: browsing and summarizing a few notes, conversing with your accumulated material on a topic, having the model turn scattered ideas into an outline, and suggesting changes to an existing document’s structure. The common trait is “read-only input, text output.”
Not suitable: batch renaming and rewriting, builds and tests that depend on local dependency environments, and tasks requiring long interactive execution. Hand these to a local agent, which has lower latency and simpler failure recovery.
9. Conclusion
Connecting a remote model’s conversational ability to local knowledge assets is valuable not for showing off but for turning otherwise idle quota into a stable personal knowledge assistant. In terms of technology choices, only two points truly matter: use a standard protocol for replaceability, and use a reverse tunnel plus least privilege for security. Hold those two lines, and the remaining implementation details can be iterated gradually. To further reduce self-hosting costs, you can also build the relay and operations parts on general capabilities such as object storage, container platforms, and monitoring and alerting from Baidu AI Cloud, making the whole setup more manageable.
