feat(V2): X-Bot-Tag header obbligatorio + endpoint /admin/audit con filtri
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -62,6 +62,20 @@ Le tool puramente read-only (`/mcp-macro/*` e `/mcp-sentiment/*`)
|
||||
richiedono comunque un bearer valido, ma il valore (testnet o mainnet) è
|
||||
indifferente perché non hanno endpoint testnet.
|
||||
|
||||
### Header X-Bot-Tag (identificazione bot)
|
||||
|
||||
Tutte le chiamate a `/mcp-*` richiedono inoltre l'header `X-Bot-Tag` con
|
||||
una stringa identificativa del bot chiamante (massimo 64 caratteri). Il
|
||||
valore viene loggato negli audit record per tracciare quale bot ha
|
||||
eseguito ogni operazione write. Esempio di richiesta:
|
||||
|
||||
Authorization: Bearer $MAINNET_TOKEN
|
||||
X-Bot-Tag: scanner-alpha-prod
|
||||
|
||||
Se l'header è assente o vuoto la risposta è `400 BAD_REQUEST`. L'header
|
||||
non è richiesto sugli endpoint pubblici (`/health`, `/apidocs`,
|
||||
`/openapi.json`) né sull'endpoint admin `/admin/audit`.
|
||||
|
||||
## Endpoint principali
|
||||
|
||||
| Path | Descrizione |
|
||||
@@ -75,6 +89,33 @@ indifferente perché non hanno endpoint testnet.
|
||||
| `POST /mcp-alpaca/tools/{tool}` | Tool exchange Alpaca |
|
||||
| `POST /mcp-macro/tools/{tool}` | Tool macro/market data |
|
||||
| `POST /mcp-sentiment/tools/{tool}` | Tool sentiment/news |
|
||||
| `GET /admin/audit` | Query dell'audit log JSONL (bearer richiesto, no X-Bot-Tag) |
|
||||
|
||||
## Audit query
|
||||
|
||||
`GET /admin/audit` legge il file JSONL puntato da `AUDIT_LOG_FILE` e
|
||||
restituisce i record filtrati. Richiede un bearer valido (testnet o
|
||||
mainnet); non richiede l'header `X-Bot-Tag`.
|
||||
|
||||
Parametri di query (tutti opzionali):
|
||||
|
||||
- `from`, `to`: ISO 8601 datetime (es. `2026-05-01` o `2026-05-01T12:34:56Z`)
|
||||
- `actor`: `testnet` | `mainnet`
|
||||
- `exchange`: nome dell'exchange (`deribit`, `bybit`, `hyperliquid`, `alpaca`)
|
||||
- `action`: nome del tool (es. `place_order`)
|
||||
- `bot_tag`: identificatore del bot
|
||||
- `limit`: massimo record restituiti, default `1000`, massimo `10000`
|
||||
|
||||
Esempio di chiamata:
|
||||
|
||||
curl -H "Authorization: Bearer $MAINNET_TOKEN" \
|
||||
"http://localhost:9000/admin/audit?from=2026-05-01&actor=mainnet&action=place_order&limit=100"
|
||||
|
||||
Se `AUDIT_LOG_FILE` non è configurata l'endpoint risponde `count: 0` con
|
||||
un campo `warning`. Per abilitare il sink persistente impostare nel `.env`:
|
||||
|
||||
AUDIT_LOG_FILE=/var/log/cerbero-mcp/audit.jsonl
|
||||
AUDIT_LOG_BACKUP_DAYS=30
|
||||
|
||||
## Tool disponibili
|
||||
|
||||
|
||||
Reference in New Issue
Block a user