Files

105 lines
10 KiB
Markdown

# ๐Ÿ”Œ Universal MCP Server for ARTEMIS
This directory contains ARTEMIS's connection-only MCP bridge and the tools hosted by the user-started web service. Official automatic configuration and Skill installation currently support Codex.
## ๐Ÿ—๏ธ Architecture
```
mcp_server/
โ”œโ”€โ”€ __init__.py # Package exports (mcp, main)
โ”œโ”€โ”€ base.py # Shared FastMCP instance
โ”œโ”€โ”€ server.py # Compatibility entrypoint for the stdio bridge
โ”œโ”€โ”€ bridge.py # Connection-only, lightweight stdio -> local HTTP
โ”œโ”€โ”€ shared.py # Tools hosted in the user-started web process
โ”œโ”€โ”€ catalog.json # Offline schemas; regenerate with scripts/generate_mcp_catalog.py
โ”œโ”€โ”€ rules.md # Compatibility link to the official artemis-use Skill
โ”œโ”€โ”€ background/ # Background process execution
โ”‚ โ””โ”€โ”€ task_runner.py # Subprocess runner for Artemis Agent
โ”œโ”€โ”€ notifiers/ # Multi-environment notification adapters
โ”‚ โ”œโ”€โ”€ base.py # BaseNotifier abstract class
โ”‚ โ”œโ”€โ”€ agentapi.py # Jetski / Antigravity AgentAPI notifier (with session sorting & caching)
โ”‚ โ”œโ”€โ”€ desktop.py # Native OS toast notifier (macOS/Linux/Windows, enabled by default)
โ”‚ โ”œโ”€โ”€ script.py # Universal Script / Command Hook notifier (ARTEMIS_NOTIFY_CMD)
โ”‚ โ”œโ”€โ”€ webhook.py # OpenClaw / CI / Discord / Slack webhook notifier
โ”‚ โ”œโ”€โ”€ file.py # File audit logger (notifications.jsonl)
โ”‚ โ””โ”€โ”€ composite.py # Multi-channel notification dispatcher
โ”œโ”€โ”€ tools/ # Modular standard MCP tools
โ”‚ โ”œโ”€โ”€ task_runner.py # mobile_run_task
โ”‚ โ”œโ”€โ”€ task_manager.py # mobile_manage_task
โ”‚ โ”œโ”€โ”€ device_state.py # mobile_get_device_state
โ”‚ โ”œโ”€โ”€ inspect_trace.py # mobile_inspect_trace
โ”‚ โ””โ”€โ”€ diagnose.py # mobile_diagnose
โ””โ”€โ”€ utils/ # Environment and device utilities
โ”œโ”€โ”€ device_utils.py # Cross-platform ADB and emulator resolver
โ””โ”€โ”€ env_utils.py # Python interpreter and process manager
```
The trace status store (traces directory layout and `status.json` lifecycle)
lives in the neutral base package as `artemis/runtime/trace_store.py`, shared
by the MCP server, the admin console, and spawned worker processes.
## ๐Ÿ”” Multi-Platform Notification & Wakeup Support
When you start an asynchronous mobile test via `mobile_run_task`, the user-started Artemis web service queues and runs the job so the AI agent is not blocked. Upon completion or failure, Artemis dispatches alerts across **all available notification channels** so that both human developers and AI agents are notified immediately across different platforms:
| Platform / Environment | Primary Notification Mechanism | How It Works & Configuration |
| :--- | :--- | :--- |
| **Antigravity / Jetski** | **Reactive Wakeup (`AgentApiNotifier`)** | Automatically detects and caches the active IDE session credentials (`ANTIGRAVITY_LS_ADDRESS`, `ANTIGRAVITY_CSRF_TOKEN`), sorting candidate processes by creation time to avoid stale PIDs, and calls `agentapi send-message` to wake up the agent directly in the conversation. |
| **Cursor / Windsurf / VS Code / Cline / Roo Code** | **Native Desktop Toast (`DesktopNotifier`) + File Audit (`FileNotifier`)** | Enabled **by default** across macOS (`osascript`), Linux (`notify-send`), and Windows (`powershell`). Pops up a system notification banner informing the developer whether the task completed or failed. The AI agent inspects `<trace_dir>/status.json` or uses `mobile_manage_task(action="status")`. Can be silenced via `ARTEMIS_DESKTOP_NOTIFY=false`. |
| **Claude Code / Desktop** | **Native Desktop Toast + File Audit** | Alerts the user via system desktop notification banner when background execution concludes, while maintaining a complete JSONL audit log in `notifications.jsonl`. |
| **OpenClaw / Slack / Discord / CI/CD** | **HTTP Webhook (`WebhookNotifier`)** | Sends structured JSON POST payloads to custom endpoints configured via `OPENCLAW_WEBHOOK_URL`, `MCP_NOTIFICATION_WEBHOOK`, or `ARTEMIS_WEBHOOK_URL`. |
| **Universal Custom IDE / CLI Hooks** | **Custom Script Hook (`ScriptNotifier`)** | Set `ARTEMIS_NOTIFY_CMD="my-script --title '{title}' --message '{message}' --trace-id '{trace_id}'"` in your environment to execute any custom command or script upon event completion. |
## Official Codex Skill
[`artemis-use`](../skills/artemis-use/SKILL.md) explains Flash, Pro and guided exploration, task diagnosis, evidence review, batching and plugin development. Detailed references load only when relevant. Its whole official directory is maintained by ARTEMIS; no global rule block is injected into AGENTS.md.
### How Global Rules & MCP are Installed
Only Codex configuration is installed: `uv run artemis mcp --install codex`. It preserves other clients and services. The user starts the web service with `start.bat`, `start-cn.bat`, or `uv run artemis ui`. The stdio bridge never starts a backend or standalone worker; all tool execution shares the web process. Offline initialization and tools/list still work, while tool calls explain how to start the service. Codex configuration is optional (`required = false`) so failures cannot block unrelated sessions. Reload both the web process and old MCP connections after upgrading.
The bridge discovers a live service from the same installation; `ARTEMIS_DAEMON_PORT` selects between multiple data spaces. Disconnection never replays a request automatically. Regenerate `catalog.json` after changing tool schemas; tests compare it with the live registrations.
## ๐Ÿ› ๏ธ MCP Tools Overview
* **`mobile_exploration`**: Guided exploration using the same queue and conversation as the web workspace. Create/start, exchange messages, pause/continue, record and analyze demonstrations, save immutable case versions, rerun with Flash/Pro, or add a batch draft. Writes use stable request IDs; reads never launch work. Defaults are independent (`gpt-6.1-terra / high`) and timeouts pause without marking the test failed. See the [exploration workflow](../docs/exploration-mode.md).
* **`mobile_run_task`**: Asynchronously launches an autonomous mobile automation task (`Flash` or `Pro` model) with optional `device_serial` targeting. Pro runs can be tuned with `verification_level` (`off` | `final` | `checkpoints` | `strict` โ€” how much the Checker audits) and `explorer_mode` (`flash` | `pro` | `ultra` โ€” the Operator's perception depth).
* **`mobile_manage_task`**: Manages task lifecycle (`status`, `stop`, `inject_instruction`), returning task state and assigned `device_serial`. Pass `release_loop=True` with `inject_instruction` to gracefully end a `[Loop:continuous]` monitoring task โ€” this explicit signal (not "please stop" wording) is what unlocks the loop milestone's completion.
* **`mobile_get_device_state`**: Real-time observer (`screenshot` or OCR+XML `hierarchy`) with optional `device_serial`.
* **`mobile_inspect_trace`**: Granular trace inspection, visual action overlays, agent reasoning, and `device_serial` tracking.
* **`mobile_diagnose`**: Environment doctor for the IDE. Reuses the readiness probes behind `artemis doctor` and the web console's device wizard (Python runtime, config, LLM credentials, ADB / devices / RSA keys / emulators, video toolchain) plus an MCP-host probe (server interpreter vs project `.venv`, detected MCP client, `.env` location, traces directory, daemon port collisions). Returns a `verdict` (`ready` | `degraded` | `blocked`), an ordered `next_steps` fix list the AI agent can act on (`Run:` one-command lines vs `Guidance:` for the user), scrubbed per-check details, `tasks` holding or waiting for devices, log paths, and the most recent failed task with its `recent_errors`. Optional deep checks: `verify_credentials=true` (live API-key validation, ~12s, result in `credentials`), `probe_device=true` (end-to-end screenshot + UIAutomator hierarchy, ~20s, result in `device_probe`), `launch_avd="<name>"` (boots an installed AVD in the background; re-run after ~60s). `attempt_fix=true` applies the safe self-heals (regenerate corrupted ADB keys, restart the ADB server, clear stale device locks / queue tickets left by crashed runners).
### ๐Ÿ“ฑ Device Selection & Multi-Device Execution
ARTEMIS supports parallel execution across multiple connected Android devices and emulators:
1. **Direct Device Specification**: Provide `device_serial` explicitly (e.g. `device_serial="63191FDKX00062"` or `device_serial="emulator-5554"`). Per-device execution locks allow distinct devices to run in parallel.
2. **Automatic Device Selection**: Omit `device_serial` to let ARTEMIS auto-select an available ready device from the device pool.
* **User Choice Priority**: When multiple devices/emulators are connected, AI agents should prioritize asking the user which device to run on.
* **Device Diagnosis**: Inspect connected hardware, authorization status, and serials anytime via `adb devices` or `adb devices -l`.
## ๐Ÿš€ How to Run & Configure
### CLI Execution
```bash
# Start server over stdio
python -m mcp_server
# Or via Artemis CLI
uv run artemis mcp
```
### IDE Configuration
#### One-Click Auto Install (Recommended)
Start ARTEMIS normally to synchronize Codex, or repair the integration explicitly:
```bash
uv run artemis mcp --install codex
```
#### Manual JSON Config Generation
Run `uv run artemis mcp --generate-config codex` to output a configuration template with resolved Python and project paths.
## ๅฎŒๆ•ด AI ่‡ชๅŠจๅŒ–
ๅทฅไฝœๅŒบๅทฅๅ…ทไธŽ็ฝ‘้กตๅ…ฑ็”จๅŽๅฐๆœๅŠก๏ผŒ่ฆ†็›–ๆ™ฎ้€šไธŽๆŽข็ดขไปปๅŠกใ€ๆ‰นๆฌกใ€ๅކๅฒใ€่ฏŠๆ–ญใ€ไบบๅทฅๅค้ชŒๅŠๆŠฅๅ‘Šๅฏผๅ‡บใ€‚ๅ‚่ง [ๆŽฅๅ…ฅ่ฏดๆ˜Ž](../docs/ai-automation.md) ๅ’Œ [Skill](../skills/artemis-use/SKILL.md)ใ€‚็ฝ‘้กตๅฏๅŠจๆ—ถๅŒๆญฅๅฎ˜ๆ–น Skill ไธŽ MCP ๆŽฅๅ…ฅ๏ผ›ๅทฒๆœ‰ๅฎกๆ‰น็ญ–็•ฅๅŠๅทฅๅ…ท็™ฝๅๅ•ไฟ็•™ใ€‚ๆ›ดๆ–ฐๅŽ้‡ๆ–ฐๅŠ ่ฝฝ MCP ๆ‰่ƒฝไฝฟ็”จๆ–ฐ็‰ˆๅทฅๅ…ทๅฎšไน‰ใ€‚
* **`mobile_favorites`**: Save independent task/case/batch templates, list or rename favorites, adjust their defaults, and start a new run with original settings. Per-run overrides are temporary; run retries use the same request_id. Source deletion does not delete favorites. See the [batch and favorite workflow](../skills/artemis-use/references/batches.md).