Skip to content

Commit 8d9a2df

Browse files
committed
feat: add reload_workflows tool
1 parent c640d73 commit 8d9a2df

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

src/workflows_mcp/tools.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
format_workflow_list_markdown,
2626
format_workflow_not_found_error,
2727
)
28-
from .server import mcp
28+
from .server import load_workflows, mcp
2929

3030
# =============================================================================
3131
# MCP Tools (following official SDK decorator pattern)
@@ -496,6 +496,45 @@ async def validate_workflow_yaml(
496496
}
497497

498498

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+
499538
# =============================================================================
500539
# Checkpoint Management Tools
501540
# =============================================================================

tests/reproduce_resolver.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import asyncio
2-
import sys
32
import os
4-
from datetime import datetime
3+
import sys
54

65
# Add src to path
76
sys.path.append(os.path.join(os.getcwd(), "src"))
87

8+
from workflows_mcp.engine.resolver.classifier import ExpressionClassifier
99
from workflows_mcp.engine.resolver.unified_resolver import UnifiedVariableResolver
10-
from workflows_mcp.engine.resolver.classifier import ExpressionClassifier, ExpressionType
1110

1211

1312
async def run_test():
@@ -62,7 +61,7 @@ async def run_test():
6261

6362
# Test 3: Pass a dict that contains the expression (simulating Block Definition Inputs)
6463
# The WorkflowRunner iterates over inputs and resolves them.
65-
print(f"\nTest 3: Simulating block definition inputs")
64+
print("\nTest 3: Simulating block definition inputs")
6665
block_inputs = {
6766
"features": "{{ inputs.features }}",
6867
"nested": {"prop": "{{ inputs.features.dual_track_enabled }}"},

0 commit comments

Comments
 (0)