# MCP Tools
> ツール名は「Rails APIの意図が分かる」ように分けています。
## `user_start`
ユーザーに紐づく token を使って、新しい game を開始します(開始のたびに新しい `public_id` が発行される)。
Input:
```json
{ "user_slug": "u_abcd1234" }
```
Output:
```json
{ "public_id": "g_xxxxx", "game_url": "/games/g_xxxxx" }
```
## `game_state`
公開ゲームの state を取得します(token不要)。
Input:
```json
{ "public_id": "g_xxxxx" }
```
Output:
```json
{
"game": {
"status": "playing",
"updated_at": "2026-01-25T03:12:34Z",
"board": [["#","#",...], ...]
}
}
```
## `game_open`
Input:
```json
{ "public_id": "g_xxxxx", "x": 3, "y": 4 }
```
## `game_flag`(トグル)
Input:
```json
{ "public_id": "g_xxxxx", "x": 3, "y": 4 }
```
## `game_chord`
Input:
```json
{ "public_id": "g_xxxxx", "x": 3, "y": 4 }
```
## `game_end`
Input:
```json
{ "public_id": "g_xxxxx" }
```
## (任意)`user_games`
公開の games 一覧取得(token不要)。
Input:
```json
{ "user_slug": "u_abcd1234" }
```
Output:
```json
{ "games": [ ... ] }
```
---
## Error Handling
Rails 側は `{ "error": "message" }` を返します。
MCP server はそれを tool error に変換します。
- 401: Unauthorized (missing/invalid token)
- 404: Not found
- 422: Unprocessable (invalid state/coords/etc)
- その他: Request failed (status=...)
---
## Logging
- stdout: MCP プロトコル専用(ログ出力禁止)
- stderr: ログ出力OK
環境変数 `LOG_LEVEL`(例: `debug|info|warn|error`)をサポートするのを推奨。