Connect a Termux MCP Server to Gemini on Android
Gemini can call a custom app if you give it the HTTPS URL of a Model Context Protocol server. Google will not fetch something that only lives on your tablet, so this guide runs a read-only notes server in Termux and publishes it through a temporary Cloudflare Quick Tunnel — with the limits and warnings that official docs actually state.
What You Need
- Google’s custom Connected Apps help is strict about this feature. You must be 18 or over and in the US, signed in to Gemini with a personal Google Account (not work or school), and have Keep Activity on. Custom apps are English-only for now, and you add them in the Gemini web app at gemini.google.com. After that, you can use them in the Gemini mobile app too.
- Termux installed from F-Droid, not Play Store. See Install Termux on Android the Right Way and Install Packages in Termux.
- Wi‑Fi you trust. A tunnel makes a local port reachable from the public internet.
- Willingness to run only a read-only notes server. Do not expose a shell, your whole home folder, passwords, or API keys.
Why this is a tunnel, and why that is risky
Google’s developer docs for the Connected Apps Platform say the MCP server URL must be a public HTTPS endpoint that speaks Streamable HTTP (not the older standalone SSE transport). A server that only listens on 127.0.0.1 on your tablet is not reachable from Google’s servers, so a localhost URL will not work by itself.
A temporary Cloudflare Quick Tunnel is one official way to give a local HTTP service a trycloudflare.com HTTPS URL without a Cloudflare account. Cloudflare’s Quick Tunnel docs also say anyone with the URL can access the service, the URL changes each time, Quick Tunnels are for testing, and Quick Tunnels do not support Server-Sent Events (SSE). That last point is why the sample server below sets json_response=True, which the official MCP Python SDK documents as returning a single JSON body instead of an SSE stream.
Google does not control, monitor, or secure third-party MCP servers. After data leaves Gemini, it is subject to that server. Gemini may share information from your chat and other connected sources with a custom app. Google says it requires manual confirmation for write actions, but it can make mistakes. Keep the sample server read-only, never put secrets in the notes folder, and stop the tunnel when you are done.
Run a Safe MCP Server and Connect It
These steps work in Termux on a phone or tablet. Connecting the URL happens in the Gemini web app, which Google documents for a phone, tablet, or computer.
-
Step 1: Confirm Google’s custom-app requirements
Before you install anything, check all of these:
- You are 18 or over and in the US.
- You are signed in with a personal Google Account. Work and school accounts cannot use this feature, according to Google’s help.
- You will use Gemini in English.
- Keep Activity is on. Google says it is on by default if you are 18 or over. To check or turn it on: open the Gemini app, tap Menu, then your profile picture or initial, then Gemini Apps Activity. If it is off, tap Off, review the disclosures, and tap Turn on. The same article covers this in the Gemini web app under Settings & help > Activity.
If any of those do not apply, stop here. Built-in Connected Apps (Gmail, Calendar, and so on) are a different feature and are not a workaround for custom MCP.
-
Step 2: Install Termux, Python, and cloudflared
Use F-Droid Termux, then update packages and install Python and Cloudflare’s tunnel client.
cloudflaredis in Termux’s official package repos.pkg update pkg upgrade pkg install python cloudflared python --version pip --version cloudflared --version pip install mcp
If
pip install mcpasks you to use a Termux-specific pip flag, follow the message it prints. The official MCP Python SDK’s run docs are what the server file in the next step follows, includingtransport="streamable-http"andjson_response=True. -
Step 3: Create a safe notes folder and the read-only server
Create a folder that holds only notes you are willing to show Gemini. Do not put passwords, keys, tokens, or private IDs there.
mkdir -p ~/gemini-safe-notes cat > ~/gemini-safe-notes/packing-hilo-day.txt << 'EOF' Water, sun shirt, closed-toe shoes, offline map for East Hawaiʻi. EOF nano ~/mcp-notes-server.py
Paste this server into
~/mcp-notes-server.py, then save and exit nano (Ctrl+X, then Y, then Enter):#!/usr/bin/env python3 """Read-only MCP server for a dedicated notes folder. Do not add shell, camera, or home-directory tools to this file. """ from pathlib import Path from mcp.server import MCPServer NOTES = Path.home() / "gemini-safe-notes" mcp = MCPServer("TermuxSafeNotes") def _safe_file(name: str) -> Path: if "/" in name or "\\" in name or name.startswith(".") or not name.endswith(".txt"): raise ValueError("Use a plain .txt filename in the notes folder only.") path = (NOTES / name).resolve() if path.parent != NOTES.resolve() or not path.is_file(): raise ValueError("File not found in the notes folder.") return path @mcp.tool() def list_notes() -> str: """List text files in the gemini-safe-notes folder.""" NOTES.mkdir(parents=True, exist_ok=True) names = sorted(p.name for p in NOTES.glob("*.txt") if p.is_file()) return "\n".join(names) if names else "No .txt notes yet." @mcp.tool() def read_note(filename: str) -> str: """Read one .txt note from the gemini-safe-notes folder. Pass only the filename.""" NOTES.mkdir(parents=True, exist_ok=True) text = _safe_file(filename).read_text(encoding="utf-8") if len(text) > 8000: return text[:8000] + "\n[truncated]" return text if __name__ == "__main__": mcp.run( transport="streamable-http", host="127.0.0.1", port=8000, json_response=True, )The server only lists and reads
.txtfiles inside~/gemini-safe-notes. It refuses paths with slashes or... It listens on127.0.0.1:8000— not on your LAN interface — and answers with JSON, not SSE.Start it in this Termux session and leave it running:
python ~/mcp-notes-server.py
Keep Termux in the foreground while you test so Android is less likely to sleep the process. If Termux gets put to sleep, see Set an App’s Battery Usage on Android after you finish, not as a way to hide a public server in the background.
-
Step 4: Open a temporary HTTPS Quick Tunnel
Open a new Termux session (Termux’s new-session control) so the Python server stays running. In the new session:
cloudflared tunnel --url http://127.0.0.1:8000
Cloudflare’s Quick Tunnel docs use this same command shape.
cloudflaredprints ahttps://….trycloudflare.comURL. The MCP endpoint is that URL plus/mcp— for example,https://random-words.trycloudflare.com/mcp. Google’s developer docs use a public HTTPS URL that often ends in/mcp.Treat that URL as a secret. Do not post it, do not screenshot it into a chat, and do not leave it in a note that syncs. Anyone who has the URL can reach the server until you stop
cloudflared. Do not add Cloudflare’s--allowed-mailflag here: Cloudflare documents that email authentication needs an interactive browser and does not support non-interactive clients, so Google’s servers would not be able to use it.A named Cloudflare Tunnel (the production kind, with a Cloudflare account and a hostname you control) is the documented upgrade if you outgrow a Quick Tunnel. This guide stays on Quick Tunnels because they need no account and they end when you stop the process.
-
Step 5: Add the custom app in the Gemini web app, then use it on the tablet
You can only connect custom apps in the Gemini web app. Google’s Android help says: on your phone or tablet, go to gemini.google.com, tap Menu, then Settings, then Connected Apps (if you do not see Connected Apps, first tap Personal Intelligence, then Connected Apps). Under Custom apps, tap Add a custom app, enter the HTTPS MCP URL (including
/mcp), tap Next, and follow the on-screen instructions. If the server does not support Dynamic Client Registration, Google says to open Advanced features and enter credentials. This sample server does not need that.You can also do the connect step on a computer at gemini.google.com if the tablet browser is awkward. Once it is connected, it is available in the Gemini mobile app too.
Google documents the connect step on a computer, phone, or tablet at gemini.google.com: open Settings, then Apps, then Connected Apps, then add a custom app, while you are signed in with a personal account and Keep Activity on. Menu labels may vary. If Connected Apps or Add a custom app is hard to find in a mobile browser, finish this connect step on a computer and come back to the mobile app to use the tool.
Then open the Gemini app on the tablet. To make sure Gemini uses the custom app, Google’s tip is to type
@and select it (it should show up as something like TermuxSafeNotes). Try: “@TermuxSafeNotes list my notes” and “read packing-hilo-day.txt.”After the custom app is connected, Google’s tip is to type
@in the Gemini mobile app and select the app from the list so Gemini uses it. If it does not appear, confirm that you finished the connect step at gemini.google.com, that Keep Activity is on, and that the mobile app is signed in with the same personal account. -
Step 6: Stop the tunnel and remove the custom app
When you are done, stop the tunnel first: in the
cloudflaredsession, press Ctrl+C. Thetrycloudflare.comURL stops working when that process stops, according to Cloudflare. Then stop the Python server with Ctrl+C in the other session.In gemini.google.com, go back to Connected Apps > Custom apps. Google documents turning the app off, or More details > Disconnect, or More details > Remove app if you want it gone from the list (Remove also unlinks the MCP server from your Google Account).
Do not leave a public tunnel running overnight, in a bag, or on a tablet you lend to someone else.
What not to build next
Related Byteslip guides
- Install Termux on Android the Right Way and Run Python Scripts in Termux.
- Keep Encrypted Field Notes in Termux With age — for notes that should never go near a public MCP server.
- Use Gemini on Android Without Making It Your Default Assistant — you can do this connect step from the Gemini app and web app; you do not have to make Gemini the default assistant to chat, though some overlay features still need that.
Official docs
Custom apps (US, 18+, personal account, Keep Activity, English, connect in the web app, @ on mobile): Gemini Apps Help 17209137. Keep Activity on/off: 13278892. Connected Apps overview: 13695044. Public HTTPS and Streamable HTTP (not legacy SSE): Connected Apps Platform transport spec and Developer Mode MCP URL. MCP Python SDK mcp.run() options, including json_response=True: MCP Python SDK run docs. Cloudflare Quick Tunnels (public URL, no SSE, testing only): Quick Tunnels.
