{
  "openapi": "3.1.0",
  "info": {
    "title": "Z-Marketplace B2B & Agentic Commerce API",
    "version": "2.0.0",
    "description": "Unified API for Buyers, Suppliers, External Search Agents (suppliers, prices, direct buy URLs), and Native MCP."
  },
  "servers": [
    {
      "url": "https://35v.ru"
    }
  ],
  "paths": {
    "/mcp": {
      "post": {
        "summary": "Native Model Context Protocol (MCP) JSON-RPC 2.0 endpoint",
        "description": "Supports initialize, tools/list, tools/call, resources/list, resources/read.",
        "responses": {
          "200": {
            "description": "JSON-RPC 2.0 response"
          }
        }
      }
    },
    "/api/mp/v1/agents/search": {
      "get": {
        "summary": "Primary global search for suppliers, prices, and direct product/supplier URLs",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "region",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 15
            }
          },
          {
            "name": "include_retail",
            "in": "query",
            "schema": {
              "type": "boolean",
              "default": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "B2B Golden SKU offers + direct retail URLs + Schema.org JSON-LD"
          }
        }
      }
    },
    "/api/mp/v1/agents/keys": {
      "get": {
        "summary": "List issued agent API keys (prefixes only)",
        "responses": {
          "200": {
            "description": "Keys list"
          }
        }
      },
      "post": {
        "summary": "Issue a scoped buyer_agent / supplier_agent / public_search API key",
        "responses": {
          "201": {
            "description": "Created key (shown once)"
          }
        }
      }
    },
    "/api/mp/v1/regions": {
      "get": {
        "summary": "List RF subject codes (421/pr) with live supplier/warehouse/offer counts",
        "responses": {
          "200": {
            "description": "Regions list"
          }
        }
      }
    },
    "/api/mp/v1/networks": {
      "get": {
        "summary": "List brand/manufacturer networks (e.g. VEZA) and all regional representative cabinets",
        "responses": {
          "200": {
            "description": "Networks list"
          }
        }
      }
    },
    "/api/mp/v1/networks/route": {
      "get": {
        "summary": "Route buyer or AI agent to the exact regional representative for a brand and RF subject code",
        "responses": {
          "200": {
            "description": "Recommended regional representative"
          }
        }
      }
    },
    "/api/mp/v1/portal/profile": {
      "post": {
        "summary": "Update company card, INN/KPP/OGRN, bank requisites, manager and covered regions for a supplier/representative cabinet",
        "responses": {
          "200": {
            "description": "Updated profile"
          }
        }
      }
    },
    "/api/mp/v1/portal/warehouses": {
      "post": {
        "summary": "Create/update supplier regional warehouse and delivery regions",
        "responses": {
          "201": {
            "description": "Saved warehouse"
          }
        }
      }
    },
    "/api/mp/v1/buyer/projects": {
      "get": {
        "summary": "List all live buyer procurement projects (highlighting DSHI Start)",
        "responses": {
          "200": {
            "description": "Projects summary"
          }
        }
      }
    },
    "/api/mp/v1/buyer/projects/{order_code}": {
      "get": {
        "summary": "Complete Buyer Dashboard: requested items, dispatches, replies, received KPs & invoices",
        "parameters": [
          {
            "name": "order_code",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "lot",
            "in": "query",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Buyer project dashboard"
          }
        }
      }
    },
    "/api/mp/v1/buyer/projects/{order_code}/export-xlsx": {
      "get": {
        "summary": "Export Buyer Dashboard (3 sheets, A4 landscape, live Excel formulas)",
        "responses": {
          "200": {
            "description": "XLSX file"
          }
        }
      }
    },
    "/api/mp/v1/portal/workspace": {
      "get": {
        "summary": "Supplier workspace (profile, open RFQs, active offers, generated KPs/invoices)",
        "responses": {
          "200": {
            "description": "Workspace payload"
          }
        }
      }
    },
    "/api/mp/v1/portal/documents/generate": {
      "post": {
        "summary": "Generate official A4 Russian KP or Invoice & publish items to Buy Box",
        "responses": {
          "201": {
            "description": "Generated document metadata + HTML URL"
          }
        }
      }
    },
    "/api/mp/v1/portal/documents/{doc_id}/html": {
      "get": {
        "summary": "Render print-ready A4 HTML of generated KP or Invoice",
        "responses": {
          "200": {
            "description": "HTML A4 document"
          }
        }
      }
    },
    "/api/mp/v1/products": {
      "get": {
        "summary": "Hybrid BGE-M3 + lexical Golden SKU catalog search",
        "responses": {
          "200": {
            "description": "Catalog cards"
          }
        }
      }
    },
    "/api/mp/v1/bom/match": {
      "post": {
        "summary": "Batch BOM specification matching and 421/pr 3-KP coverage",
        "responses": {
          "200": {
            "description": "Matched BOM"
          }
        }
      }
    },
    "/healthz": {
      "get": {
        "summary": "Service and PostgreSQL health check",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}