|
| 1 | +import logging |
| 2 | +from pathlib import Path |
| 3 | + |
| 4 | +from .orchestrator_service import orchestrator_mcp |
| 5 | + |
| 6 | +logger = logging.getLogger(__name__) |
| 7 | + |
| 8 | +SERVERLESS_JSON_PATH = "serverless-workflow/consolidated_workflow_schema.json" |
| 9 | + |
| 10 | +# Cache for schema content |
| 11 | +_schema_cache = None |
| 12 | + |
| 13 | + |
| 14 | +@orchestrator_mcp.tool() |
| 15 | +def get_schema_rules(session_id: str) -> str: |
| 16 | + """ |
| 17 | + Retrieve the complete orchestrator workflow schema for orchestrator operations. |
| 18 | +
|
| 19 | + This tool returns the full consolidated workflow schema from the orchestrator-workflow |
| 20 | + specification. Use this when you need to understand the complete schema structure, |
| 21 | + validate workflow definitions, or reference specific schema components. |
| 22 | +
|
| 23 | + Args: |
| 24 | + session_id (str): Session identifier for logging and tracking purposes |
| 25 | +
|
| 26 | + Returns: |
| 27 | + str: Complete JSON schema as a string, or error message if schema cannot be loaded |
| 28 | +
|
| 29 | + Note: |
| 30 | + Only request this when you need schema validation or have specific questions |
| 31 | + about the workflow structure, as it returns the entire schema document. |
| 32 | + """ # noqa: E501 |
| 33 | + global _schema_cache |
| 34 | + |
| 35 | + logger.info(f"get_filtered_schema_rules for session_id='{session_id}'") |
| 36 | + |
| 37 | + # Return cached content if available |
| 38 | + if _schema_cache is not None: |
| 39 | + return _schema_cache |
| 40 | + |
| 41 | + # Load and cache the schema |
| 42 | + input_path = Path(SERVERLESS_JSON_PATH) |
| 43 | + if not input_path.exists(): |
| 44 | + return "Error: cannot load the orchestrator-workflow schema" |
| 45 | + |
| 46 | + try: |
| 47 | + with open(input_path, "r", encoding="utf-8") as f: |
| 48 | + _schema_cache = f.read() |
| 49 | + return _schema_cache |
| 50 | + except Exception as e: |
| 51 | + logger.error(f"Error reading schema file: {e}") |
| 52 | + return "Error: cannot read the orchestrator-workflow schema" |
0 commit comments