{
  "openapi": "3.1.0",
  "info": {
    "title": "Sherpa API",
    "version": "1.0.0",
    "summary": "Change, preview, publish and measure websites hosted on Sherpa.",
    "description": "Sherpa's agent interface is a remote MCP server. Agents register an OAuth client, sign the person in with the authorization code flow and PKCE, then send MCP JSON-RPC messages to /mcp. The tools are listed in the MCP server card at https://www.withsherpa.ai/.well-known/mcp/server-card.json.",
    "contact": {
      "name": "Sherpa",
      "email": "hello@withsherpa.ai"
    },
    "termsOfService": "https://www.withsherpa.ai/legal/terms"
  },
  "externalDocs": {
    "description": "Manage a Sherpa website",
    "url": "https://www.withsherpa.ai/.well-known/agent-skills/sherpa-website/SKILL.md"
  },
  "servers": [
    {
      "url": "https://www.withsherpa.ai"
    }
  ],
  "components": {
    "securitySchemes": {
      "sherpaOAuth": {
        "type": "oauth2",
        "description": "OAuth with PKCE (S256) and dynamic client registration. The person signs in to Sherpa and approves access.",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://www.withsherpa.ai/oauth/authorize",
            "tokenUrl": "https://www.withsherpa.ai/api/oauth/token",
            "refreshUrl": "https://www.withsherpa.ai/api/oauth/token",
            "scopes": {}
          }
        }
      }
    },
    "schemas": {
      "OAuthError": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string",
            "description": "OAuth error code, such as invalid_token or invalid_request."
          },
          "error_description": {
            "type": "string"
          }
        }
      },
      "JsonRpcRequest": {
        "type": "object",
        "required": [
          "jsonrpc",
          "method"
        ],
        "properties": {
          "jsonrpc": {
            "const": "2.0"
          },
          "id": {
            "type": [
              "string",
              "integer"
            ]
          },
          "method": {
            "type": "string",
            "description": "An MCP method, such as initialize, tools/list or tools/call."
          },
          "params": {
            "type": "object"
          }
        }
      },
      "JsonRpcResponse": {
        "type": "object",
        "required": [
          "jsonrpc"
        ],
        "properties": {
          "jsonrpc": {
            "const": "2.0"
          },
          "id": {
            "type": [
              "string",
              "integer"
            ]
          },
          "result": {
            "type": "object"
          },
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "integer"
              },
              "message": {
                "type": "string"
              },
              "data": {}
            }
          }
        }
      }
    }
  },
  "paths": {
    "/mcp": {
      "post": {
        "operationId": "sendMcpMessage",
        "summary": "Send an MCP message",
        "description": "Streamable HTTP transport for the Sherpa MCP server. Call tools/list for the available tools, then tools/call.",
        "security": [
          {
            "sherpaOAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/JsonRpcRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The MCP response, as JSON or a server-sent event stream.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/JsonRpcResponse"
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid access token. The WWW-Authenticate header points to the protected resource metadata.",
            "headers": {
              "WWW-Authenticate": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthError"
                }
              }
            }
          }
        }
      }
    },
    "/api/oauth/register": {
      "post": {
        "operationId": "registerOAuthClient",
        "summary": "Register an OAuth client (RFC 7591)",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "redirect_uris"
                ],
                "properties": {
                  "client_name": {
                    "type": "string"
                  },
                  "redirect_uris": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uri"
                    }
                  },
                  "grant_types": {
                    "type": "array",
                    "items": {
                      "enum": [
                        "authorization_code",
                        "refresh_token"
                      ]
                    }
                  },
                  "response_types": {
                    "type": "array",
                    "items": {
                      "const": "code"
                    }
                  },
                  "token_endpoint_auth_method": {
                    "const": "none"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "The registered client.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "client_id"
                  ],
                  "properties": {
                    "client_id": {
                      "type": "string"
                    },
                    "client_name": {
                      "type": "string"
                    },
                    "redirect_uris": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid client metadata.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthError"
                }
              }
            }
          }
        }
      }
    },
    "/api/oauth/token": {
      "post": {
        "operationId": "getOAuthToken",
        "summary": "Exchange an authorization code or refresh token for an access token",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "required": [
                  "grant_type",
                  "client_id"
                ],
                "properties": {
                  "grant_type": {
                    "enum": [
                      "authorization_code",
                      "refresh_token"
                    ]
                  },
                  "client_id": {
                    "type": "string"
                  },
                  "code": {
                    "type": "string"
                  },
                  "redirect_uri": {
                    "type": "string"
                  },
                  "code_verifier": {
                    "type": "string"
                  },
                  "refresh_token": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Tokens.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "access_token",
                    "token_type"
                  ],
                  "properties": {
                    "access_token": {
                      "type": "string"
                    },
                    "token_type": {
                      "const": "Bearer"
                    },
                    "expires_in": {
                      "type": "integer"
                    },
                    "refresh_token": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid grant or request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OAuthError"
                }
              }
            }
          }
        }
      }
    }
  }
}