# PiksoResourcePlatform — Agent Integration Guide

> Pikso 2D 角色装扮、场景物件、动作动画、视频/透明序列帧导出与资源画布管理平台（支持免登录公开卡片 API 与 Remote MCP Streamable HTTP）。

- **Base Origin**: `https://pikso-assets.vm.tooqing.com`
- **Human / Interactive Guide**: https://pikso-assets.vm.tooqing.com/agent
- **Machine JSON Spec**: https://pikso-assets.vm.tooqing.com/api/v1/agent/guide
- **Remote MCP Endpoint**: `https://pikso-assets.vm.tooqing.com/mcp` (Streamable HTTP (JSON-RPC 2.0))
- **OAuth 2.1 Discovery**: https://pikso-assets.vm.tooqing.com/.well-known/oauth-authorization-server
- **Live Status**: catalog=0, savedOutfits=undefined, actions=76, ffmpeg=available

## 1. Authentication Summary

- **No Auth Required**: `/cards/character`, `/cards/object`, `/agent`, `/llms.txt`, `/api/v1/agent/guide`, and all `/api/v1/cards/*` endpoints (manifests, card details, character card video/frame export & download).
- **Bearer / OAuth 2.1 Required**: `/mcp` (Streamable HTTP JSON-RPC 2.0) and workspace `/api/v1/*` management APIs.
- **MCP Session Header**: First send `initialize` to `POST /mcp`, capture the `Mcp-Session-Id` response header, and send it on subsequent `tools/list` and `tools/call` requests.

## 2. Public Card Pages & REST APIs (No Auth)

### `GET /cards/character`
独立角色卡展示页（默认播放 Idle 动画，点击展开右侧详情与导出弹框）
Query parameters:
- `id` (e.g. `default`): 角色卡 ID（default / outfit_xxx / avatar:20087 / equip:10001）
- `facing` (e.g. `right_front`): 初始朝向：right_front | left_front | right_back | left_back
- `clip` (e.g. `Idle`): 初始播放动作名称
- `gender` (e.g. `2`): 仅 id=default 时生效，1=男，2=女
Example: `https://pikso-assets.vm.tooqing.com/cards/character?id=default`

### `GET /cards/object`
独立物件卡展示页（含动画时自动循环播放，点击展开右侧详情）
Query parameters:
- `key` (e.g. `system_resource:4017992`): 物件资源 key（留空自动展示默认带动画物件）
Example: `https://pikso-assets.vm.tooqing.com/cards/object?key=system_resource%3A4017992`

### `GET /api/v1/cards/outfits` (aliases: `/api/v1/cards/characters`)
免登录拉取装扮清单（含已保存角色卡 savedOutfits 与全部动作清单 actions）
Query parameters:
- `q` (e.g. `冬`): 按中文名/英文名/标签关键字检索
- `gender` (e.g. `2`): 性别筛选：1=男，2=女
- `part` (e.g. `coat`): 部位筛选
- `cached` (e.g. `parsed`): 缓存筛选：all | parsed | unparsed
- `actionCategory` (e.g. `dance`): 动作分类筛选：idle | emote | dance | move | pose
- `page` (e.g. `1`): 页码（传 all=1 可一次返回全部）
- `pageSize` (e.g. `20`): 每页数量（最大 200）
Example: `https://pikso-assets.vm.tooqing.com/api/v1/cards/outfits?page=1&pageSize=10`

### `GET /api/v1/cards/characters/:id`
免登录获取单张角色卡配置、穿戴部件及可用动作清单
Query parameters:
- `gender` (e.g. `2`): 仅 id=default 时可选
Example: `https://pikso-assets.vm.tooqing.com/api/v1/cards/characters/default`

### `POST /api/v1/cards/characters/:id/export`
导出角色卡为 MP4、透明通道 MOV (ProRes 4444) 或 PNG 序列帧 ZIP（请求体传 {} 即使用默认配置）
Example JSON body:
```json
{
  "format": "mov",
  "clipName": "Idle",
  "facing": "right_front",
  "width": 720,
  "height": 900,
  "fps": 30,
  "loops": 1,
  "background": "transparent",
  "scale": 1
}
```
Example: `https://pikso-assets.vm.tooqing.com/api/v1/cards/characters/default/export`

### `GET /api/v1/cards/exports/:exportId/download`
下载已导出的 .mp4 / .mov / _frames.zip 文件（支持 Range 断点续传与 ?inline=1 预览）
Query parameters:
- `inline` (e.g. `1`): 设为 1 时浏览器内联预览而非强制附件下载
Example: `https://pikso-assets.vm.tooqing.com/api/v1/cards/exports/cexp_xxxxxxxxxxxx/download`

### `GET /api/v1/cards/export-config`
查询角色卡导出的默认参数、边界范围及 FFmpeg 可用状态
Example: `https://pikso-assets.vm.tooqing.com/api/v1/cards/export-config`

### `GET /api/v1/cards/objects` (aliases: `/api/v1/cards/items`)
免登录拉取物品 / 场景物件清单（支持关键词、维度与缓存状态筛选）
Query parameters:
- `q` (e.g. `lamp`): 关键词检索
- `cached` (e.g. `parsed`): all | parsed | unparsed
- `dimension` (e.g. `2d`): 2d | 3d | all
- `page` (e.g. `1`): 页码（all=1 返回全量）
- `pageSize` (e.g. `20`): 每页数量
Example: `https://pikso-assets.vm.tooqing.com/api/v1/cards/objects?cached=parsed&page=1&pageSize=10`

### `GET /api/v1/cards/objects/:key`
免登录获取单张物件卡完整元数据与动画摘要（hasAnimation / clips）
Example: `https://pikso-assets.vm.tooqing.com/api/v1/cards/objects/system_resource%3A4017992`

### `GET /api/v1/cards/clips`
获取角色全部可用动作列表（支持 ?category=idle|emote|dance|move|pose）
Query parameters:
- `category` (e.g. `emote`): 动作分类筛选
Example: `https://pikso-assets.vm.tooqing.com/api/v1/cards/clips`

### `POST /api/v1/cards/outfits/compose`
根据性别与装备 ID 列表实时解析试穿搭配结果
Example JSON body:
```json
{
  "gender": 2,
  "equipIds": []
}
```
Example: `https://pikso-assets.vm.tooqing.com/api/v1/cards/outfits/compose`

## 3. Character Card Export Defaults

- `format`: `"webm"` (options: mp4 | mov | webm | frames)
- `width` x `height`: `720x900` (range: 256..2048)
- `fps`: `30` (range: 10..60)
- `loops`: `1` (range: 1..5; or set `durationSec` 0.4..30)
- `background`: default `"dark"` for `mp4`, `"transparent"` (Alpha channel!) for `mov` (Apple ProRes 4444) and `frames` (RGBA PNG sequence ZIP)
- `scale`: `1` (range: 0.5..2.0)

## 4. Remote MCP Tools (26 tools)

```json
{
  "mcpServers": {
    "pikso-resource-platform": {
      "type": "streamable-http",
      "url": "https://pikso-assets.vm.tooqing.com/mcp",
      "headers": {
        "Authorization": "Bearer <YOUR_ACCESS_TOKEN>"
      }
    }
  }
}
```

### `search_resources` [read | 资源检索与预览]
Search Pikso resource catalog across equip, scene_object, scene_component, system_resource, and avatar items.
- Required args: none
```json
{
  "q": "冬",
  "kind": "equip",
  "dimension": "2d",
  "gender": 2,
  "pageSize": 10
}
```

### `get_resource_detail` [read | 资源检索与预览]
Get full metadata, AssetBundle dependencies, and cache status for a resource key.
- Required args: `key`
```json
{
  "key": "system_resource:4017992"
}
```

### `preview_resource` [write | 资源检索与预览]
Ensure a resource prefab or icon AssetBundle is parsed and return exported PNG URLs and graph summary.
- Required args: `key`
```json
{
  "key": "equip:10001",
  "force": false
}
```

### `compose_outfit` [write | 角色卡与导出]
Compose a complete EZ2D avatar outfit for a target gender and equip IDs, filling defaults and sorting by draw order.
- Required args: `gender`, `equipIds`
```json
{
  "gender": 2,
  "equipIds": [
    10001
  ],
  "resolvePreview": false
}
```

### `list_character_cards` [read | 角色卡与导出]
List saved persistent EZ2D character cards (outfits) with direct shareable /cards/character?id=<id> URLs and available action clips.
- Required args: none
```json
{
  "limit": 20
}
```

### `create_character_card` [write | 角色卡与导出]
Create and persist a named EZ2D character card (saved outfit) and return a direct viewable /cards/character?id=<id> URL.
- Required args: `name`, `equipIds`
```json
{
  "name": "冬日暖绒少女",
  "description": "适合冬季主题展示的 2D 装扮",
  "gender": 2,
  "equipIds": [
    10001
  ],
  "facing": "right_front",
  "clipName": "Idle"
}
```

### `update_character_card` [write | 角色卡与导出]
Update an existing saved EZ2D character card and return its direct viewable /cards/character?id=<id> URL.
- Required args: `id`
```json
{
  "id": "default",
  "clipName": "Dance01",
  "facing": "left_front"
}
```

### `export_character_card` [write | 角色卡与导出]
Export a character card (saved outfit, avatar, or equip) with a clean transparent Alpha channel by default for easy compositing into video scripts. Defaults to WebM (VP9 Alpha, 720x900, 30fps, 1 loop, transparent); also supports transparent MOV (qtrle 8-bit RGBA default or prores_4444, plus h264 opaque), RGBA PNG frame sequence ZIP (with manifest.json), and MP4 (H.264).
- Required args: `id`
```json
{
  "id": "default",
  "format": "webm",
  "clipName": "Idle",
  "facing": "right_front",
  "width": 720,
  "height": 900,
  "fps": 30,
  "loops": 1,
  "background": "transparent"
}
```

### `create_download_bundle` [write | 打包下载与运维]
Package one or more Pikso resources into a downloadable ZIP bundle and return its metadata and downloadUrl.
- Required args: `keys`
```json
{
  "keys": [
    "system_resource:4017992"
  ],
  "name": "my_bundle",
  "includeTextures": true,
  "includeGraph": true
}
```

### `get_cache_status` [read | 资源检索与预览]
Get catalog summary, L1/L2 cache hit statistics, disk usage, parser pool status, and recent jobs.
- Required args: none
```json
{}
```

### `prewarm_resources` [admin | 打包下载与运维]
[Admin only] Submit an asynchronous prewarm job for resource keys or a search filter.
- Required args: none
```json
{
  "keys": [
    "system_resource:4017992"
  ]
}
```

### `sync_catalog` [admin | 打包下载与运维]
[Admin only] Sync MiniTypeGroupData and ResourceListMD5 from upstream servers.
- Required args: none
```json
{
  "force": false
}
```

### `generate_outfit_batch` [write | 角色卡与导出]
Match EZ2D outfits and animation actions from a prompt, generate 10 outfits × 5 actions (or configured counts), write preview PNGs/manifests into outputDir, and create a downloadable ZIP archive.
- Required args: `prompt`
```json
{
  "prompt": "冬日甜美少女",
  "count": 3,
  "gender": 2
}
```

### `list_story_scripts` [read | 其他工具]
List saved Pikso drama story scripts, their rendered video status, and built-in starter templates.
- Required args: none
```json
{}
```

### `create_story_script` [write | 场景与剧情视频]
Validate, normalize, and persist a StageMcp-compatible story script (spawns, setup, frames) under cache/stories.
- Required args: `name`
```json
{
  "title": "示例剧情",
  "sceneId": "scene_default",
  "steps": []
}
```

### `render_story_video` [write | 场景与剧情视频]
Execute a saved story script in the headless 2D stage renderer and capture an H.264 MP4 (or WebM fallback) video file.
- Required args: `storyId`
```json
{
  "storyId": "story_xxxxxxxx"
}
```

### `list_server_scenes` [read | 其他工具]
List distinct server scenes indexed from live sceneFeedUrl, cached scenes, saved scene copies, and local TempStreamingAssets Cache/Scene packages.
- Required args: none
```json
{}
```

### `pull_server_scenes` [write | 场景与剧情视频]
Pull and cache N (default 10) distinct server scenes from sceneFeedUrl, areaTemplates, or Cache/Scene packages into cache/scenes/.
- Required args: none
```json
{
  "limit": 5
}
```

### `export_scenes_psd` [write | 场景与剧情视频]
Pull up to count (default 10) distinct scenes, render separated transparent layers (01_SkyBox..05_Foreground_Decor), and export standard layered 8BPS .psd files + ZIP.
- Required args: none
```json
{
  "sceneIds": [
    "scene_default"
  ]
}
```

### `list_resource_projects` [read | 资源工程与无限画布]
List saved Pikso resource projects (infinite canvas workspaces) with card counts, deliverable counts, and viewport state.
- Required args: none
```json
{}
```

### `create_resource_project` [write | 资源工程与无限画布]
Create a new Pikso resource project with an infinite canvas workspace.
- Required args: `name`
```json
{
  "name": "冬季宣发工程",
  "description": "整合角色卡与视频片段"
}
```

### `get_project_canvas` [read | 其他工具]
Get the full infinite canvas state for a resource project, including cards, stacked overlays, ownership tags, and deliverables.
- Required args: `projectId`
```json
{
  "projectId": "<projectId>"
}
```

### `upsert_canvas_card` [write | 资源工程与无限画布]
Create a new text/image/video card on a project canvas (when cardId is omitted) or update an existing card (when cardId is provided).
- Required args: `projectId`
```json
{
  "projectId": "proj_xxxxxxxx",
  "kind": "text",
  "title": "宣发文案",
  "content": "冬日限定装扮上线"
}
```

### `append_card_overlay` [write | 资源工程与无限画布]
Append a non-destructive AI result overlay (polish, generate_image, generate_video, or custom) onto an existing canvas card without overwriting its original content.
- Required args: `projectId`, `cardId`, `action`, `resultType`
```json
{
  "projectId": "proj_xxxxxxxx",
  "cardId": "card_xxxxxxxx",
  "action": "polish",
  "resultText": "润色后的宣发文案"
}
```

### `import_to_project_canvas` [write | 资源工程与无限画布]
Import an artifact from R1 outfit batches, saved outfits, R2 rendered story videos, R3 scene PSD exports, or catalog items onto a resource project canvas.
- Required args: `projectId`
```json
{
  "projectId": "proj_xxxxxxxx",
  "sourceType": "saved_outfit",
  "outfitId": "default"
}
```

### `publish_project_deliverable` [write | 资源工程与无限画布]
Synthesize and publish a project deliverable (copy, image, video, or html) derived from canvas cards into cache/projects/<projectId>/deliverables/.
- Required args: `projectId`, `kind`, `title`
```json
{
  "projectId": "proj_xxxxxxxx",
  "kind": "html",
  "title": "冬季装扮专题页",
  "content": "<h1>冬季装扮</h1>"
}
```

## 5. Recommended Agent Recipes

### 场景 1：Agent 自动选搭并创建角色卡，返回直达链接
通过远程 MCP 搜索装扮 → 保存为命名角色卡 → 直接返回 /cards/character?id=... 给用户查看。
1. 调用 MCP 工具 `search_resources`（`kind: "equip"`, `dimension: "2d"`, `q: "冬"`）筛选可用部件 ID。
2. 调用 MCP 工具 `create_character_card` 传入 `name`、`gender`、`equipIds`、`facing`、`clipName`。
3. 返回结果中的 `fullCardUrl`（如 `${origin}/cards/character?id=outfit_xxx`）即可直接在浏览器打开预览与交互。
```json
{
  "jsonrpc": "2.0",
  "id": 10,
  "method": "tools/call",
  "params": {
    "name": "create_character_card",
    "arguments": {
      "name": "冬日暖绒少女",
      "description": "Agent 自动搭配的冬季套装",
      "gender": 2,
      "equipIds": [
        10001
      ],
      "facing": "right_front",
      "clipName": "Idle"
    }
  }
}
```

### 场景 2：导出角色卡为透明 MOV / MP4 / PNG 序列帧
既可通过免登录 REST API，也可通过 MCP `export_character_card` 一键导出视频与透明序列帧。
1. 不传参数（仅传 `id` 或空 `{}`）自动按默认配置导出 MP4（720×900, 30fps, 1 周期, 深色棚拍）。
2. 需要后期叠加合成时设 `format: "mov"`（自动 Apple ProRes 4444 + 透明通道）或 `format: "frames"`（透明 PNG 序列帧 + manifest.json ZIP）。
3. 通过返回的 `fullDownloadUrl` 直接下载文件，或传 `outputDir` 同步落盘到允许的本地目录。
```bash
# 1. 免登录 REST 一键导出透明通道 MOV (ProRes 4444)
curl -X POST "https://pikso-assets.vm.tooqing.com/api/v1/cards/characters/default/export" \
  -H "Content-Type: application/json" \
  -d '{"format":"mov","clipName":"Idle","width":720,"height":900,"fps":30,"background":"transparent"}'

# 2. 也可传 {} 使用默认参数导出 MP4
curl -X POST "https://pikso-assets.vm.tooqing.com/api/v1/cards/characters/default/export" \
  -H "Content-Type: application/json" -d '{}'
```

### 场景 3：免登录拉取装扮（含动作）清单与物品清单
适合外部业务系统或无鉴权 Agent 直接拉取目录并拼装卡片展示链接。
1. 拉取装扮与动作清单：`GET /api/v1/cards/outfits?page=1&pageSize=50`（返回 `items`、`savedOutfits` 与全量 `actions`）。
2. 拉取物品/物件清单：`GET /api/v1/cards/objects?cached=parsed&page=1&pageSize=50`。
3. 清单每项自带 `cardUrl`，拼上服务域名即可免登录展示角色卡或物件卡。
```bash
curl "https://pikso-assets.vm.tooqing.com/api/v1/cards/outfits?page=1&pageSize=10"
curl "https://pikso-assets.vm.tooqing.com/api/v1/cards/objects?cached=parsed&page=1&pageSize=10"
```

### 场景 4：远程 MCP（Streamable HTTP）标准接入握手流程
连接 `/mcp` 前需携带 Bearer Token（通过 OAuth 2.1 PKCE 或管理员预置 Token 获取），首包执行 `initialize` 获取 `Mcp-Session-Id`。
1. 通过 `GET /.well-known/oauth-authorization-server` 自动发现 OAuth 2.1 端点（Cursor / Claude 等支持 Remote MCP OAuth 的客户端会自动完成授权）。
2. 向 `POST /mcp` 发送 `initialize` JSON-RPC 请求，从响应头读取 `Mcp-Session-Id`。
3. 后续请求携带 `Authorization: Bearer <token>` 与 `Mcp-Session-Id: <sid>` 调用 `tools/list` 与 `tools/call`。
```json
{
  "mcpServers": {
    "pikso-resource-platform": {
      "type": "streamable-http",
      "url": "https://pikso-assets.vm.tooqing.com/mcp",
      "headers": {
        "Authorization": "Bearer <YOUR_ACCESS_TOKEN>"
      }
    }
  }
}
```
