---
name: mx-message-query
description: Query Midea MX / 美信 local message cache through the MX local HTTP query service from Codex. Use when the user asks to read MX sessions, search chat history, search messages globally or inside a group/session, list recent messages, or page message history. This is read-only and does not require send authorization. Never fall back to reading SQLite or app cache files directly.
---

# MX Message Query

Use this skill for read-only MX / 美信 message-cache queries.

## Rules

- Read-only queries do not require extra user authorization.
- Do not send messages from this skill.
- Do not read MX SQLite databases, app internals, or cache files directly.
- Use exposed `mx_message_*` tools if the current Codex context provides them.
- If no tool is exposed, use `scripts/mx_query.py`, which calls the MX local
  HTTP query service only.
- If the local service rejects auth or cannot be located, report that directly.

## Auth

`scripts/mx_query.py` resolves auth in this order:

1. `MX_MESSAGE_QUERY_BEARER_TOKEN`.
2. `OPENCLAW_MX_SERVER_PORT` + `OPENCLAW_MX_SERVER_SECRET` from the current env.
3. The MX OpenClaw LaunchAgent plist
   `ai.midea-openclaw.gateway-stable.plist`, then `GET /oc-token` with
   `x-server-secret` to exchange a fresh OC token.
4. `MX_OC_TOKEN`.
5. Runtime MCP config `mcporter.json`.
6. `/tmp/ua_token.txt`.

Never print or store the raw OC token or server secret in skill docs, repo files,
logs, or memory.

## Commands

List sessions:

```bash
python3 scripts/mx_query.py sessions --limit 20 --offset 0
```

List messages in a session:

```bash
python3 scripts/mx_query.py list --sid "<sId>" --page-size 20
```

Global search:

```bash
python3 scripts/mx_query.py search-global --keyword "<关键词>" --limit 20
```

Session search:

```bash
python3 scripts/mx_query.py search-session --sid "<sId>" --keyword "<关键词>" --limit 20
```

History paging:

```bash
python3 scripts/mx_query.py history \
  --sid "<sId>" \
  --mid "<mid>" \
  --timestamp 1704000000000 \
  --direction before
```

By default the script prints compact previews. Use `--raw` only when the user
needs complete returned JSON.

For the original MX tool contract, read `references/original-skill.md`.
