# RoleTrail MCP API — Machine-readable Integration Guide > Static API documentation for AI agents and non-JavaScript scrapers. Use this file instead of scraping RoleTrail's React-rendered `/docs` pages. Last updated: 2026-10-17 ## Base endpoint RoleTrail exposes a Streamable HTTP MCP server at: ```text https://api.roletrail.com/functions/v1/mcp ``` All requests are JSON-RPC 2.0 over HTTPS. ## Authentication Two methods are supported: OAuth 2.0 (recommended for LLM connectors) and Personal Access Tokens (for scripts and automation). ### OAuth 2.0 (LLM connectors: ChatGPT, Claude, MCP clients) - Issuer: `https://oauth.roletrail.com` - Discovery: `https://oauth.roletrail.com/.well-known/openid-configuration` (authorization_endpoint, token_endpoint, registration_endpoint, S256 PKCE, RFC 8707 resource indicators) - Protected-resource metadata: `https://api.roletrail.com/functions/v1/mcp/oauth-protected-resource` (also linked from the 401 WWW-Authenticate header) - Dynamic Client Registration: `POST https://oauth.roletrail.com/oauth/register` — public PKCE clients only; redirects allowlisted to known connector callbacks and localhost. - Authorize: `GET {issuer}/oauth/auth?response_type=code&client_id=...&redirect_uri=...&code_challenge=...&code_challenge_method=S256&resource=https://api.roletrail.com/functions/v1/mcp&scope=openid offline_access ` - At consent the user logs in and selects ONE workspace; the token is bound to it. Other workspaces return forbidden/not_found. - Token exchange: `POST {issuer}/oauth/token` (grant_type=authorization_code + code_verifier). Access tokens are opaque, TTL 300s. Include `offline_access` + consent for a rotating refresh_token (grant_type=refresh_token). - OAuth-grantable scopes: read:profile, read:tasks, read:projects, read:decisions, write:tasks, write:reminders. - Staging pair for testing: issuer `https://roletrail-oauth-staging.vercel.app`, MCP `https://vugsrvzgkwfmnchtltom.supabase.co/functions/v1/mcp` — never mix staging and prod. Send the OAuth access token the same way: ```http Authorization: Bearer ``` ### Personal Access Token Create a Personal Access Token in RoleTrail: 1. Open RoleTrail. 2. Go to Settings -> Developer -> Access Tokens. 3. Click New Token. 4. Explicitly choose a personal or team workspace and only the scopes your agent needs. 5. Copy the `rt_pat_...` token immediately. It is shown only once. Send the token on every request: ```http Authorization: Bearer rt_pat_YOUR_TOKEN_HERE Content-Type: application/json Accept: application/json, text/event-stream ``` The `Accept: application/json, text/event-stream` header is required by MCP Streamable HTTP clients and servers. PAT tokens support the full scope set below. Ordinary Supabase login JWTs are rejected — only OAuth issuer tokens and PATs are accepted. ## Scopes | Scope | Purpose | |---|---| | `read:profile` | Confirm token identity and workspace with `whoami` | | `read:tasks` | List, search, and read tasks | | `write:tasks` | Create tasks, update task status, complete tasks, resolve reviews, create unblock tasks, attach deliverables | | `read:decisions` | List and read decisions | | `write:decisions` | Create decisions (no update tool — decisions are append-only) | | `read:projects` | List, read, and search projects | | `read:issues` | List and read issues (team bug tracker) | | `write:issues` | Create and update issues | | `write:reminders` | Create, list, and cancel task reminders | | `write:feedback` | Submit feedback via a feedback link token | | `write:friction` | Log friction notes | | `read:webhooks` | List outbound webhook subscriptions (workspace admin) | | `write:webhooks` | Create outbound webhook subscriptions (workspace admin) | ## Available tools ### Discovery and search - `whoami` — returns the token's user, workspace, linked agent profile, and granted scopes. Requires `read:profile`. - `search` — keyword search across tasks, decisions, and projects. Requires at least one matching read scope; only resource families with their own read scope are returned. ### Tasks - `list_tasks` — list tasks in the token's scope. Requires `read:tasks`. - `get_task` — fetch a task by ID. Requires `read:tasks`. - `create_task` — create a task (`title` required; optional `executor_id`, `assignee_id`, `reviewer_id`, `project_id`, `success_criteria`, `due_date`, `priority`). Requires `write:tasks`. Team tokens must supply a project to retain workspace ownership. Supports `dry_run` and `idempotency_key` / `_meta.idempotency_key`. - `update_task_status` — move a task's status through the canonical transition path. Requires `write:tasks`. Supports `idempotency_key`; optional `expected_review_requested_at` (optimistic lock) and `feedback` (required when sending pending_review work back). - `complete_task` — complete a task with optional `completion_notes` (attached as proof-of-work deliverable). Requires `write:tasks`. Supports `idempotency_key`. - `resolve_task_review` — act on a `pending_review` task as its designated reviewer: `action: "accept" | "request_changes"` (feedback required for request_changes). Requires `write:tasks`. Supports `idempotency_key`. - `create_unblock_task` — create the unblock task for an open blocker; one task per blocker, retries replay `{ task_id, replayed: true }`. Requires `write:tasks`. - `attach_deliverable` — attach an agent-produced artifact (canonical `deliverable`/`deliverable_links` + `ai_*` provenance) and optionally mark it complete. Requires `write:tasks`. Supports `idempotency_key`. ### Decisions - `list_decisions` — list decisions. Requires `read:decisions`. - `get_decision` — fetch a decision by ID. Requires `read:decisions`. - `create_decision` — create a decision. Requires `write:decisions`. Supports `dry_run` and `idempotency_key`. - *No `update_decision` tool exists — decisions are append-only over MCP.* ### Projects - `list_projects` — list projects. Requires `read:projects`. - `get_project` — fetch a project by ID (includes linked rocks). Requires `read:projects`. - `create_project` — create a project (`name` required; `description`, `priority`, `target_date` optional). Requires `write:projects`. Supports `dry_run` and `idempotency_key`. ### Issues (team bug tracker) - `list_issues` — list issues (filters: `status`, `project_id`, `since`, `limit`). Requires `read:issues`. - `get_issue` — fetch an issue plus linked feedback. Requires `read:issues`. - `create_issue` — create an issue (`title` required; `priority` 0–3). Requires `write:issues`. Supports `dry_run` and `idempotency_key`. - `update_issue` — update status, priority, owner, root_cause, resolution. Requires `write:issues`. Supports `idempotency_key`. ### Reminders - `create_reminder` — schedule a reminder on a task (`task_id`, `remind_at`, `message`). Requires `write:reminders`. Supports `dry_run` and `idempotency_key`. A server-side dispatcher delivers it — it fires even when the client is offline. Retries with the same key replay the stored result. - `list_reminders` — list reminders in the token's scope. Requires `read:tasks` or `write:reminders`. - `cancel_reminder` — cancel a scheduled reminder. Requires `write:reminders`. Supports `idempotency_key`. ### Public feedback - `submit_feedback` — submit a public feedback item via a feedback-link `token`; requires `write:feedback`, a link belonging to the token workspace, and an idempotency key. ### Friction notes - `log_friction` — log an unstructured friction note (`text` required). Requires `write:friction`. Supports `dry_run` and `idempotency_key`. ### Outbound webhooks (admin-only) - `list_webhook_subscriptions` — list webhook subscriptions. Requires `read:webhooks` + workspace admin. - `create_webhook_subscription` — create a webhook subscription; returns the generated `signing_secret` once. Requires `write:webhooks` + workspace admin. Supports `dry_run` and `idempotency_key`. ## JSON-RPC request shape ```json { "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "tool_name", "arguments": {} } } ``` ## List available tools ```bash curl -X POST https://api.roletrail.com/functions/v1/mcp \ -H "Authorization: Bearer rt_pat_YOUR_TOKEN_HERE" \ -H "Content-Type: application/json" \ -H "Accept: application/json, text/event-stream" \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' ``` ## Example: whoami ```json { "jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": { "name": "whoami", "arguments": {} } } ``` ## Example: list tasks ```json { "jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": { "name": "list_tasks", "arguments": { "status": "not_started", "limit": 10 } } } ``` ## Example: attach a deliverable safely Use `_meta.idempotency_key` for every write operation. Generate one UUID per logical operation and reuse it for retries after network failures. ```json { "jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": { "name": "attach_deliverable", "arguments": { "task_id": "00000000-0000-0000-0000-000000000000", "deliverable_type": "markdown", "content": "# Research summary\n\n- Finding 1\n- Finding 2", "summary": "Completed research summary", "mark_complete": true, "idempotency_key": "4e3f5e7a-0d9b-4541-bb12-7d9dfca6ce42" } } } ``` ## Idempotency and safe retries Write tools require `idempotency_key` (except dry runs) as a top-level argument or as `_meta.idempotency_key` inside `params.arguments`. Behavior: - Same token + same idempotency key + same payload: RoleTrail replays the cached original response. - Same token + same idempotency key + different payload: RoleTrail returns `idempotency_key_mismatch`. - No key: `idempotency_key_required`; no write occurs. - Pending or uncertain outcome: no second execution. Reconcile before taking further action; never change the key to bypass this guard. - Completed error results replay too. Reservations do not expire automatically. Recommended retry policy: 1. For write tools, generate a UUID before the first attempt. 2. Send it as top-level `idempotency_key` (or `_meta.idempotency_key`). 3. If the network fails, retry the exact same JSON payload with the same key. 4. Retry transient network failures and HTTP 5xx with exponential backoff, maximum 3 attempts. 5. Honor `Retry-After` on HTTP 429. ## Review rules for completing work Completion is not unconditional — the same contract the UI enforces applies: - A task needs proof of work to complete: a `deliverable` body or `deliverable_links` URL list (`attach_deliverable` writes these). Completing without proof returns `validation_failed`. - `done` on a task with a named reviewer, or delegated work closed by its doer, returns `outcome: "submitted"` and moves the task to `pending_review` — it does not close. - The designated reviewer (named reviewer, else the owner) accepts via `resolve_task_review` (`action: "accept"`) or returns it (`action: "request_changes"` + `feedback`) → status `in_progress`. - Pass `expected_review_requested_at` as an optimistic lock; a stale review round returns `outcome: "stale"`. Transition tools return `{ task_id, status, outcome }` with `outcome` in `transitioned | submitted | accepted | changes_requested | reopened | already_done | already_pending | requires_submission | stale | replayed`. ## Dry run Create-type tools support `dry_run: true`. This returns what would be written without committing changes. ```json { "jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": { "name": "create_task", "arguments": { "title": "Draft launch checklist", "priority": "high", "dry_run": true } } } ``` ## Response shape Successful MCP responses contain a JSON string in `result.content[0].text`: ```json { "jsonrpc": "2.0", "id": 1, "result": { "content": [ { "type": "text", "text": "{\"ok\":true}" } ] } } ``` Parse `result.content[0].text` as JSON to get the actual tool output. ## Error handling There are two error layers: 1. Transport-level errors: non-200 HTTP status or top-level JSON-RPC `error`. 2. Tool-level errors: HTTP 200 with a parsed payload containing `{ "error": "..." }`. Common transport statuses: | HTTP | Meaning | Action | |---|---|---| | 400 | Invalid JSON-RPC request | Fix request body | | 401 | Missing, invalid, expired, or revoked token | Re-authorize / create a new PAT | | 406 | Missing required MCP `Accept` header | Add `Accept: application/json, text/event-stream` | | 422 | Invalid tool arguments | Fix arguments | | 429 | Rate limit exceeded | Honor `Retry-After` | | 5xx | Server error | Retry with exponential backoff | Common tool-level errors: | Error | Meaning | |---|---| | `not_found` | Resource does not exist or is outside the token workspace | | `forbidden` | Token cannot access the resource | | `missing_scope` | Token/grant lacks the required scope | | `validation_failed` | Tool arguments failed business validation | | `idempotency_key_mismatch` | Same key was reused with a different payload | ## Minimal OpenClaw setup If OpenClaw asks for API docs, provide these URLs: ```text https://roletrail.com/openclaw.txt https://roletrail.com/llms-mcp.txt https://roletrail.com/llms.txt ``` If OpenClaw asks for the MCP endpoint, provide: ```text https://api.roletrail.com/functions/v1/mcp ``` If OpenClaw asks for authentication, provide: ```text Authorization: Bearer rt_pat_YOUR_TOKEN_HERE ```