loki-auto MCP Server
Enables LLM agents to automate browser tasks through secure, sandboxed Rhai scripts executed in a WebAssembly VM, supporting DOM interactions and tab management via MCP tools.
README
loki-auto (Open-Source Edition)
loki-auto is an ultra-lightweight, zero-dependency "Serverless in Browser" web automation runtime designed for the AI Agent era. It executes episodic, transient LLM tool actions inside a secure Rhai VM (compiled to WebAssembly) sandbox container directly within the browser's foreground page context, completely bypassing heavy headless browser resource overhead.
🛠 Architecture
loki-auto uses a stateless, event-driven Oneshot CGI paradigm:
graph TD
A[LLM Agent / Orchestrator] <-->|MCP Protocol over Stdio| B[Axum MCP Server Host]
B <-->|WebSocket ws://127.0.0.1:10402| C[Browser Extension BG Script]
C <-->|chrome.runtime Messages| D[Active Tab Content Script]
D -->|Instantiates On-Demand| E[Rhai WASM VM Sandbox]
E -->|Synchronous DOM interactions| F[Page DOM]
- Layer 1: Host Environment – Rust Axum MCP server handling Model Context Protocol (MCP) tool bindings and bridging commands over local WebSockets.
- Layer 2: Browser Background – Extension background script managing tab states and routing target instructions.
- Layer 3: Browser Sandbox – The content script instantiates a lightweight WASM-compiled Rhai VM per prompt invocation, executes DOM operations, captures results/logs, and purges the VM from memory instantly.
🚀 Getting Started
1. Prerequisites
Ensure you have the following installed on your system:
- Bun (Workspace package manager)
- Rust & Cargo (with
wasm32-unknown-unknowntarget installed:rustup target add wasm32-unknown-unknown) - wasm-pack (for Rust-to-WASM compilation)
2. Compilation and Build
Build the WebAssembly sandbox first, and then compile the extension assets:
# 1. Compile Rust Sandbox to WebAssembly
cd packages/sandbox
wasm-pack build --target web
# 2. Return to root, install dependencies and compile the Chrome/Firefox extensions
cd ../..
bun install
bun run build
This will output two fully-compiled, self-contained extension directories under the root folder:
- Chrome (Manifest V3):
./dist/chrome - Firefox (Manifest V2):
./dist/firefox
3. Load the Browser Extension
- Firefox: Open
about:debugging#/runtime/this-firefox, click "Load Temporary Add-on...", and select the compiled packageloki-auto.xpiat the root of the project (or select./dist/firefox/manifest.json). - Chrome: Open
chrome://extensions/, enable Developer mode, click "Load unpacked", and select the./dist/chromefolder.
4. Launch the Local MCP Server
Start the Axum host to begin listening for browser connections and LLM tool calls:
# Start the MCP host (default port: 10402)
cargo run --bin loki-mcp-server
🔌 MCP Tool Specifications
loki-auto exposes standard Model Context Protocol (MCP) tools:
list_tabs- Lists all open browser tabs and their focused states.open_tab(url, active)- Opens a new tab with the specified URL.close_tab(tab_id)- Closes a target tab by ID.activate_tab(tab_id)- Focuses a browser tab to the foreground.execute_loki_oneshot(target_tab_id, target_url_pattern, rhai_script, payload)- Runs a Rhai automation script synchronously inside the sandboxed VM of the target tab.
📝 Rhai Sandbox DOM APIs
Scripts running inside the WASM sandbox have access to the following synchronous DOM hooks:
sleep(ms)- Suspends execution for the specified milliseconds.log(message)- Prints a message/object to the execution console logs.dom_to_string() -> String- Returns a cleaned, token-optimized (AEO-optimized) HTML tree of the current page.element_exists(selector) -> bool- Immediate check if a element matches the CSS selector.wait_element(selector, [timeout_ms]) -> bool- Blocks until the element is present, or throws a timeout exception.click(selector, [timeout_ms]) -> bool- Wait and click on the selected element.type_text(selector, text, [timeout_ms]) -> bool- Wait and instantly set text into an input or textarea, triggering input events (recommended for long texts/articles).type_as_human(selector, text, [timeout_ms]) -> bool- Wait and type text character-by-character with randomized human typing delays and standard keydown/keyup events (recommended for search boxes and login inputs).get_text(selector, [timeout_ms]) -> String- Extract inner text content.get_value(selector, [timeout_ms]) -> String- Extract form input value.get_attribute(selector, attr, [timeout_ms]) -> String- Extract specific attribute value.scroll_to(selector, [timeout_ms]) -> bool- Scroll the viewport smoothly to the targeted element.get_loki_data(dom_selector, [timeout_ms]) -> String- Scopes target DOM and extracts child nodes bearingdata-lokiattributes in a clean, Markdown-friendly format.
[!NOTE] The
[timeout_ms]parameter in DOM APIs (e.g.,click,type_text,type_as_human) specifies the maximum wait time for the target element to appear in the DOM before throwing aTimeoutError(defaults to5000ms). Fortype_as_human, this is the element detection limit and does not restrict the typing execution time itself (which runs asynchronously and is only limited by the global 45-second MCP oneshot task timeout).
Example Rhai Script
print("Interacting with search input...");
if wait_element("textarea[name='q']", 2000) {
type_text("textarea[name='q']", "weather in Boston today");
sleep(500);
click("input[name='btnK']");
}
🛡 Security and Isolation
- Strict Sandbox: The Rhai runtime inside WebAssembly has no access to standard JS APIs, cookies, localStorage, or system files unless explicitly exposed through bridge bindings.
- No Network Access: The sandbox cannot perform
fetchor AJAX requests. All actions occur inside the page context, and results are returned via the secure extension channel.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。