{
  "openapi": "3.1.0",
  "info": {
    "title": "Marqly Developer & MCP OAuth API",
    "version": "1.0.0",
    "description": "Authentication, discovery, and Model Context Protocol (MCP) specification for Marqly. Connects bookmarks, 6-color web highlights, YouTube transcripts, boards, tags, and ChatVault AI conversations over OAuth 2.1 with PKCE (S256).\n\n## Versioning & Deprecation Policy\nMarqly versions its API via URL path prefixes (`/v1/`) and the optional `X-API-Version` header (date-stamped, e.g. `2026-12-01`). Breaking changes are introduced only in a new major version. Deprecated endpoints emit standard `Deprecation` and `Sunset` HTTP response headers with at least 12 months advance notice.\n\n## Pagination\nList endpoints use cursor-based pagination with `cursor` and `limit` query parameters and return `{ items, next_cursor, has_more }`.\n\n## Error Model\nAll error responses return structured JSON conforming to RFC 9457 Problem Details (`application/problem+json` / `application/json`) with machine-readable `code`, `status`, `title`, `detail`, `retryable`, and `request_id` fields.",
    "contact": {
      "name": "Marqly Support",
      "url": "https://www.marqly.com/contact",
      "email": "support@marqly.com"
    },
    "termsOfService": "https://www.marqly.com/terms",
    "x-versioning-policy": {
      "strategy": "path-and-header",
      "currentVersion": "v1",
      "headerName": "X-API-Version",
      "deprecationNoticeMonths": 12,
      "headers": ["Deprecation", "Sunset"]
    }
  },
  "servers": [
    {
      "url": "https://mcp.marqly.com",
      "description": "Marqly Streamable HTTP MCP Server"
    },
    {
      "url": "https://api.marqly.com/v1",
      "description": "Marqly REST API (v1)"
    },
    {
      "url": "https://api.marqly.com",
      "description": "Marqly OAuth 2.1 Authorization Server"
    }
  ],
  "externalDocs": {
    "description": "Marqly Developer Portal & MCP Documentation",
    "url": "https://www.marqly.com/developers"
  },
  "security": [
    {
      "oauth2": [
        "bookmarks:read",
        "boards:read",
        "tags:read",
        "highlights:read",
        "account:read"
      ]
    }
  ],
  "components": {
    "parameters": {
      "ApiVersionHeader": {
        "name": "X-API-Version",
        "in": "header",
        "required": false,
        "description": "Optional date-stamped API version pin (e.g. 2026-12-01). Defaults to the latest stable v1 release.",
        "schema": {
          "type": "string",
          "default": "2026-12-01",
          "example": "2026-12-01"
        }
      },
      "CursorParam": {
        "name": "cursor",
        "in": "query",
        "required": false,
        "description": "Opaque cursor returned by the previous page's next_cursor field.",
        "schema": {
          "type": "string"
        }
      },
      "LimitParam": {
        "name": "limit",
        "in": "query",
        "required": false,
        "description": "Maximum number of items to return per page (1–100, default 20).",
        "schema": {
          "type": "integer",
          "minimum": 1,
          "maximum": 100,
          "default": 20
        }
      }
    },
    "schemas": {
      "JsonRpcRequest": {
        "type": "object",
        "required": ["jsonrpc", "method"],
        "properties": {
          "jsonrpc": { "type": "string", "const": "2.0" },
          "id": { "type": ["string", "integer"] },
          "method": { "type": "string", "example": "tools/list" },
          "params": { "type": "object", "additionalProperties": true }
        }
      },
      "JsonRpcResponse": {
        "type": "object",
        "required": ["jsonrpc", "id"],
        "properties": {
          "jsonrpc": { "type": "string", "const": "2.0" },
          "id": { "type": ["string", "integer", "null"] },
          "result": { "type": "object", "additionalProperties": true },
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "integer" },
              "message": { "type": "string" },
              "data": { "type": "object", "additionalProperties": true }
            }
          }
        }
      },
      "ProtectedResourceMetadata": {
        "type": "object",
        "required": ["resource", "authorization_servers", "scopes_supported"],
        "properties": {
          "resource": { "type": "string", "format": "uri" },
          "authorization_servers": {
            "type": "array",
            "items": { "type": "string", "format": "uri" }
          },
          "scopes_supported": {
            "type": "array",
            "items": { "type": "string" }
          },
          "bearer_methods_supported": {
            "type": "array",
            "items": { "type": "string" }
          },
          "resource_name": { "type": "string" },
          "resource_documentation": { "type": "string", "format": "uri" }
        }
      },
      "AuthorizationServerMetadata": {
        "type": "object",
        "required": ["issuer", "authorization_endpoint", "token_endpoint"],
        "properties": {
          "issuer": { "type": "string", "format": "uri" },
          "authorization_endpoint": { "type": "string", "format": "uri" },
          "token_endpoint": { "type": "string", "format": "uri" },
          "registration_endpoint": { "type": "string", "format": "uri" },
          "revocation_endpoint": { "type": "string", "format": "uri" },
          "response_types_supported": { "type": "array", "items": { "type": "string" } },
          "grant_types_supported": { "type": "array", "items": { "type": "string" } },
          "code_challenge_methods_supported": { "type": "array", "items": { "type": "string" } },
          "scopes_supported": { "type": "array", "items": { "type": "string" } }
        }
      },
      "Bookmark": {
        "type": "object",
        "required": ["id", "url", "title", "created_at"],
        "properties": {
          "id": { "type": "string", "example": "bm_01JFQ7W8Z9X2Y3" },
          "url": { "type": "string", "format": "uri" },
          "title": { "type": "string" },
          "summary": { "type": ["string", "null"] },
          "board_id": { "type": ["string", "null"] },
          "tags": { "type": "array", "items": { "type": "string" } },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "BookmarkListResponse": {
        "type": "object",
        "description": "Cursor-paginated list of saved bookmarks.",
        "required": ["items", "has_more", "next_cursor"],
        "properties": {
          "items": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Bookmark" }
          },
          "has_more": { "type": "boolean", "example": true },
          "next_cursor": {
            "type": ["string", "null"],
            "example": "cur_01JFQ7W8Z9X2Y3"
          }
        }
      },
      "ProblemDetails": {
        "type": "object",
        "description": "RFC 9457 Problem Details structured error response.",
        "required": ["type", "title", "status", "code", "detail"],
        "properties": {
          "type": {
            "type": "string",
            "format": "uri",
            "example": "https://www.marqly.com/developers#errors"
          },
          "title": {
            "type": "string",
            "example": "Insufficient Scope"
          },
          "status": {
            "type": "integer",
            "example": 403
          },
          "code": {
            "type": "string",
            "enum": [
              "invalid_request",
              "unauthorized",
              "insufficient_scope",
              "write_disabled",
              "not_found",
              "rate_limited",
              "internal_error"
            ],
            "example": "insufficient_scope"
          },
          "detail": {
            "type": "string",
            "example": "The access token does not grant the bookmarks:write scope."
          },
          "retryable": {
            "type": "boolean",
            "example": false
          },
          "request_id": {
            "type": "string",
            "example": "req_01JFQ7W8Z9X2Y3"
          }
        }
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Malformed request or invalid parameters.",
        "content": {
          "application/problem+json": {
            "schema": { "$ref": "#/components/schemas/ProblemDetails" }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing, invalid, or expired Bearer token. Includes WWW-Authenticate header with RFC 9728 resource_metadata URL.",
        "headers": {
          "WWW-Authenticate": {
            "description": "Bearer challenge with RFC 9728 resource_metadata URI.",
            "schema": { "type": "string" }
          }
        },
        "content": {
          "application/problem+json": {
            "schema": { "$ref": "#/components/schemas/ProblemDetails" }
          }
        }
      },
      "Forbidden": {
        "description": "Insufficient OAuth scope or per-app write toggle is disabled.",
        "content": {
          "application/problem+json": {
            "schema": { "$ref": "#/components/schemas/ProblemDetails" }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limit exceeded. Retry after the reset window.",
        "headers": {
          "Retry-After": {
            "description": "Seconds until the client should retry.",
            "schema": { "type": "integer" }
          }
        },
        "content": {
          "application/problem+json": {
            "schema": { "$ref": "#/components/schemas/ProblemDetails" }
          }
        }
      },
      "InternalError": {
        "description": "Unexpected server error (retryable with exponential backoff).",
        "content": {
          "application/problem+json": {
            "schema": { "$ref": "#/components/schemas/ProblemDetails" }
          }
        }
      }
    },
    "securitySchemes": {
      "oauth2": {
        "type": "oauth2",
        "description": "OAuth 2.1 Authorization Code flow with PKCE (S256) and Dynamic Client Registration (RFC 7591). Protected Resource Metadata (RFC 9728) is published at https://mcp.marqly.com/.well-known/oauth-protected-resource/ai/mcp.",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://api.marqly.com/oauth/authorize",
            "tokenUrl": "https://api.marqly.com/oauth/token",
            "refreshUrl": "https://api.marqly.com/oauth/token",
            "scopes": {
              "bookmarks:read": "Search and read saved bookmarks, metadata, summaries, and full content.",
              "bookmarks:write": "Create, update, tag, move, and soft-delete bookmarks (requires per-app write toggle).",
              "boards:read": "List and inspect boards and board hierarchy.",
              "boards:write": "Create, update, merge, and soft-delete boards (requires per-app write toggle).",
              "tags:read": "List and inspect tags across the library.",
              "tags:write": "Rename, merge, and delete tags (requires per-app write toggle).",
              "highlights:read": "Search and read saved webpage highlights and notes.",
              "highlights:write": "Create, update, and delete webpage highlights (requires per-app write toggle).",
              "account:read": "Read authenticated user profile and plan status.",
              "bookmarks": "Combined read and write access to bookmarks.",
              "boards": "Combined read and write access to boards.",
              "tags": "Combined read and write access to tags.",
              "conversations": "Search and read saved ChatVault AI conversations."
            }
          }
        }
      },
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "OAuth 2.1 Bearer access token obtained from https://api.marqly.com/oauth/token."
      }
    }
  },
  "paths": {
    "/ai/mcp": {
      "post": {
        "operationId": "mcpJsonRpc",
        "summary": "Send a Model Context Protocol (MCP) JSON-RPC 2.0 request",
        "description": "Streamable HTTP MCP endpoint supporting 22 tools across bookmarks, boards, tags, highlights, account info, and help search. Read-only by default; write operations require explicit write scopes and per-app write toggle.",
        "parameters": [
          { "$ref": "#/components/parameters/ApiVersionHeader" }
        ],
        "security": [
          {
            "oauth2": [
              "bookmarks:read",
              "boards:read",
              "tags:read",
              "highlights:read",
              "account:read"
            ]
          },
          {
            "oauth2": [
              "bookmarks:read",
              "bookmarks:write",
              "boards:read",
              "boards:write",
              "tags:read",
              "tags:write",
              "highlights:read",
              "highlights:write",
              "account:read",
              "conversations"
            ]
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/JsonRpcRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC 2.0 result payload.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/JsonRpcResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "500": { "$ref": "#/components/responses/InternalError" }
        }
      }
    },
    "/v1/bookmarks": {
      "get": {
        "operationId": "listBookmarks",
        "summary": "List saved bookmarks with cursor-based pagination",
        "description": "Returns a cursor-paginated page of bookmarks for the authenticated user. Use next_cursor to fetch subsequent pages.",
        "parameters": [
          { "$ref": "#/components/parameters/ApiVersionHeader" },
          { "$ref": "#/components/parameters/CursorParam" },
          { "$ref": "#/components/parameters/LimitParam" },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Optional search query.",
            "schema": { "type": "string" }
          }
        ],
        "security": [
          { "oauth2": ["bookmarks:read"] }
        ],
        "responses": {
          "200": {
            "description": "A cursor-paginated list of bookmarks.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BookmarkListResponse" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/Forbidden" },
          "429": { "$ref": "#/components/responses/RateLimited" },
          "500": { "$ref": "#/components/responses/InternalError" }
        }
      }
    },
    "/.well-known/oauth-protected-resource/ai/mcp": {
      "get": {
        "operationId": "getProtectedResourceMetadata",
        "summary": "OAuth 2.0 Protected Resource Metadata (RFC 9728)",
        "security": [],
        "responses": {
          "200": {
            "description": "Protected resource metadata advertising authorization_servers and scopes_supported.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ProtectedResourceMetadata" }
              }
            }
          },
          "500": { "$ref": "#/components/responses/InternalError" }
        }
      }
    },
    "/.well-known/oauth-authorization-server": {
      "get": {
        "operationId": "getAuthorizationServerMetadata",
        "summary": "OAuth 2.0 Authorization Server Metadata (RFC 8414)",
        "security": [],
        "responses": {
          "200": {
            "description": "Authorization server metadata including PKCE S256 and dynamic client registration endpoints.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AuthorizationServerMetadata" }
              }
            }
          },
          "500": { "$ref": "#/components/responses/InternalError" }
        }
      }
    }
  }
}
