diff --git a/mcp_servers/product_mcp/server.py b/mcp_servers/product_mcp/server.py index 866cd5a..daadd15 100644 --- a/mcp_servers/product_mcp/server.py +++ b/mcp_servers/product_mcp/server.py @@ -17,6 +17,11 @@ class Settings(BaseSettings): """Server configuration""" hyperf_api_url: str hyperf_api_token: str + mall_api_url: str + mall_tenant_id: str = "2" + mall_currency_code: str = "EUR" + mall_language_id: str = "1" + mall_source: str = "us.qa1.gaia888.com" log_level: str = "INFO" model_config = ConfigDict(env_file=".env") @@ -277,6 +282,14 @@ async def search_products( try: from shared.mall_client import MallClient + import logging + logger = logging.getLogger(__name__) + + logger.info( + f"search_products called with keyword={keyword}, " + f"user_token_prefix={user_token[:20] if user_token else None}..." + ) + print(f"[DEBUG] search_products called: keyword={keyword}, user_token={user_token[:20] if user_token else None}...") # 使用用户 token 创建 Mall 客户端 mall = MallClient( @@ -294,8 +307,19 @@ async def search_products( page=page ) + logger.info( + f"Mall API returned: result_type={type(result).__name__}, " + f"result_keys={list(result.keys()) if isinstance(result, dict) else 'not a dict'}, " + f"result={result}" + ) + print(f"[DEBUG] Mall API returned: {result}") + # 解析返回结果 - products = result.get("list", []) + # Mall API 返回结构: {"total": X, "data": {"data": [...], ...}} + if "data" in result and isinstance(result["data"], dict): + products = result["data"].get("data", []) + else: + products = result.get("list", []) total = result.get("total", 0) # 格式化商品数据