{
  "openapi": "3.0.3",
  "info": {
    "title": "ChinaDriveTest — Official Public REST & MCP API",
    "version": "1.0.0",
    "description": "Stateless read-only driving compliance and exam engines covering 2,545 bilingual China Subject 1 test questions, SM-2 spaced repetition, MPS Order No. 172 mutual license swap rules, 9 airport 15-minute permit counters, 5 municipal DMV guides, and 3 iconic self-drive itineraries.",
    "contact": {
      "name": "ChinaDriveTest",
      "url": "https://chinadrivetest.com",
      "email": "admin@chinadrivetest.com"
    },
    "license": {
      "name": "MIT",
      "url": "https://opensource.org/licenses/MIT"
    }
  },
  "externalDocs": {
    "description": "ChinaDriveTest Official Portal",
    "url": "https://chinadrivetest.com"
  },
  "servers": [
    {
      "url": "https://chinadrivetest.com",
      "description": "Production Edge & Cloud Run"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    }
  },
  "paths": {
    "/api/v1/me": {
      "get": {
        "operationId": "verifyApiConnection",
        "summary": "Verify ChinaDriveTest Connection & Tool Count",
        "security": [
          {
            "ApiKeyAuth": []
          },
          {
            "BearerAuth": []
          },
          {}
        ],
        "responses": {
          "200": {
            "description": "Service status and MCP tool inventory count"
          }
        }
      }
    },
    "/api/v1/tools": {
      "get": {
        "operationId": "listChinaDriveTestTools",
        "summary": "List All ChinaDriveTest Tools",
        "responses": {
          "200": {
            "description": "JSON schema inventory of all 8 ChinaDriveTest tools"
          }
        }
      }
    },
    "/api/v1/tools/search_subject1_exam_questions": {
      "post": {
        "operationId": "search_subject1_exam_questions",
        "summary": "China Subject 1 Bilingual Question Bank Search (2,545 Official Items)",
        "description": "Filter the full 2,545-question Mainland China driving theory exam corpus by English or Chinese keyword, topic chapter, difficulty rating, and historical candidate error rate.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "keyword": {
                    "type": "string",
                    "description": "Search phrase matched against English/Chinese prompts, answer options, or legal explanations (e.g., \"yellow\", \"alcohol\", \"expressway\")."
                  },
                  "chapterSlug": {
                    "type": "string",
                    "enum": [
                      "all",
                      "traffic-signs",
                      "speed-limits",
                      "point-deduction-rules",
                      "police-hand-signals",
                      "alcohol-drunk-driving",
                      "expressway-rules",
                      "accident-procedures",
                      "ev-green-plate-rules",
                      "general-laws"
                    ],
                    "description": "Filter by one of the 9 official Subject 1 syllabus chapters or pass \"all\"."
                  },
                  "questionType": {
                    "type": "string",
                    "enum": [
                      "all",
                      "choice",
                      "judgement"
                    ],
                    "description": "Restrict results to 4-option multiple choice or Correct/Wrong true-false judgement questions."
                  },
                  "minDifficulty": {
                    "type": "number",
                    "description": "Minimum difficulty tier from 1 (basic) to 5 (high-trap tricky wording)."
                  },
                  "sortByErrorRate": {
                    "type": "boolean",
                    "description": "Sort matching items descending by historical candidate error rate to surface top exam traps first."
                  },
                  "limit": {
                    "type": "number",
                    "description": "Maximum questions returned per query (1 to 25, defaults to 10)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance & exam result"
          }
        }
      }
    },
    "/api/v1/tools/grade_mock_exam_and_sm2_schedule": {
      "post": {
        "operationId": "grade_mock_exam_and_sm2_schedule",
        "summary": "Subject 1 Mock Exam Grader & SuperMemo-2 Spaced Repetition Engine",
        "description": "Score candidate answer sheets against the 90/100 statutory pass cutoff while computing updated SuperMemo-2 review intervals, or generate a weighted practice drill sheet by chapter.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "submissions": {
                    "type": "array",
                    "description": "Candidate answers to grade against the 2,545-question official answer key with optional prior SM-2 card state.",
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "properties": {
                        "questionId": {
                          "type": "string",
                          "description": "Question ID string or numeric question index (1-2545) from the Subject 1 bank."
                        },
                        "selectedAnswer": {
                          "type": "string",
                          "description": "Candidate choice letter (\"A\", \"B\", \"C\", or \"D\")."
                        },
                        "currentReps": {
                          "type": "number",
                          "description": "Prior consecutive correct repetitions for this SM-2 card (defaults to 0)."
                        },
                        "currentInterval": {
                          "type": "number",
                          "description": "Prior SM-2 spacing interval in days before this attempt (defaults to 0)."
                        },
                        "currentEase": {
                          "type": "number",
                          "description": "Prior SM-2 ease factor between 1.3 and 3.0 (defaults to 2.5)."
                        }
                      },
                      "required": [
                        "questionId",
                        "selectedAnswer"
                      ]
                    }
                  },
                  "generateDrillCount": {
                    "type": "number",
                    "description": "When submissions are omitted, number of high-trap questions to emit for a timed drill (5 to 25)."
                  },
                  "chapterSlug": {
                    "type": "string",
                    "enum": [
                      "all",
                      "traffic-signs",
                      "speed-limits",
                      "point-deduction-rules",
                      "police-hand-signals",
                      "alcohol-drunk-driving",
                      "expressway-rules",
                      "accident-procedures",
                      "ev-green-plate-rules",
                      "general-laws"
                    ],
                    "description": "Optional syllabus chapter filter when generating a fresh practice quiz sheet."
                  },
                  "includeAnswerKey": {
                    "type": "boolean",
                    "description": "Whether freshly generated drill questions include answers and explanations immediately."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance & exam result"
          }
        }
      }
    },
    "/api/v1/tools/evaluate_foreign_license_conversion_and_mutual_swap": {
      "post": {
        "operationId": "evaluate_foreign_license_conversion_and_mutual_swap",
        "summary": "MPS Order No. 172 Mutual Recognition & Permit vs 6-Year License Evaluator",
        "description": "Determine whether an overseas driver qualifies for a zero-exam bilateral swap across 6 treaty jurisdictions, a 15-minute airport tourist permit, or a 6-year C1/C2 conversion.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "issuingJurisdiction": {
                    "type": "string",
                    "description": "Country or SAR issuing the current valid foreign license (e.g., \"France\", \"Belgium\", \"UAE\", \"Serbia\", \"Hong Kong\", \"Macau\", \"USA\", \"UK\")."
                  },
                  "stayDurationDays": {
                    "type": "number",
                    "description": "Planned stay duration in Mainland China measured in days (temporary permit covers up to 90 days per entry)."
                  },
                  "holdsChinaResidencePermit": {
                    "type": "boolean",
                    "description": "Whether the applicant holds a Chinese Work, Study, or Family Residence Permit valid for 90+ days."
                  },
                  "applicantAge": {
                    "type": "number",
                    "description": "Driver age in years; checks C1/C2 zero upper age ceiling and age 70+ cognitive Three Abilities test under Order No. 172."
                  }
                },
                "required": [
                  "issuingJurisdiction"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance & exam result"
          }
        }
      }
    },
    "/api/v1/tools/query_airport_temporary_permit_counter": {
      "post": {
        "operationId": "query_airport_temporary_permit_counter",
        "summary": "China Airport 15-Minute Temporary Driving Permit Counter Locator",
        "description": "Look up on-arrival Traffic Police service desks across 9 international airports (PVG, SHA, PEK, PKX, TFU, SYX, HAK, SZX, URC), returning terminal concourses, fees, photo booths, and car rental pickup bays.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "airportQuery": {
                    "type": "string",
                    "description": "IATA code (PVG, SHA, PEK, PKX, TFU, SYX, HAK, SZX, URC), city name (Shanghai, Beijing, Chengdu, Sanya), slug, or \"all\"."
                  },
                  "includeArrivalSteps": {
                    "type": "boolean",
                    "description": "Include step-by-step terminal walking instructions from Customs exit to the licensing counter."
                  },
                  "includeRentalBays": {
                    "type": "boolean",
                    "description": "Include on-site airport rental car garage pickup zones and foreign credit card compatibility."
                  }
                },
                "required": [
                  "airportQuery"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance & exam result"
          }
        }
      }
    },
    "/api/v1/tools/query_city_dmv_conversion_guide": {
      "post": {
        "operationId": "query_city_dmv_conversion_guide",
        "summary": "Chinese Municipal DMV (Cheguansuo) Foreign License Conversion Walkthrough",
        "description": "Retrieve exact street addresses, subway access, Traffic Management 12123 booking rules, bilingual taxi direction cards, and window workflows for Shanghai, Beijing, Shenzhen, Guangzhou, and Chengdu DMVs.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "citySlug": {
                    "type": "string",
                    "enum": [
                      "shanghai",
                      "beijing",
                      "shenzhen",
                      "guangzhou",
                      "chengdu",
                      "all"
                    ],
                    "description": "Chinese municipality Vehicle Management Office (车管所) guide to inspect."
                  },
                  "includeHallSteps": {
                    "type": "boolean",
                    "description": "Include counter-by-counter window sequence inside the DMV hall."
                  },
                  "includeBranchDirectory": {
                    "type": "boolean",
                    "description": "Include sub-district DMV offices accepting foreign passport holders in the municipality."
                  }
                },
                "required": [
                  "citySlug"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance & exam result"
          }
        }
      }
    },
    "/api/v1/tools/generate_dmv_license_translation_and_class_map": {
      "post": {
        "operationId": "generate_dmv_license_translation_and_class_map",
        "summary": "Chinese Driver License Translation Sheet & Vehicle Class Mapper",
        "description": "Convert overseas license categories to PRC C1, C2, or E/D equivalents, deterministically synthesize an official 3-character Chinese applicant name, and output a structured DMV filing dossier.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "fullName": {
                    "type": "string",
                    "description": "Applicant full Latin name exactly as shown on foreign passport (e.g., \"John David Smith\")."
                  },
                  "gender": {
                    "type": "string",
                    "enum": [
                      "male",
                      "female"
                    ],
                    "description": "Preferred naming character pool when synthesizing the 3-character Chinese name."
                  },
                  "foreignLicenseClass": {
                    "type": "string",
                    "description": "License class printed on home license (e.g., \"Class C\", \"Automatic only\", \"Class M Motorcycle\")."
                  },
                  "issuingCountry": {
                    "type": "string",
                    "description": "Country/state that issued the original driver license."
                  },
                  "nationality": {
                    "type": "string",
                    "description": "Passport nationality for translation form header."
                  },
                  "originalLicenseNumber": {
                    "type": "string",
                    "description": "Alphanumeric license number printed on the foreign driving permit."
                  }
                },
                "required": [
                  "fullName"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance & exam result"
          }
        }
      }
    },
    "/api/v1/tools/lookup_chinese_road_signs_and_demerit_points": {
      "post": {
        "operationId": "lookup_chinese_road_signs_and_demerit_points",
        "summary": "GB5768 Road Sign Decoder, Police Hand Signals & 12-Point Penalty Ledger",
        "description": "Inspect 25 visual traffic warning, prohibition, mandatory, and directional signs plus 8 official police hand gestures alongside Order No. 172 demerit brackets (12, 9, 6, 3, and 1 points).",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "category": {
                    "type": "string",
                    "enum": [
                      "all",
                      "warning",
                      "prohibition",
                      "mandatory",
                      "guide",
                      "police_signals"
                    ],
                    "description": "Road sign or gesture family under GB5768 national standards."
                  },
                  "keyword": {
                    "type": "string",
                    "description": "Keyword to search sign names, exam trap notes, or demerit offense descriptions."
                  },
                  "demeritPointsFilter": {
                    "type": "number",
                    "enum": [
                      0,
                      12,
                      9,
                      6,
                      3,
                      1
                    ],
                    "description": "Filter violations by demerit point tier (12, 9, 6, 3, or 1), or 0 for all severity tiers."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance & exam result"
          }
        }
      }
    },
    "/api/v1/tools/plan_china_self_drive_route_and_rental": {
      "post": {
        "operationId": "plan_china_self_drive_route_and_rental",
        "summary": "China Foreigner Self-Drive Route Dossier & Car Rental Agency Advisor",
        "description": "Compile logistics for Duku Highway (G217), Western Sichuan (G318), and Hainan Ring Road itineraries including altitude hazards, foreign passport police checkpoints, EV charging corridors, and rental partners.",
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                  "routeSlug": {
                    "type": "string",
                    "enum": [
                      "duku-highway-xinjiang",
                      "western-sichuan-g318",
                      "hainan-island-ring-road",
                      "all"
                    ],
                    "description": "Featured Chinese scenic driving corridor or \"all\" for full catalog."
                  },
                  "includeDayByDayItinerary": {
                    "type": "boolean",
                    "description": "Include full daily stage distances, elevation profiles, and driving tips."
                  },
                  "includeRentalAgencies": {
                    "type": "boolean",
                    "description": "Include verified car rental platforms accepting foreign passports and Visa/Mastercard."
                  }
                },
                "required": [
                  "routeSlug"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deterministic compliance & exam result"
          }
        }
      }
    }
  }
}
