Termux AI server: REST API daemon (termux-mcp) + native MCP server (termux-native-mcp) — let AI agents run shell commands on your Android device in real time
pip install termux-mcp==0.13.0 Copy PIP instructions
A lightweight HTTP server that runs inside Termux on Android, exposing shell execution and device capabilities as a streaming API. Built for AI agents, LLM tool-calling, and automation scripts.
AI Agent --> POST /run {"cmd": "ls -la"} --> Termux-MCP --> Termux Shell | <-- chunked streaming output -+ Two commands — which do I run? Command What it is termux-mcp REST API daemon on :8080 (this README's endpoints) termux-native-mcp Native MCP server (Model Context Protocol, spec 2025-06-18) for MCP clients: RikkaHub, desktop AI apps (Cursor, ...) Both install together via pkg install termux-mcp and run as separate processes — starting termux-native-mcp never touches the REST daemon's port, state or behavior.
termux-mcp # REST API on 127.0.0.1:8080 termux-native-mcp # native MCP, Streamable HTTP on 127.0.0.1:8081 termux-native-mcp --stdio # native MCP over stdin/stdout (desktop clients) RikkaHub (same phone):
{ "type": "http", "url": "http://127.0.0.1:8081/mcp", "commonOptions": { "name": "Termux", "enable": true, "headers": [["Authorization", "Bearer "]] } } Desktop MCP client (over ssh): {"command": "ssh", "args": ["android", "termux-native-mcp", "--stdio"]}
Both servers share the same safety system (risk gates, file snapshots, trash) because they run the same handler code.
pkg update && pkg install python -y pip install termux-mcp termux-mcp This installs a global termux-mcp command — it runs from any directory, and pip install -U termux-mcp upgrades it.
pkg update && pkg install python git -y git clone https://github.com/termuxgpt/termux-mcp cd termux-mcp pip install . termux-mcp pip install . registers the command globally, so the cd is only needed for the install itself. Without it, python -m termux_mcp only works from inside the clone.
curl -fSL https://termux-mcp.pages.dev/add-repo.sh | bash pkg install termux-mcp termux-mcp Quick Test curl http://localhost:8080/ping curl -X POST http://localhost:8080/run -H "Content-Type: application/json" -d '{"cmd": "ls ~"}' Termux Tutorial Apps (AD) Configuration Variable Default Description TERMUX_MCP_PORT 8080 HTTP listen port TERMUX_MCP_HOST 127.0.0.1 Bind address. Use 127.0.0.1 for local-only. TERMUX_MCP_TIMEOUT 0 Command timeout in seconds. 0 = no timeout (default) — long operations like pkg upgrade run until they finish. Set a positive value to re-enable the watchdog kill. TERMUX_MCP_AUTH on Authentication is on by default: a token is generated into ~/.termux-mcp/token (mode 0600) on first start. off disables it (loopback only). TERMUX_MCP_AUTH_TOKEN (generated) Use this token instead of the generated one TERMUX_MCP_CONFIG_DIR ~/.termux-mcp Token, pairing code, capability tokens, policy.json, event logs TERMUX_MCP_LOG_EVENTS 1 0 stops the JSONL event log (logs/events.jsonl) TERMUX_MCP_MAX_OUTPUT 20000 Max streamed output bytes per command. Output beyond this is drained (process keeps running) but not sent; a truncation marker is appended. Keeps LLM tool results small and token-efficient. Pair the app once: run termux-mcp pair in Termux and type the 6-digit code into the app when it asks (the code lasts 5 minutes and 5 tries). termux-mcp token prints the token for other clients; termux-mcp token --rotate replaces it immediately (paired apps pair again). When binding to a non-loopback address, authentication cannot be switched off.
Playbooks are declarative, one JSON file each, and validated when they load: phrases, typed slots, preconditions, steps with a verification, and the line to say afterwards. The doctor's checks are the same objects — a check is a probe with a fix, and a playbook's requires names a check. Ten ship with the package (update and upgrade, install anything, clone a repo, storage setup, check space, find what is eating it, clear the package cache, battery, wifi, an SSH key); harvest adds more, saved under ~/termuxGPT/playbooks/ and loaded alongside the shipped ones.
Every smart tool answers with a compact digest instead of raw output:
{"ok": false, "exit": 100, "summary": "", "errors": [{"code": "E_PKG_NOT_FOUND", "subject": "htopp"}], "fixes": [{"id": "pkg_search_name", "risk": "safe"}], "excerpt": "…", "out_ref": "8f2c1a"} Only six entries are listed in tools/list (run_digest, out_read, context_pack, batch, tool_search, smart). The other ~40 are reached with smart {tool, params} after tool_search returns their schema, so the per-request tool list stays small. Every one is also a REST endpoint (POST / ) and a WebSocket tool; native MCP results carry structuredContent.
MCP resources: termux://graph, termux://changes, termux://health, termux://context, termux://out/ .
Every shell call made by a smart tool has a hard timeout and runs in its own process group, so a hung termux-* command is killed with all of its children instead of blocking the connection.
One execution kernel. /run, WebSocket run, MCP run, run_digest and every shell-backed endpoint go through kernel.gate() — capability scope → policy.json → dangerous tier → warning tier (with one-shot device approvals) — and share one watchdog (TERMUX_MCP_TIMEOUT, termux-* helpers capped at 25 s, process groups via start_new_session). Transport-parity tests keep all four answering the same way. GET /metrics (and the metrics tool) shows per-tool p50/p95 latency, error rates, error codes and FixGraph success rates; each call is also a line in ~/.termux-mcp/logs/events.jsonl.
Power tools: venv_ensure, node_ensure, proot_ensure/proot_run, cron_ensure, tunnel (time-limited public URL), web_fetch (readable text / CSS selector), db_query (SQLite or CSV), log_watch (reactor log_match), file_find (indexed), backup_incremental (dedup + verify + restore; encrypted via restic), clipboard_pipe, share_to, media_convert (ffmpeg presets with progress), ssh_hosts/ssh_run.
All of them are reached through smart {tool, params} / tool_search, so tools/list stays at six entries.
The /run endpoint and most tool endpoints use HTTP chunked transfer encoding. Output is sent line-by-line as the command produces it. Clients should read the response as a stream and process each chunk as it arrives.
For long-running commands, a watchdog thread enforces the timeout. Package install commands automatically receive -y flags and DEBIAN_FRONTEND=noninteractive to prevent prompts.
GNU Affero General Public License v3.0 (AGPL-3.0)
Copyleft — anyone who distributes a modified version, or hosts it as a service (SaaS), must release their changes under the same license.
Note: versions up to 0.8.3 were released under the MIT License; those releases keep their MIT terms. AGPL-3.0 applies from 0.8.4 onward.
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.




