|
25 | 25 | format_workflow_list_markdown, |
26 | 26 | format_workflow_not_found_error, |
27 | 27 | ) |
28 | | -from .server import mcp |
| 28 | +from .server import load_workflows, mcp |
29 | 29 |
|
30 | 30 | # ============================================================================= |
31 | 31 | # MCP Tools (following official SDK decorator pattern) |
@@ -496,6 +496,45 @@ async def validate_workflow_yaml( |
496 | 496 | } |
497 | 497 |
|
498 | 498 |
|
| 499 | +@mcp.tool( |
| 500 | + annotations=ToolAnnotations( |
| 501 | + title="Reload Workflows", |
| 502 | + readOnlyHint=False, # Modifies server state (registry) |
| 503 | + destructiveHint=False, |
| 504 | + idempotentHint=True, # Repeated calls have same effect |
| 505 | + openWorldHint=False, |
| 506 | + ) |
| 507 | +) |
| 508 | +async def reload_workflows( |
| 509 | + *, |
| 510 | + ctx: AppContextType, |
| 511 | +) -> dict[str, Any]: |
| 512 | + """Reload all workflows from disk (built-in and user templates).""" |
| 513 | + # Access shared resources from lifespan context |
| 514 | + if ctx is None: |
| 515 | + return { |
| 516 | + "status": "failure", |
| 517 | + "message": "Server context not available.", |
| 518 | + } |
| 519 | + |
| 520 | + app_ctx = ctx.request_context.lifespan_context |
| 521 | + registry = app_ctx.registry |
| 522 | + |
| 523 | + try: |
| 524 | + load_workflows(registry) |
| 525 | + except Exception as e: |
| 526 | + return { |
| 527 | + "status": "failure", |
| 528 | + "message": f"Failed to reload workflows: {str(e)}", |
| 529 | + } |
| 530 | + |
| 531 | + return { |
| 532 | + "status": "success", |
| 533 | + "message": "Successfully reloaded workflows", |
| 534 | + "total": len(registry.list_names()), |
| 535 | + } |
| 536 | + |
| 537 | + |
499 | 538 | # ============================================================================= |
500 | 539 | # Checkpoint Management Tools |
501 | 540 | # ============================================================================= |
|
0 commit comments