{
  "openapi": "3.1.0",
  "info": {
    "title": "GetRestaurantLeads Public API & Hosted MCP Server",
    "version": "1.0.1",
    "summary": "Public read-only REST & Streamable HTTP MCP API for US pre-opening restaurant, bar, and cafe leads across 22 jurisdictions.",
    "description": "Strictly B2B commercial hospitality market intelligence sourced from 46 official US state and municipal government registries across 22 jurisdictions (TX, NY, FL, CA, IL, WA, OR, MA, PA, DC, CT, CO, NC, MD, OH, MO, VA, TN, KY, MI, DE, AZ). Public endpoints return masked lead previews (never paid subscriber PII). Full unmasked 18-column CRM CSV exports require a Stripe subscription at https://getrestaurantleads.com/#pricing. Non-FCRA.",
    "contact": {
      "name": "GetRestaurantLeads Support",
      "email": "hello@getrestaurantleads.com",
      "url": "https://getrestaurantleads.com/contact"
    },
    "license": {
      "name": "GetRestaurantLeads Terms of Service",
      "url": "https://getrestaurantleads.com/terms"
    }
  },
  "servers": [
    {
      "url": "https://getrestaurantleads.com",
      "description": "Production Cloudflare Workers endpoint"
    }
  ],
  "tags": [
    {
      "name": "Public Data",
      "description": "Read-only health, state statistics, and masked lead previews."
    },
    {
      "name": "MCP",
      "description": "Hosted anonymous read-only Streamable HTTP Model Context Protocol server."
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "tags": [
          "Public Data"
        ],
        "operationId": "getHealth",
        "summary": "Service health and indexed database summary",
        "description": "Returns operational status, indexed state count, and total normalized public filings.",
        "responses": {
          "200": {
            "description": "Healthy service metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "ok",
                    "states_indexed",
                    "total_leads"
                  ],
                  "properties": {
                    "ok": {
                      "type": "boolean"
                    },
                    "states_indexed": {
                      "type": "integer"
                    },
                    "total_leads": {
                      "type": "integer"
                    },
                    "stripe_configured": {
                      "type": "boolean"
                    },
                    "email_configured": {
                      "type": "boolean"
                    },
                    "email_provider": {
                      "type": "string",
                      "enum": [
                        "resend",
                        "brevo",
                        "none"
                      ]
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/stats": {
      "get": {
        "tags": [
          "Public Data"
        ],
        "operationId": "getStats",
        "summary": "Live per-state indexed filings and latest ingest timestamp",
        "description": "Returns the latest successful ingest UTC timestamp and per-state total and pre-opening counts.",
        "responses": {
          "200": {
            "description": "State-level filing statistics",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "latest_ingest_at",
                    "states"
                  ],
                  "properties": {
                    "latest_ingest_at": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "format": "date-time"
                    },
                    "states": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/StateStats"
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/leads": {
      "get": {
        "tags": [
          "Public Data"
        ],
        "operationId": "listPublicLeads",
        "summary": "Search masked public preview leads",
        "description": "Returns masked public preview records filtered by state, venue_type, and free-text query q. Street house numbers are masked and paid contact fields (owner name, legal entity, mailing address, phone) are redacted into boolean availability flags.",
        "parameters": [
          {
            "name": "state",
            "in": "query",
            "required": false,
            "description": "2-letter US state/DC code (TX, NY, FL, CA, IL, WA, OR, MA, PA, DC, CT, CO, NC, MD, OH, MO, VA, TN, KY, MI, DE, AZ).",
            "schema": {
              "type": "string",
              "enum": [
                "TX",
                "NY",
                "FL",
                "CA",
                "IL",
                "WA",
                "OR",
                "MA",
                "PA",
                "DC",
                "CT",
                "CO",
                "NC",
                "MD",
                "OH",
                "MO",
                "VA",
                "TN",
                "KY",
                "MI",
                "DE",
                "AZ"
              ]
            }
          },
          {
            "name": "venue_type",
            "in": "query",
            "required": false,
            "description": "Normalized venue category filter.",
            "schema": {
              "type": "string",
              "enum": [
                "full_service",
                "limited_service",
                "bar",
                "cafe_bakery",
                "food_other"
              ]
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Free-text FTS5 search query (max 64 chars; punctuation-only queries short-circuit to empty results).",
            "schema": {
              "type": "string",
              "maxLength": 64
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "description": "Maximum preview rows to return (clamped 1..50, default 20).",
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 50,
              "default": 20
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Masked public lead previews",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "count",
                    "leads"
                  ],
                  "properties": {
                    "count": {
                      "type": "integer"
                    },
                    "leads": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/PublicLeadView"
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/mcp": {
      "get": {
        "tags": [
          "MCP"
        ],
        "operationId": "discoverMcpServer",
        "summary": "Discover hosted Streamable HTTP MCP server capabilities",
        "description": "Returns endpoint metadata, protocol version, tool directory, and rate limits for the hosted anonymous read-only MCP server.",
        "responses": {
          "200": {
            "description": "MCP server discovery metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "name",
                    "version",
                    "protocolVersion",
                    "transport",
                    "endpoint",
                    "tools"
                  ],
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "title": {
                      "type": "string"
                    },
                    "version": {
                      "type": "string"
                    },
                    "protocolVersion": {
                      "type": "string"
                    },
                    "transport": {
                      "type": "string",
                      "enum": [
                        "streamable-http"
                      ]
                    },
                    "auth": {
                      "type": "string"
                    },
                    "endpoint": {
                      "type": "string",
                      "format": "uri"
                    },
                    "documentation": {
                      "type": "string",
                      "format": "uri"
                    },
                    "openapi": {
                      "type": "string",
                      "format": "uri"
                    },
                    "tools": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "name": {
                            "type": "string"
                          },
                          "title": {
                            "type": "string"
                          },
                          "auth": {
                            "type": "string"
                          },
                          "read_only": {
                            "type": "boolean"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      },
      "post": {
        "tags": [
          "MCP"
        ],
        "operationId": "invokeMcpJsonRpc",
        "summary": "Execute Streamable HTTP MCP JSON-RPC 2.0 request",
        "description": "Handles MCP JSON-RPC 2.0 methods (`initialize`, `notifications/initialized`, `ping`, `tools/list`, `tools/call`) exposing 5 free anonymous read-only tools: `search_restaurant_leads`, `get_state_coverage`, `get_national_openings_stats`, `list_official_feeds`, and `get_pricing_and_csv_schema`. Max request body size is 16 KB.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/McpJsonRpcRequest"
              },
              "examples": {
                "listTools": {
                  "summary": "List all 5 MCP tools",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 1,
                    "method": "tools/list",
                    "params": {}
                  }
                },
                "searchLeads": {
                  "summary": "Search Texas full-service leads",
                  "value": {
                    "jsonrpc": "2.0",
                    "id": 2,
                    "method": "tools/call",
                    "params": {
                      "name": "search_restaurant_leads",
                      "arguments": {
                        "state": "TX",
                        "venue_type": "full_service",
                        "limit": 5
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "JSON-RPC 2.0 result or error object",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/McpJsonRpcResponse"
                }
              }
            }
          },
          "202": {
            "description": "Notification accepted (`notifications/initialized`)"
          },
          "400": {
            "description": "Malformed JSON or invalid JSON-RPC envelope",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/McpJsonRpcResponse"
                }
              }
            }
          },
          "413": {
            "description": "Request payload exceeds 16 KB limit",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/McpJsonRpcResponse"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/data/summary.json": {
      "get": {
        "tags": [
          "Public Data"
        ],
        "operationId": "getDatasetSummary",
        "summary": "Live 22-jurisdiction dataset summary JSON",
        "description": "Returns live indexed totals, active launch signals, per-state active signal share, venue/filing breakdowns, top active cities, pricing summary, and all 46 official government feed URLs.",
        "responses": {
          "200": {
            "description": "Live dataset summary JSON",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/data/row.schema.json": {
      "get": {
        "tags": [
          "Public Data"
        ],
        "operationId": "getRowSchema",
        "summary": "18-column filing record JSON Schema (Draft 2020-12)",
        "description": "Machine-readable JSON Schema describing every column in the public preview and 18-column subscriber CSV.",
        "responses": {
          "200": {
            "description": "JSON Schema Draft 2020-12 document",
            "content": {
              "application/schema+json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    },
    "/data/sample.csv": {
      "get": {
        "tags": [
          "Public Data"
        ],
        "operationId": "getPublicSampleCsv",
        "summary": "Public masked 18-column sample CSV (latest 25 filings)",
        "description": "Zero-signup masked CSV sample using the exact 18-column subscriber header with street numbers masked and contact fields redacted.",
        "responses": {
          "200": {
            "description": "UTF-8 CSV sample",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/.well-known/mcp/server-card.json": {
      "get": {
        "tags": [
          "MCP"
        ],
        "operationId": "getMcpServerCard",
        "summary": "MCP Server Card discovery metadata",
        "description": "Standard MCP server card declaring transport, endpoint URL, supported protocol versions, zero-auth tier, and all 5 anonymous tools.",
        "responses": {
          "200": {
            "description": "MCP server card JSON",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "responses": {
      "RateLimited": {
        "description": "Rate limit exceeded (60 req / 60s per IP, or global search cap reached)",
        "headers": {
          "Retry-After": {
            "description": "Seconds to wait before retrying",
            "schema": {
              "type": "integer"
            }
          }
        },
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "StateStats": {
        "type": "object",
        "required": [
          "state",
          "total",
          "pre_opening",
          "latest_filing"
        ],
        "properties": {
          "state": {
            "type": "string",
            "enum": [
              "TX",
              "NY",
              "FL",
              "CA",
              "IL",
              "WA",
              "OR",
              "MA",
              "PA",
              "DC",
              "CT",
              "CO",
              "NC",
              "MD",
              "OH",
              "MO",
              "VA",
              "TN",
              "KY",
              "MI",
              "DE",
              "AZ"
            ]
          },
          "total": {
            "type": "integer"
          },
          "pre_opening": {
            "type": "integer"
          },
          "latest_filing": {
            "type": "string"
          }
        }
      },
      "PublicLeadView": {
        "type": "object",
        "required": [
          "id",
          "source_id",
          "state",
          "city",
          "business_name",
          "venue_type",
          "street_preview",
          "has_owner",
          "has_phone",
          "filing_type",
          "stage_key",
          "pre_opening_score"
        ],
        "properties": {
          "id": {
            "type": "integer"
          },
          "source_id": {
            "type": "string"
          },
          "state": {
            "type": "string",
            "enum": [
              "TX",
              "NY",
              "FL",
              "CA",
              "IL",
              "WA",
              "OR",
              "MA",
              "PA",
              "DC",
              "CT",
              "CO",
              "NC",
              "MD",
              "OH",
              "MO",
              "VA",
              "TN",
              "KY",
              "MI",
              "DE",
              "AZ"
            ]
          },
          "city": {
            "type": "string"
          },
          "metro": {
            "type": "string"
          },
          "business_name": {
            "type": "string"
          },
          "venue_type": {
            "type": "string",
            "enum": [
              "full_service",
              "limited_service",
              "bar",
              "cafe_bakery",
              "food_other"
            ]
          },
          "venue_label": {
            "type": "string"
          },
          "raw_category": {
            "type": "string"
          },
          "street_preview": {
            "type": "string",
            "description": "House number masked as •••"
          },
          "zip_code": {
            "type": "string"
          },
          "has_owner": {
            "type": "boolean"
          },
          "has_phone": {
            "type": "boolean"
          },
          "seat_count": {
            "type": [
              "integer",
              "null"
            ]
          },
          "filing_type": {
            "type": "string",
            "enum": [
              "sales_tax",
              "liquor_pending",
              "liquor_active",
              "food_license",
              "business_license",
              "building_permit"
            ]
          },
          "filing_label": {
            "type": "string"
          },
          "filing_status": {
            "type": "string"
          },
          "filing_date": {
            "type": "string"
          },
          "planned_open_date": {
            "type": "string"
          },
          "is_future_open": {
            "type": "boolean"
          },
          "is_pre_opening": {
            "type": "boolean"
          },
          "stage_key": {
            "type": "string",
            "enum": [
              "final_inspection",
              "pending_liquor",
              "pre_opening",
              "new_filing",
              "active_registry"
            ]
          },
          "stage_label": {
            "type": "string"
          },
          "pre_opening_score": {
            "type": "integer",
            "minimum": 35,
            "maximum": 98
          }
        }
      },
      "McpJsonRpcRequest": {
        "type": "object",
        "required": [
          "jsonrpc",
          "method"
        ],
        "properties": {
          "jsonrpc": {
            "type": "string",
            "const": "2.0"
          },
          "id": {
            "type": [
              "string",
              "integer",
              "null"
            ]
          },
          "method": {
            "type": "string",
            "enum": [
              "initialize",
              "notifications/initialized",
              "ping",
              "tools/list",
              "tools/call"
            ]
          },
          "params": {
            "type": "object"
          }
        }
      },
      "McpJsonRpcResponse": {
        "type": "object",
        "required": [
          "jsonrpc",
          "id"
        ],
        "properties": {
          "jsonrpc": {
            "type": "string",
            "const": "2.0"
          },
          "id": {
            "type": [
              "string",
              "integer",
              "null"
            ]
          },
          "result": {
            "type": "object"
          },
          "error": {
            "type": "object",
            "required": [
              "code",
              "message"
            ],
            "properties": {
              "code": {
                "type": "integer"
              },
              "message": {
                "type": "string"
              }
            }
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        }
      }
    }
  }
}