autojs6-mcp-bridge
v0.1.0
Published
stdio to Streamable HTTP bridge for the AutoJs6 MCP Server plugin: lets stdio-only MCP clients such as Claude Desktop reach the phone
Maintainers
Readme
autojs6-mcp-bridge
Language: English | 简体中文
A small stdio to Streamable HTTP bridge for the AutoJs6 MCP Server plugin. MCP clients that can only launch stdio servers (Claude Desktop, older Cursor and Cline builds, anything without an HTTP transport) start this program; it forwards every JSON-RPC message to the phone over HTTP and returns the answers.
The bridge does not add tools, permissions or state of its own. The token and the phone-side pairing of the plugin still apply, and the phone still asks you to allow each new client.
Requirements
- Node.js 18 or newer.
- The AutoJs6 MCP Server plugin switched on in the AutoJs6 drawer, and its token copied from the plugin settings page.
- For USB: Android platform-tools (
adb) on the PATH or passed with--adb.
Install
npm install -g autojs6-mcp-bridge
autojs6-mcp-bridge --versionnpx autojs6-mcp-bridge works too, but clients start the bridge on every
session, so a global install keeps startup fast.
Usage
autojs6-mcp-bridge [options]
--url <url> Endpoint of the phone (default: http://127.0.0.1:9637/mcp)
--serial <serial> Run "adb -s <serial> forward" for the endpoint port and remove it on exit
--forward Run "adb forward" without -s (single device or emulator)
--adb <path> adb executable (default: adb on the PATH, or AUTOJS6_MCP_ADB)
--protocol <date> Request this MCP protocol version from the phone instead of the client's
--token <token> Bearer token; prefer the AUTOJS6_MCP_TOKEN environment variable
-h, --help Show this help
-v, --version Show the versionThe token is read from AUTOJS6_MCP_TOKEN first so that it does not appear in
process listings; --token is accepted for one-off use and prints a warning.
--serial and --forward require a loopback --url; over Wi-Fi pass the
address shown on the plugin settings page and leave forwarding off.
Client configuration
The plugin settings page copies the HTTP configuration for clients that support it. For stdio-only clients, point them at this bridge instead.
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"autojs6": {
"command": "autojs6-mcp-bridge",
"args": ["--serial", "<serial from adb devices>"],
"env": {
"AUTOJS6_MCP_TOKEN": "<token>"
}
}
}
}Claude Code (stdio fallback when the HTTP transport cannot be used):
claude mcp add autojs6 -e AUTOJS6_MCP_TOKEN=<token> -- autojs6-mcp-bridge --serial <serial>Any other stdio client: command autojs6-mcp-bridge, arguments as above, and
AUTOJS6_MCP_TOKEN in the environment block of its configuration. Over Wi-Fi
replace --serial <serial> with --url http://<phone-address>:9637/mcp.
How it works
- The client's stdin / stdout carry newline-delimited JSON-RPC (the MCP stdio transport); the bridge uses the official MCP SDK transports on both sides.
- Each message is POSTed to the phone with
Authorization: Bearer <token>, theMcp-Session-Idreturned by the phone and the negotiatedMCP-Protocol-Version. Responses arrive as JSON or as SSE and are written back to stdout unchanged. The phone's own errors, such asPAIRING_REQUIREDon the first call of a new client, pass through as they are; accept the pairing prompt on the phone and let the client retry. --protocol <date>rewrites theprotocolVersionof the client'sinitializerequest. Without it the client's version is passed through and the phone negotiates as usual.- With
--serialor--forward, the bridge runsadb forward tcp:<port> tcp:<port>before the first request andadb forward --removewhen the client closes stdin or the process receives SIGINT / SIGTERM. Requests that are still on their way to the phone when stdin ends get up to 10 s to finish, so a one-shotecho '{...}' | autojs6-mcp-bridgestill receives its answer. - The first connection through a forward that was just created can be
refused or reset while the phone's listener is coming up; the bridge
repeats
initializeup to 4 times (500 ms apart) before reporting the failure. Later requests are never repeated, because they may have already acted on the phone. - When a message cannot be delivered, the client receives a JSON-RPC error (code -32000) with one readable sentence instead of a hanging request:
| Situation | Message starts with |
| --- | --- |
| Token rejected | 401 Unauthorized from <url>: the token was rejected. Copy it again ... |
| Phone not listening or no forward | Cannot connect to <url> (connection refused): switch MCP Server on ... |
| Phone unreachable over Wi-Fi | Cannot reach <url> (EHOSTUNREACH): the phone is not reachable on this network ... |
| Host header not on the allow list | 421 Misdirected Request from <url>: the Host header is not accepted ... |
| Listener restarted | The connection to <url> was reset: the listener restarted ... |
| adb problems at startup | adb forward tcp:9637 failed (exit 1): ... Several devices are connected: pass --serial ... (exit code 3) |
Exit codes: 0 on a normal close, 1 on an unexpected error, 2 for invalid
options, 3 when adb forward fails.
Compatibility
| Bridge | Plugin | MCP protocol requested by the bridge | Node.js | Verified clients |
| --- | --- | --- | --- | --- |
| 0.1.0 | AutoJs6 MCP Server 1.0.0 | passes the client's version through (the plugin negotiates 2025-06-18 or older); --protocol overrides it | 18 or newer (engines); tested with 24.15 | Claude Code 2.1.257 (stdio, claude mcp add ... -- autojs6-mcp-bridge --serial <serial>) |
Keep this table in step with the plugin README; both sides list it.
Security
- The token authorizes full control of the phone through the plugin. Keep it in the environment block of the client configuration, not in shell history or process arguments, and rotate it from the plugin settings page if it leaks.
- The bridge talks plain HTTP to the phone. Over USB the traffic stays on the adb forward; over Wi-Fi use a trusted network and the addresses listed on the plugin settings page.
- Only stderr carries diagnostics; stdout is reserved for the protocol. The token is never logged.
Development
npm install
npm test # builds dist/ and runs node --test
npm run pack:checkTests cover option parsing, the adb forward lifecycle with a fake runner, the error mapping, and the message flow against a local fake phone (protocol passthrough and rewrite, session id and protocol headers, 401 and connection refused mapping, session termination on close).
License
Links
- Plugin: https://github.com/SuperMonster003/AutoJs6-Plugin-MCP-Server
- AutoJs6: https://github.com/SuperMonster003/AutoJs6
- MCP specification: https://modelcontextprotocol.io/specification
