"""Search tools for Trade Me MCP server."""
from typing import Any, Optional
from ..client import TradeMeClient
async def search_general(client: TradeMeClient, **kwargs: Any) -> dict[str, Any]:
"""
Search the Trade Me marketplace across all categories.
Perform a general search for listings with various filtering options.
No authentication required for basic searches.
Args:
search_string: Search keywords (optional)
category: Category number to search within (e.g., "0004-0369-6076-")
price_min: Minimum price filter
price_max: Maximum price filter
condition: Item condition ("New", "Used", "Refurbished")
buy_now_only: Only show Buy Now listings (true/false)
region: Region ID for location filtering
district: District ID for location filtering
suburb: Suburb ID for location filtering
page: Page number for pagination (default: 1)
rows: Number of results per page (default: 25, max: 500)
sort_order: Sort order ("Default", "ExpiryAsc", "ExpiryDesc", "PriceAsc", "PriceDesc", "Featured")
member_listing: Search by member ID
return_metadata: Include metadata in response (true/false)
Returns:
Search results with listings, pagination info, and filters
Example:
Search for "laptop": search_general(search_string="laptop", price_max=1000)
Search in category: search_general(category="0004-", rows=50)
"""
params = {}
if "search_string" in kwargs:
params["search_string"] = kwargs["search_string"]
if "category" in kwargs:
params["category"] = kwargs["category"]
if "price_min" in kwargs:
params["price_min"] = kwargs["price_min"]
if "price_max" in kwargs:
params["price_max"] = kwargs["price_max"]
if "condition" in kwargs:
params["condition"] = kwargs["condition"]
if "buy_now_only" in kwargs:
params["buy_now_only"] = str(kwargs["buy_now_only"]).lower()
if "region" in kwargs:
params["region"] = kwargs["region"]
if "district" in kwargs:
params["district"] = kwargs["district"]
if "suburb" in kwargs:
params["suburb"] = kwargs["suburb"]
if "page" in kwargs:
params["page"] = kwargs["page"]
if "rows" in kwargs:
params["rows"] = min(kwargs["rows"], 500) # Enforce max limit
if "sort_order" in kwargs:
params["sort_order"] = kwargs["sort_order"]
if "member_listing" in kwargs:
params["member_listing"] = kwargs["member_listing"]
if "return_metadata" in kwargs:
params["return_metadata"] = str(kwargs["return_metadata"]).lower()
return client.get("/Search/General.json", params=params, requires_auth=False)
async def search_property_residential(client: TradeMeClient, **kwargs: Any) -> dict[str, Any]:
"""
Search for residential properties for sale.
Search Trade Me Property for houses, apartments, and residential land.
No authentication required.
Args:
search_string: Search keywords
region: Region ID
district: District ID for location filtering
suburb: Suburb ID for location filtering
price_min: Minimum price
price_max: Maximum price
bedrooms_min: Minimum number of bedrooms
bedrooms_max: Maximum number of bedrooms
bathrooms_min: Minimum number of bathrooms
property_type: Type of property ("House", "Apartment", "Townhouse", "Unit", "Land")
adjacent_suburbs: Include adjacent suburbs in search (true/false)
page: Page number
rows: Results per page (max 500)
sort_order: Sort order ("Default", "PriceAsc", "PriceDesc", "ExpiryAsc", "ExpiryDesc")
Returns:
Property search results with listings and metadata
Example:
search_property_residential(region=9, bedrooms_min=3, price_max=800000)
"""
params = {}
if "search_string" in kwargs:
params["search_string"] = kwargs["search_string"]
if "region" in kwargs:
params["region"] = kwargs["region"]
if "district" in kwargs:
params["district"] = kwargs["district"]
if "suburb" in kwargs:
params["suburb"] = kwargs["suburb"]
if "price_min" in kwargs:
params["price_min"] = kwargs["price_min"]
if "price_max" in kwargs:
params["price_max"] = kwargs["price_max"]
if "bedrooms_min" in kwargs:
params["bedrooms_min"] = kwargs["bedrooms_min"]
if "bedrooms_max" in kwargs:
params["bedrooms_max"] = kwargs["bedrooms_max"]
if "bathrooms_min" in kwargs:
params["bathrooms_min"] = kwargs["bathrooms_min"]
if "property_type" in kwargs:
params["property_type"] = kwargs["property_type"]
if "adjacent_suburbs" in kwargs:
params["adjacent_suburbs"] = str(kwargs["adjacent_suburbs"]).lower()
if "page" in kwargs:
params["page"] = kwargs["page"]
if "rows" in kwargs:
params["rows"] = min(kwargs["rows"], 500)
if "sort_order" in kwargs:
params["sort_order"] = kwargs["sort_order"]
return client.get("/Search/Property/Residential.json", params=params, requires_auth=False)
async def search_property_rental(client: TradeMeClient, **kwargs: Any) -> dict[str, Any]:
"""
Search for rental properties.
Search Trade Me Property for houses and apartments to rent.
No authentication required.
Args:
search_string: Search keywords
region: Region ID
district: District ID
suburb: Suburb ID
price_min: Minimum weekly rent
price_max: Maximum weekly rent
bedrooms_min: Minimum bedrooms
bedrooms_max: Maximum bedrooms
property_type: Property type ("House", "Apartment", "Townhouse", etc.)
pets_ok: Allow pets (true/false)
smokers_ok: Allow smokers (true/false)
date_available: Date available from (ISO format YYYY-MM-DD)
adjacent_suburbs: Include adjacent suburbs (true/false)
page: Page number
rows: Results per page (max 500)
sort_order: Sort order
Returns:
Rental property search results
Example:
search_property_rental(region=9, bedrooms_min=2, price_max=500, pets_ok=true)
"""
params = {}
if "search_string" in kwargs:
params["search_string"] = kwargs["search_string"]
if "region" in kwargs:
params["region"] = kwargs["region"]
if "district" in kwargs:
params["district"] = kwargs["district"]
if "suburb" in kwargs:
params["suburb"] = kwargs["suburb"]
if "price_min" in kwargs:
params["price_min"] = kwargs["price_min"]
if "price_max" in kwargs:
params["price_max"] = kwargs["price_max"]
if "bedrooms_min" in kwargs:
params["bedrooms_min"] = kwargs["bedrooms_min"]
if "bedrooms_max" in kwargs:
params["bedrooms_max"] = kwargs["bedrooms_max"]
if "property_type" in kwargs:
params["property_type"] = kwargs["property_type"]
if "pets_ok" in kwargs:
params["pets_ok"] = str(kwargs["pets_ok"]).lower()
if "smokers_ok" in kwargs:
params["smokers_ok"] = str(kwargs["smokers_ok"]).lower()
if "date_available" in kwargs:
params["date_available"] = kwargs["date_available"]
if "adjacent_suburbs" in kwargs:
params["adjacent_suburbs"] = str(kwargs["adjacent_suburbs"]).lower()
if "page" in kwargs:
params["page"] = kwargs["page"]
if "rows" in kwargs:
params["rows"] = min(kwargs["rows"], 500)
if "sort_order" in kwargs:
params["sort_order"] = kwargs["sort_order"]
return client.get("/Search/Property/Rental.json", params=params, requires_auth=False)
async def search_property_commercial(client: TradeMeClient, **kwargs: Any) -> dict[str, Any]:
"""
Search for commercial properties.
Search for commercial real estate including offices, retail, industrial.
No authentication required.
Args:
search_string: Search keywords
region: Region ID
district: District ID
suburb: Suburb ID
price_min: Minimum price
price_max: Maximum price
property_type: Commercial property type ("Office", "Retail", "Industrial", "Land")
area_min: Minimum floor area (sqm)
area_max: Maximum floor area (sqm)
page: Page number
rows: Results per page (max 500)
sort_order: Sort order
Returns:
Commercial property search results
Example:
search_property_commercial(property_type="Office", region=9, area_min=100)
"""
params = {}
if "search_string" in kwargs:
params["search_string"] = kwargs["search_string"]
if "region" in kwargs:
params["region"] = kwargs["region"]
if "district" in kwargs:
params["district"] = kwargs["district"]
if "suburb" in kwargs:
params["suburb"] = kwargs["suburb"]
if "price_min" in kwargs:
params["price_min"] = kwargs["price_min"]
if "price_max" in kwargs:
params["price_max"] = kwargs["price_max"]
if "property_type" in kwargs:
params["property_type"] = kwargs["property_type"]
if "area_min" in kwargs:
params["area_min"] = kwargs["area_min"]
if "area_max" in kwargs:
params["area_max"] = kwargs["area_max"]
if "page" in kwargs:
params["page"] = kwargs["page"]
if "rows" in kwargs:
params["rows"] = min(kwargs["rows"], 500)
if "sort_order" in kwargs:
params["sort_order"] = kwargs["sort_order"]
return client.get("/Search/Property/Commercial.json", params=params, requires_auth=False)
async def search_motors(client: TradeMeClient, **kwargs: Any) -> dict[str, Any]:
"""
Search for motor vehicles.
Search Trade Me Motors for cars, motorcycles, boats, and other vehicles.
No authentication required.
Args:
search_string: Search keywords (make/model)
category: Motors category (e.g., "0268-" for cars)
price_min: Minimum price
price_max: Maximum price
year_min: Minimum year
year_max: Maximum year
odometer_min: Minimum odometer reading (km)
odometer_max: Maximum odometer reading (km)
make: Vehicle make
model: Vehicle model
body_style: Body style ("Sedan", "SUV", "Hatchback", etc.)
doors_min: Minimum number of doors
transmission: Transmission type ("Automatic", "Manual")
fuel_type: Fuel type ("Petrol", "Diesel", "Electric", "Hybrid")
engine_size_min: Minimum engine size (cc)
engine_size_max: Maximum engine size (cc)
region: Region ID
page: Page number
rows: Results per page (max 500)
sort_order: Sort order
Returns:
Motor vehicle search results
Example:
search_motors(make="Toyota", year_min=2015, price_max=25000, transmission="Automatic")
"""
params = {}
if "search_string" in kwargs:
params["search_string"] = kwargs["search_string"]
if "category" in kwargs:
params["category"] = kwargs["category"]
if "price_min" in kwargs:
params["price_min"] = kwargs["price_min"]
if "price_max" in kwargs:
params["price_max"] = kwargs["price_max"]
if "year_min" in kwargs:
params["year_min"] = kwargs["year_min"]
if "year_max" in kwargs:
params["year_max"] = kwargs["year_max"]
if "odometer_min" in kwargs:
params["odometer_min"] = kwargs["odometer_min"]
if "odometer_max" in kwargs:
params["odometer_max"] = kwargs["odometer_max"]
if "make" in kwargs:
params["make"] = kwargs["make"]
if "model" in kwargs:
params["model"] = kwargs["model"]
if "body_style" in kwargs:
params["body_style"] = kwargs["body_style"]
if "doors_min" in kwargs:
params["doors_min"] = kwargs["doors_min"]
if "transmission" in kwargs:
params["transmission"] = kwargs["transmission"]
if "fuel_type" in kwargs:
params["fuel_type"] = kwargs["fuel_type"]
if "engine_size_min" in kwargs:
params["engine_size_min"] = kwargs["engine_size_min"]
if "engine_size_max" in kwargs:
params["engine_size_max"] = kwargs["engine_size_max"]
if "region" in kwargs:
params["region"] = kwargs["region"]
if "page" in kwargs:
params["page"] = kwargs["page"]
if "rows" in kwargs:
params["rows"] = min(kwargs["rows"], 500)
if "sort_order" in kwargs:
params["sort_order"] = kwargs["sort_order"]
return client.get("/Search/Motors.json", params=params, requires_auth=False)
async def search_jobs(client: TradeMeClient, **kwargs: Any) -> dict[str, Any]:
"""
Search for job listings.
Search Trade Me Jobs for employment opportunities.
No authentication required.
Args:
search_string: Search keywords (job title, company)
category: Jobs category number
region: Region ID
district: District ID
type: Job type ("FullTime", "PartTime", "Contract", "Casual", "Temporary")
pay_min: Minimum salary/pay
pay_max: Maximum salary/pay
pay_type: Pay period ("Annual", "Hourly", "Daily")
work_type: Work arrangement ("Office", "Remote", "Hybrid")
page: Page number
rows: Results per page (max 500)
sort_order: Sort order ("Default", "ExpiryAsc", "ExpiryDesc")
Returns:
Job search results
Example:
search_jobs(search_string="software developer", region=9, type="FullTime", pay_min=80000)
"""
params = {}
if "search_string" in kwargs:
params["search_string"] = kwargs["search_string"]
if "category" in kwargs:
params["category"] = kwargs["category"]
if "region" in kwargs:
params["region"] = kwargs["region"]
if "district" in kwargs:
params["district"] = kwargs["district"]
if "type" in kwargs:
params["type"] = kwargs["type"]
if "pay_min" in kwargs:
params["pay_min"] = kwargs["pay_min"]
if "pay_max" in kwargs:
params["pay_max"] = kwargs["pay_max"]
if "pay_type" in kwargs:
params["pay_type"] = kwargs["pay_type"]
if "work_type" in kwargs:
params["work_type"] = kwargs["work_type"]
if "page" in kwargs:
params["page"] = kwargs["page"]
if "rows" in kwargs:
params["rows"] = min(kwargs["rows"], 500)
if "sort_order" in kwargs:
params["sort_order"] = kwargs["sort_order"]
return client.get("/Search/Jobs.json", params=params, requires_auth=False)
async def search_services(client: TradeMeClient, **kwargs: Any) -> dict[str, Any]:
"""
Search for services.
Search Trade Me Services for professional services and tradespeople.
No authentication required.
Args:
search_string: Search keywords (service type, tradesperson)
category: Services category number
region: Region ID
district: District ID
suburb: Suburb ID
page: Page number
rows: Results per page (max 500)
sort_order: Sort order
Returns:
Services search results
Example:
search_services(search_string="plumber", region=9)
"""
params = {}
if "search_string" in kwargs:
params["search_string"] = kwargs["search_string"]
if "category" in kwargs:
params["category"] = kwargs["category"]
if "region" in kwargs:
params["region"] = kwargs["region"]
if "district" in kwargs:
params["district"] = kwargs["district"]
if "suburb" in kwargs:
params["suburb"] = kwargs["suburb"]
if "page" in kwargs:
params["page"] = kwargs["page"]
if "rows" in kwargs:
params["rows"] = min(kwargs["rows"], 500)
if "sort_order" in kwargs:
params["sort_order"] = kwargs["sort_order"]
return client.get("/Search/Services.json", params=params, requires_auth=False)