{
  "openapi": "3.1.0",
  "info": {
    "title": "ChatPRD Model Context Protocol API",
    "version": "1.0.0",
    "description": "Authenticated Streamable HTTP MCP transport for accessing ChatPRD product documents, projects, templates, and product-management context.",
    "contact": {
      "name": "ChatPRD Support",
      "email": "support@chatprd.ai",
      "url": "https://www.chatprd.ai/docs"
    }
  },
  "servers": [
    {
      "url": "https://www.chatprd.ai",
      "description": "Public ChatPRD discovery and documentation API"
    }
  ],
  "externalDocs": {
    "description": "ChatPRD MCP integration and supported tools",
    "url": "https://www.chatprd.ai/product/mcp"
  },
  "tags": [
    {
      "name": "Model Context Protocol",
      "description": "Authenticated product-document tools over Streamable HTTP MCP."
    }
  ],
  "paths": {
    "/api/agent": {
      "get": {
        "operationId": "getAgentIntegrationDetails",
        "summary": "Discover ChatPRD agent and MCP integration details",
        "description": "Retrieve public, read-only ChatPRD product information, documentation links, MCP endpoint details, and OAuth discovery metadata.",
        "tags": ["Model Context Protocol"],
        "responses": {
          "200": {
            "description": "Public ChatPRD agent integration and authentication discovery details.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AgentIntegration" }
              }
            }
          },
          "405": {
            "description": "The discovery endpoint accepts only GET requests.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    },
    "/mcp": {
      "post": {
        "operationId": "sendMcpMessage",
        "summary": "Send an authenticated MCP JSON-RPC message",
        "description": "Initialize an MCP session, discover available ChatPRD tools, or invoke a tool using the authenticated user's existing workspace permissions.",
        "tags": ["Model Context Protocol"],
        "servers": [
          {
            "url": "https://app.chatprd.ai",
            "description": "Authenticated ChatPRD MCP server"
          }
        ],
        "security": [{ "oauth2": ["profile", "email"] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/JsonRpcRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "MCP JSON-RPC response or server-sent event stream.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/JsonRpcResponse" }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "Streamed MCP response events."
                }
              }
            }
          },
          "400": {
            "description": "The JSON-RPC request is invalid.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": {
            "description": "OAuth authorization is required; inspect the WWW-Authenticate resource_metadata challenge.",
            "headers": {
              "WWW-Authenticate": {
                "description": "Bearer challenge referencing OAuth protected-resource metadata.",
                "schema": { "type": "string" }
              }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "403": {
            "description": "The authenticated account lacks permission for the requested resource.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "429": {
            "description": "The request was rate limited; retry after the indicated interval.",
            "headers": {
              "Retry-After": {
                "description": "Seconds to wait before retrying.",
                "schema": { "type": "integer", "minimum": 0 }
              }
            },
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "oauth2": {
        "type": "oauth2",
        "description": "OAuth authorization for the authenticated ChatPRD account; protected-resource metadata is available at https://app.chatprd.ai/.well-known/oauth-protected-resource/mcp.",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://clerk.chatprd.ai/oauth/authorize",
            "tokenUrl": "https://clerk.chatprd.ai/oauth/token",
            "scopes": {
              "profile": "Read the authenticated ChatPRD account profile.",
              "email": "Read the authenticated ChatPRD account email address."
            }
          }
        }
      }
    },
    "schemas": {
      "AgentIntegration": {
        "type": "object",
        "required": [
          "name",
          "description",
          "website",
          "documentation",
          "agentInstructions",
          "openapi",
          "mcp"
        ],
        "properties": {
          "name": { "type": "string" },
          "description": { "type": "string" },
          "website": { "type": "string", "format": "uri" },
          "documentation": { "type": "string", "format": "uri" },
          "agentInstructions": { "type": "string", "format": "uri" },
          "openapi": { "type": "string", "format": "uri" },
          "mcp": {
            "type": "object",
            "required": [
              "endpoint",
              "transport",
              "documentation",
              "serverManifest",
              "authentication"
            ],
            "properties": {
              "endpoint": { "type": "string", "format": "uri" },
              "transport": { "type": "string", "enum": ["streamable-http"] },
              "documentation": { "type": "string", "format": "uri" },
              "serverManifest": { "type": "string", "format": "uri" },
              "authentication": {
                "type": "object",
                "required": ["type", "protectedResourceMetadata"],
                "properties": {
                  "type": { "type": "string", "enum": ["oauth2"] },
                  "protectedResourceMetadata": {
                    "type": "string",
                    "format": "uri"
                  }
                }
              }
            }
          }
        }
      },
      "JsonRpcRequest": {
        "type": "object",
        "required": ["jsonrpc", "method"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"] },
          "id": { "oneOf": [{ "type": "string" }, { "type": "integer" }] },
          "method": {
            "type": "string",
            "description": "MCP method such as initialize, tools/list, or tools/call."
          },
          "params": {
            "type": "object",
            "description": "Method-specific MCP parameters.",
            "additionalProperties": true
          }
        }
      },
      "JsonRpcResponse": {
        "type": "object",
        "required": ["jsonrpc", "id"],
        "properties": {
          "jsonrpc": { "type": "string", "enum": ["2.0"] },
          "id": {
            "oneOf": [
              { "type": "string" },
              { "type": "integer" },
              { "type": "null" }
            ]
          },
          "result": { "type": "object", "additionalProperties": true },
          "error": { "$ref": "#/components/schemas/ErrorResponse" }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": {
            "type": "string",
            "description": "Machine-readable error code."
          },
          "message": {
            "type": "string",
            "description": "Human-readable error explanation."
          },
          "resolution": {
            "type": "string",
            "description": "Suggested next action for recovering from the error."
          },
          "error_description": {
            "type": "string",
            "description": "Human-readable error explanation and recovery guidance."
          }
        }
      }
    }
  }
}
