Skip to content

Commit a50d661

Browse files
committed
Adding approval workflow for policies
1 parent f841741 commit a50d661

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

modelcontextprotocol/server.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ def search_assets_tool(
3232
domain_guids=None,
3333
date_range=None,
3434
guids=None,
35+
workflow_run_type=None,
36+
workflow_run_status=None,
37+
include_attributes_extra=None,
3538
):
3639
"""
3740
Advanced asset search using FluentSearch with flexible conditions.
@@ -60,6 +63,10 @@ def search_assets_tool(
6063
date_range (Dict[str, Dict[str, Any]], optional): Date range filters.
6164
Format: {"attribute_name": {"gte": start_timestamp, "lte": end_timestamp}}
6265
guids (List[str], optional): List of asset GUIDs to filter by.
66+
workflow_run_type (str, optional): Workflow run type to filter by.
67+
workflow_run_status (str, optional): Workflow run status to filter by.
68+
include_attributes_extra (Dict[str, str], optional): Additional attributes to include in results.
69+
Format: {"asset_type": "attribute_name"}
6370
6471
Returns:
6572
List[Asset]: List of assets matching the search criteria
@@ -154,6 +161,14 @@ def search_assets_tool(
154161
}
155162
)
156163
164+
# get business policy that are pending for approval, here the attribute workflow_run_on_asset_guid is the business policy guid that should be used to fetch the business policy details
165+
assets = search_assets(
166+
"asset_type"="WorkflowRun",
167+
"workflow_run_type"="POLICY",
168+
"workflow_run_status"="PENDING",
169+
include_attributes_extra={"WorkflowRun": "workflow_run_on_asset_guid"}
170+
)
171+
157172
"""
158173
return search_assets(
159174
conditions,
@@ -173,6 +188,9 @@ def search_assets_tool(
173188
domain_guids,
174189
date_range,
175190
guids,
191+
workflow_run_type,
192+
workflow_run_status,
193+
include_attributes_extra,
176194
)
177195

178196

modelcontextprotocol/tools/search.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pyatlan.model.assets import Asset
77
from pyatlan.model.fluent_search import CompoundQuery, FluentSearch
88
from pyatlan.model.fields.atlan_fields import AtlanField
9+
from pyatlan.model.assets.workflow_run import WorkflowRun
910

1011
# Configure logging
1112
logger = logging.getLogger(__name__)
@@ -29,6 +30,9 @@ def search_assets(
2930
domain_guids: Optional[List[str]] = None,
3031
date_range: Optional[Dict[str, Dict[str, Any]]] = None,
3132
guids: Optional[List[str]] = None,
33+
workflow_run_type: Optional[str] = None,
34+
workflow_run_status: Optional[str] = None,
35+
include_attributes_extra: Optional[Dict[str, str]] = None,
3236
) -> List[Asset]:
3337
"""
3438
Advanced asset search using FluentSearch with flexible conditions.
@@ -57,7 +61,10 @@ def search_assets(
5761
date_range (Dict[str, Dict[str, Any]], optional): Date range filters.
5862
Format: {"attribute_name": {"gte": start_timestamp, "lte": end_timestamp}}
5963
guids (List[str], optional): List of GUIDs to filter by.
60-
64+
workflow_run_type (str, optional): Workflow run type to filter by.
65+
workflow_run_status (str, optional): Workflow run status to filter by.
66+
include_attributes_extra (Dict[str, str], optional): Additional attributes to include in results.
67+
Format: {"asset_type": "attribute_name"}
6168
6269
Returns:
6370
List[Asset]: List of assets matching the search criteria
@@ -107,6 +114,18 @@ def search_assets(
107114
Asset.QUALIFIED_NAME.startswith(connection_qualified_name)
108115
)
109116

117+
# Apply workflow run type filter if provided
118+
if workflow_run_type:
119+
logger.debug(f"Filtering by workflow run type: {workflow_run_type}")
120+
search = search.where(WorkflowRun.WORKFLOW_RUN_TYPE.eq(workflow_run_type))
121+
122+
# Apply workflow run status filter if provided
123+
if workflow_run_status:
124+
logger.debug(f"Filtering by workflow run status: {workflow_run_status}")
125+
search = search.where(
126+
WorkflowRun.WORKFLOW_RUN_STATUS.eq(workflow_run_status)
127+
)
128+
110129
# Apply tags filter if provided
111130
if tags and len(tags) > 0:
112131
logger.debug(
@@ -342,6 +361,14 @@ def search_assets(
342361

343362
logger.debug(f"Included {included_count} attributes in results")
344363

364+
if include_attributes_extra:
365+
for asset_type, attr_type in include_attributes_extra.items():
366+
if asset_type == "WorkflowRun":
367+
attr_obj = getattr(WorkflowRun, attr_type.upper(), None)
368+
search = search.include_on_results(attr_obj)
369+
else:
370+
logger.warning(f"Unknown attribute for inclusion: {attr}, skipping")
371+
345372
# Set pagination
346373
logger.debug(f"Setting pagination: limit={limit}, offset={offset}")
347374
search = search.page_size(limit)

0 commit comments

Comments
 (0)