Spaces:
Running
Running
Ali Hmaou commited on
Commit ·
8523d41
1
Parent(s): a1c243a
Version 1
Browse files- src/mcp_server/server.py +37 -2
src/mcp_server/server.py
CHANGED
|
@@ -302,11 +302,44 @@ with gr.Blocks(title="Meta-MCP Fractal") as demo:
|
|
| 302 |
# Mise à jour du résumé quand le draft_id change
|
| 303 |
draft_id_deploy.change(update_deployment_summary, inputs=[draft_id_deploy], outputs=[deployment_summary], api_name=False)
|
| 304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
btn_deploy.click(
|
| 306 |
step_3_deployment,
|
| 307 |
inputs=[draft_id_deploy],
|
| 308 |
outputs=out_deploy,
|
| 309 |
api_name="step_3_deployment"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 310 |
)
|
| 311 |
|
| 312 |
# Câblage global des événements (une fois tous les composants définis)
|
|
@@ -319,7 +352,8 @@ with gr.Blocks(title="Meta-MCP Fractal") as demo:
|
|
| 319 |
).then(
|
| 320 |
fn=lambda x: x,
|
| 321 |
inputs=[draft_id_logic],
|
| 322 |
-
outputs=[draft_id_deploy]
|
|
|
|
| 323 |
)
|
| 324 |
|
| 325 |
with gr.Tab("4. Test & Playground (Smolagents)"):
|
|
@@ -344,7 +378,8 @@ with gr.Blocks(title="Meta-MCP Fractal") as demo:
|
|
| 344 |
btn_reload.click(
|
| 345 |
fn=reload_tools_handler,
|
| 346 |
inputs=[mcp_url_input],
|
| 347 |
-
outputs=[tool_table, status_msg]
|
|
|
|
| 348 |
)
|
| 349 |
|
| 350 |
# Exposition explicite des outils pour les agents MCP sans UI
|
|
|
|
| 302 |
# Mise à jour du résumé quand le draft_id change
|
| 303 |
draft_id_deploy.change(update_deployment_summary, inputs=[draft_id_deploy], outputs=[deployment_summary], api_name=False)
|
| 304 |
|
| 305 |
+
# Fonction pour extraire l'URL MCP directe et préremplir le playground
|
| 306 |
+
def auto_fill_playground(deploy_result):
|
| 307 |
+
if not deploy_result or "url" not in deploy_result:
|
| 308 |
+
return gr.update()
|
| 309 |
+
|
| 310 |
+
# L'URL retournée est de la forme https://huggingface.co/spaces/USER/SPACE
|
| 311 |
+
# On veut https://USER-SPACE.hf.space/gradio_api/mcp/
|
| 312 |
+
hf_url = deploy_result["url"]
|
| 313 |
+
|
| 314 |
+
try:
|
| 315 |
+
# Extraction user et space
|
| 316 |
+
if "huggingface.co/spaces/" in hf_url:
|
| 317 |
+
parts = hf_url.split("huggingface.co/spaces/")
|
| 318 |
+
if len(parts) > 1:
|
| 319 |
+
path = parts[1].strip("/")
|
| 320 |
+
if "/" in path:
|
| 321 |
+
user, space = path.split("/", 1)
|
| 322 |
+
# Format direct url : https://user-space.hf.space
|
| 323 |
+
# Note: le nom du space dans l'url doit être en minuscules et les _ deviennent - parfois, mais HF gère la redirection souvent.
|
| 324 |
+
# Pour être sûr, on garde la structure simple.
|
| 325 |
+
direct_url = f"https://{user}-{space}.hf.space/gradio_api/mcp/"
|
| 326 |
+
return direct_url
|
| 327 |
+
except:
|
| 328 |
+
pass
|
| 329 |
+
|
| 330 |
+
# Fallback si parsing échoue
|
| 331 |
+
return hf_url
|
| 332 |
+
|
| 333 |
btn_deploy.click(
|
| 334 |
step_3_deployment,
|
| 335 |
inputs=[draft_id_deploy],
|
| 336 |
outputs=out_deploy,
|
| 337 |
api_name="step_3_deployment"
|
| 338 |
+
).then(
|
| 339 |
+
fn=auto_fill_playground,
|
| 340 |
+
inputs=[out_deploy],
|
| 341 |
+
outputs=[mcp_url_input],
|
| 342 |
+
api_name=False
|
| 343 |
)
|
| 344 |
|
| 345 |
# Câblage global des événements (une fois tous les composants définis)
|
|
|
|
| 352 |
).then(
|
| 353 |
fn=lambda x: x,
|
| 354 |
inputs=[draft_id_logic],
|
| 355 |
+
outputs=[draft_id_deploy],
|
| 356 |
+
api_name=False # Internal logic only
|
| 357 |
)
|
| 358 |
|
| 359 |
with gr.Tab("4. Test & Playground (Smolagents)"):
|
|
|
|
| 378 |
btn_reload.click(
|
| 379 |
fn=reload_tools_handler,
|
| 380 |
inputs=[mcp_url_input],
|
| 381 |
+
outputs=[tool_table, status_msg],
|
| 382 |
+
api_name=False # Hide internal tool
|
| 383 |
)
|
| 384 |
|
| 385 |
# Exposition explicite des outils pour les agents MCP sans UI
|