Philippe commited on
Commit
39b89ab
·
1 Parent(s): d76a30d

­ƒñû Ajout Browser MCP - Navigation web intelligente

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -310,7 +310,7 @@ async def send_message(sid, data):
310
  return
311
 
312
  # 🤖 Détecter les commandes Browser MCP
313
- if text.startswith("/browse ") or text.startswith("/web "):
314
  await handle_browser_command(sid, room, name, text)
315
  return
316
 
@@ -334,9 +334,10 @@ async def handle_browser_command(sid: str, room: str, name: str, text: str):
334
  args = parts[2] if len(parts) > 2 else ""
335
 
336
  try:
337
- if command.startswith("http"):
338
- # Navigation vers URL
339
- result = await browser_mcp.call_tool("navigate_to_url", {"url": command})
 
340
 
341
  # Auto-capture d'écran après navigation
342
  if "✅" in result:
@@ -383,14 +384,14 @@ async def handle_browser_command(sid: str, room: str, name: str, text: str):
383
 
384
  elif command == "help":
385
  result = """🌐 **Commandes Browser MCP disponibles:**
386
- • `/browse <url>` - Naviguer vers une URL
387
  • `/web screenshot` - Capture d'écran
388
  • `/web text [selector]` - Extraire le texte
389
  • `/web click <selector>` - Cliquer sur un élément
390
  • `/web fill <selector>=<value>` - Remplir un champ
391
  • `/web info` - Infos de la page
392
  • `/web search <text>` - Rechercher du texte
393
- • `/web links` - Extraire les liens
394
  • `/web wait <selector>` - Attendre un élément
395
  • `/web help` - Cette aide"""
396
 
@@ -398,7 +399,10 @@ async def handle_browser_command(sid: str, room: str, name: str, text: str):
398
  result = f"❌ Commande inconnue: {command}. Tapez '/web help' pour l'aide."
399
 
400
  except Exception as e:
401
- result = f"❌ Erreur Browser MCP: {str(e)}"
 
 
 
402
 
403
  # Envoyer la réponse
404
  response_msg = {"type": "message", "name": "🤖 Browser", "text": result, "ts": time.time()}
 
310
  return
311
 
312
  # 🤖 Détecter les commandes Browser MCP
313
+ if text.startswith("/browse ") or text.startswith("/browser ") or text.startswith("/web "):
314
  await handle_browser_command(sid, room, name, text)
315
  return
316
 
 
334
  args = parts[2] if len(parts) > 2 else ""
335
 
336
  try:
337
+ if command.startswith("http") or text.startswith("/browser "):
338
+ # Navigation vers URL (supporter /browser et /browse)
339
+ url = command if command.startswith("http") else command
340
+ result = await browser_mcp.call_tool("navigate_to_url", {"url": url})
341
 
342
  # Auto-capture d'écran après navigation
343
  if "✅" in result:
 
384
 
385
  elif command == "help":
386
  result = """🌐 **Commandes Browser MCP disponibles:**
387
+ • `/browse <url>` ou `/browser <url>` - Naviguer vers une URL
388
  • `/web screenshot` - Capture d'écran
389
  • `/web text [selector]` - Extraire le texte
390
  • `/web click <selector>` - Cliquer sur un élément
391
  • `/web fill <selector>=<value>` - Remplir un champ
392
  • `/web info` - Infos de la page
393
  • `/web search <text>` - Rechercher du texte
394
+ • `/web links` - Extrairer les liens
395
  • `/web wait <selector>` - Attendre un élément
396
  • `/web help` - Cette aide"""
397
 
 
399
  result = f"❌ Commande inconnue: {command}. Tapez '/web help' pour l'aide."
400
 
401
  except Exception as e:
402
+ import traceback
403
+ error_details = traceback.format_exc()
404
+ print(f"❌ Browser MCP Error: {error_details}")
405
+ result = f"❌ Erreur lors de l'appel MCP: {str(e)}"
406
 
407
  # Envoyer la réponse
408
  response_msg = {"type": "message", "name": "🤖 Browser", "text": result, "ts": time.time()}