{
  "openapi": "3.0.3",
  "info": {
    "title": "AgentFood API",
    "description": "USDA FoodData Central nutrition data API with x402 micropayments. Search foods, get full nutrition profiles, and compare multiple foods side-by-side.",
    "version": "1.0.0",
    "contact": {
      "name": "MemoryAPI",
      "url": "https://memoryapi.org"
    }
  },
  "servers": [
    { "url": "https://food.memoryapi.org", "description": "Production" },
    { "url": "http://localhost:3017", "description": "Local development" }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Health check",
        "operationId": "health",
        "security": [],
        "responses": {
          "200": {
            "description": "Service is healthy",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string", "example": "ok" },
                    "service": { "type": "string", "example": "agentfood" },
                    "port": { "type": "integer", "example": 3017 }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/x402/food/search": {
      "get": {
        "summary": "Search foods",
        "description": "Search USDA FoodData Central for foods. Returns nutrition macros per 100g.",
        "operationId": "searchFood",
        "x-price": "$0.001 USDC",
        "parameters": [
          { "name": "q", "in": "query", "description": "Food name to search", "schema": { "type": "string", "default": "chicken breast" } },
          { "name": "limit", "in": "query", "description": "Number of results (max 25)", "schema": { "type": "integer", "default": 10, "maximum": 25 } },
          { "name": "dataType", "in": "query", "description": "Filter by data type: Foundation, SR Legacy, Survey (FNDDS), Branded", "schema": { "type": "string" } },
          { "name": "brand", "in": "query", "description": "Filter by brand owner", "schema": { "type": "string" } }
        ],
        "responses": {
          "200": {
            "description": "Search results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "query": { "type": "string" },
                    "total_hits": { "type": "integer" },
                    "count": { "type": "integer" },
                    "foods": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "fdcId": { "type": "integer" },
                          "name": { "type": "string" },
                          "brand": { "type": "string" },
                          "dataType": { "type": "string" },
                          "calories": { "type": "number" },
                          "protein_g": { "type": "number" },
                          "fat_g": { "type": "number" },
                          "carbs_g": { "type": "number" },
                          "fiber_g": { "type": "number" },
                          "sodium_mg": { "type": "number" },
                          "ingredients": { "type": "string" }
                        }
                      }
                    },
                    "source": { "type": "string", "example": "USDA FoodData Central" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required — send x402 payment header" }
        }
      }
    },
    "/x402/food/nutrition": {
      "get": {
        "summary": "Get nutrition profile",
        "description": "Get full nutrition breakdown for a specific food by USDA FDC ID.",
        "operationId": "getNutrition",
        "x-price": "$0.001 USDC",
        "parameters": [
          { "name": "fdc_id", "in": "query", "description": "USDA FoodData Central ID", "schema": { "type": "string", "default": "173950" } },
          { "name": "format", "in": "query", "description": "abridged or full", "schema": { "type": "string", "enum": ["abridged", "full"], "default": "abridged" } }
        ],
        "responses": {
          "200": {
            "description": "Nutrition profile",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "fdc_id": { "type": "integer" },
                    "name": { "type": "string" },
                    "brand": { "type": "string" },
                    "description": { "type": "string" },
                    "data_type": { "type": "string" },
                    "nutrients": {
                      "type": "object",
                      "properties": {
                        "macronutrients": { "type": "object" },
                        "vitamins": { "type": "object" },
                        "minerals": { "type": "object" },
                        "other": { "type": "object" }
                      }
                    },
                    "source": { "type": "string" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required" }
        }
      }
    },
    "/x402/food/compare": {
      "get": {
        "summary": "Compare foods",
        "description": "Compare nutrition profiles of multiple foods side-by-side.",
        "operationId": "compareFoods",
        "x-price": "$0.001 USDC",
        "parameters": [
          { "name": "ids", "in": "query", "description": "Comma-separated USDA FDC IDs (up to 10)", "schema": { "type": "string", "default": "173950,2187885,1103516" } }
        ],
        "responses": {
          "200": {
            "description": "Comparison results",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "count": { "type": "integer" },
                    "foods": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": { "type": "integer" },
                          "name": { "type": "string" },
                          "brand": { "type": "string" },
                          "calories": { "type": "number" },
                          "protein": { "type": "number" },
                          "fat": { "type": "number" },
                          "carbs": { "type": "number" },
                          "fiber": { "type": "number" },
                          "sodium": { "type": "number" }
                        }
                      }
                    },
                    "winner_by_protein": { "type": "string" },
                    "winner_by_calories": { "type": "string" },
                    "source": { "type": "string" }
                  }
                }
              }
            }
          },
          "402": { "description": "Payment required" }
        }
      }
    },
    "/mcp": {
      "get": {
        "summary": "MCP server info",
        "operationId": "mcpInfo",
        "security": [],
        "responses": {
          "200": { "description": "MCP server info and available tools" }
        }
      },
      "post": {
        "summary": "MCP tool execution",
        "description": "Execute MCP tools: search_food, get_nutrition, compare_foods",
        "operationId": "mcpExecute",
        "security": [],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "jsonrpc": { "type": "string", "example": "2.0" },
                  "method": { "type": "string", "example": "tools/call" },
                  "params": { "type": "object" },
                  "id": { "type": "integer" }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "MCP response" }
        }
      }
    }
  }
}
