get_coupons
Retrieve coupons for a product. Optionally filter by coupon code and paginate results.
Instructions
Get Coupons
Retorna os cupons de um produto.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| product_id | Yes | ID do produto | |
| code | No | Código do cupom | |
| page_token | No | Token de paginação para a próxima página | |
| select | No | Seleção de campos customizados na resposta |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/hotmart_mcp/tools/coupons.py:48-72 (handler)The async function 'get_coupons' that implements the tool logic. It calls GET /products/api/v1/coupon/product/{product_id} with optional query params (code, page_token, select) and returns JSON.
async def get_coupons( product_id: int, code: Optional[str] = None, page_token: Optional[str] = None, select: Optional[str] = None, ) -> str: """Get Coupons Retorna os cupons de um produto. Args: product_id: ID do produto code: Código do cupom page_token: Token de paginação para a próxima página select: Seleção de campos customizados na resposta""" endpoint = f"/products/api/v1/coupon/product/{product_id}" params = {} if code is not None: params["code"] = code if page_token is not None: params["page_token"] = page_token if select is not None: params["select"] = select result = await get_client().get(endpoint, params=params) return json.dumps(result, indent=2) - src/hotmart_mcp/server.py:21-37 (registration)The '_discover_and_register_tools' function that auto-discovers and registers all async functions from tool modules (including get_coupons) as MCP tools via mcp.tool().
def _discover_and_register_tools() -> int: """Import all modules under hotmart_mcp.tools and register async functions.""" registered = 0 for module_info in pkgutil.iter_modules(tools_pkg.__path__, prefix=f"{tools_pkg.__name__}."): if module_info.name.endswith("__init__"): continue module = importlib.import_module(module_info.name) for name, obj in inspect.getmembers(module, iscoroutinefunction): if name.startswith("_"): continue mcp.tool()(obj) registered += 1 return registered - src/hotmart_mcp/tools/coupons.py:8-8 (registration)The __all__ list in coupons.py that exports 'get_coupons' as a public function, making it discoverable by the registration mechanism.
__all__ = ["create_coupon", "get_coupons", "delete_coupon"] - The function signature and type annotations serve as input schema: product_id (int, required), code (Optional[str]), page_token (Optional[str]), select (Optional[str]). Returns str (JSON).
async def get_coupons( product_id: int, code: Optional[str] = None, page_token: Optional[str] = None, select: Optional[str] = None, ) -> str: - src/hotmart_mcp/_shared.py:10-14 (helper)The 'get_client' helper that provides the HTTP client used by get_coupons to make the API request.
def get_client() -> HotmartClient: global _client if _client is None: _client = HotmartClient() return _client