# Teeworlds-MRPG-0.6 Editor Studio — AI & MCP Guide

> Model-agnostic REST & MCP JSON-RPC 2.0 platform for inspecting MRPG 0.6 worlds, maps, items, quests, NPCs, mobs, shops, and JSON scenarios, and submitting safe human-reviewed Change Requests.

## Discovery Endpoints (Public)
- Onboarding (HTML / JSON): https://editor.mmotee.online/ai/ and https://editor.mmotee.online/ai/?format=json
- Plugin Descriptor: https://editor.mmotee.online/api/ai.php?action=discovery (alias: https://editor.mmotee.online/.well-known/ai-plugin.json)
- OpenAPI 3.1.0 Spec: https://editor.mmotee.online/api/ai.php?action=openapi (alias: https://editor.mmotee.online/openapi.json)
- MCP HTTP Endpoint (JSON-RPC 2.0): https://editor.mmotee.online/api/mcp.php (alias: https://editor.mmotee.online/mcp)
- REST API Entrypoint: https://editor.mmotee.online/api/ai.php

## Authentication & Safety Boundary
- Header: `Authorization: Bearer esai_<token>` (or `X-AI-Token: esai_<token>`)
- Scopes: `read`, `create`, `update`, `delete` (enforced server-side per tool/operation).
- Direct database/disk mutations are impossible: every write creates a Change Request in SQLite reviewed by a Studio administrator.
- Deletions, clearing JSON fields, >10 operations, or modifying `worlds`/`dungeons` require explicit `confirm_dangerous: true` after reviewing `dangerous_actions`.

## Recommended AI Workflow
1. **Capabilities & Schema**: `GET /api/ai.php?action=manifest` (MCP: `get_manifest`, `get_schema`, resource `mrpg://cookbook`).
2. **Fast Orientation**: `GET /api/ai.php?action=search&q=<term>` (MCP: `search_editor`) and `GET /api/ai.php?action=context&resource=worlds|quests|items|bots_info&id=<id>` (MCP: `get_context`).
3. **Maps & Visual Verification**: `GET /api/ai.php?action=analyze&resource=maps&world=<id>` (MCP: `analyze_map`) + `GET /api/ai.php?action=map_screenshot&world=<id>&target=overview|guild_house:1|house:1` (MCP: `get_map_screenshot` returning native PNG).
4. **Anti-Duplicates & Scenarios**: `GET /api/ai.php?action=similar&resource=<res>&name=<Name>` (MCP: `find_similar`) and `GET /api/ai.php?action=analyze&resource=scenarios` (MCP: `analyze_scenario`).
5. **Batch Reads & Filtering**: `GET /api/ai.php?action=get&resource=<res>&ids=1,2,3` (MCP: `get_record` with `ids`), plus `list` operator filters (`{"Level":{"gte":5}}`) and `sort=-ID`.
6. **Atomic Multi-Object Authoring (`ref` / `$alias`)**: Add `"ref": "my_item"` on any DB `create`/`copy` op and reference it as `"$my_item"` in FK fields, DSL (`"[$my_item/3]"`), or JSON in the same batch.
7. **Safe JSON Edits**: Prefer `patch_json` (RFC 7396); verify read-only via `POST /api/ai.php?action=apply_patch` (MCP: `apply_patch`), then `validate` -> `preview` -> `propose`.
8. **Review Loop**: Check admin feedback, reply, or withdraw pending requests via `GET /api/ai.php?action=request&id=<id>`, `POST action=request_reply`, `POST action=request_withdraw` (MCP: `manage_change_request`).
