@@ -10,19 +10,18 @@ import {
1010
1111const WEBFLOW_API_BASE = "https://api.webflow.com" ;
1212
13- async function listWorkflows ( arg : {
14- site_id : string ;
15- token : string ;
16- } ) : Promise < unknown > {
17- const response = await fetch (
18- `${ WEBFLOW_API_BASE } /v2/sites/${ arg . site_id } /workflows` ,
19- {
20- headers : {
21- Authorization : `Bearer ${ arg . token } ` ,
22- ...requestOptions . headers ,
23- } ,
24- }
25- ) ;
13+ async function apiRequest (
14+ method : string ,
15+ path : string ,
16+ token : string
17+ ) : Promise < unknown > {
18+ const response = await fetch ( `${ WEBFLOW_API_BASE } ${ path } ` , {
19+ method,
20+ headers : {
21+ Authorization : `Bearer ${ token } ` ,
22+ ...requestOptions . headers ,
23+ } ,
24+ } ) ;
2625
2726 if ( ! response . ok ) {
2827 const error = await response . json ( ) . catch ( ( ) => ( { } ) ) ;
@@ -45,11 +44,11 @@ export function registerWorkflowsTools(
4544 {
4645 title : "Data Workflows Tool" ,
4746 annotations : {
48- readOnlyHint : true ,
47+ readOnlyHint : false ,
4948 openWorldHint : false ,
5049 } ,
5150 description :
52- "Data tool - Workflows tool to perform actions like listing AI workflows configured for a site ." ,
51+ "Data tool - Workflows tool to list AI workflows, execute a workflow, and poll execution status ." ,
5352 inputSchema : {
5453 actions : z . array (
5554 z
@@ -65,11 +64,50 @@ export function registerWorkflowsTools(
6564 . describe (
6665 "List all AI workflows configured for a site. Returns each workflow's ID, name, active status, and template slug."
6766 ) ,
67+ // POST https://api.webflow.com/v2/sites/:site_id/workflows/:workflow_id/execute
68+ execute_workflow : z
69+ . object ( {
70+ site_id : z
71+ . string ( )
72+ . describe ( "Unique identifier for the site." ) ,
73+ workflow_id : z
74+ . string ( )
75+ . describe ( "Unique identifier for the workflow to execute." ) ,
76+ } )
77+ . optional ( )
78+ . describe (
79+ "Execute an AI workflow. The workflow must be active. Returns an execution_id to poll with get_workflow_execution_status."
80+ ) ,
81+ // GET https://api.webflow.com/v2/sites/:site_id/workflows/executions/:execution_id
82+ get_workflow_execution_status : z
83+ . object ( {
84+ site_id : z
85+ . string ( )
86+ . describe ( "Unique identifier for the site." ) ,
87+ execution_id : z
88+ . string ( )
89+ . describe (
90+ "Execution ID returned by execute_workflow. Poll until isFinished is true."
91+ ) ,
92+ } )
93+ . optional ( )
94+ . describe (
95+ "Get the status of a workflow execution. Returns status, start/stop times, and isFinished."
96+ ) ,
6897 } )
6998 . strict ( )
70- . refine ( ( d ) => [ d . list_workflows ] . filter ( Boolean ) . length >= 1 , {
71- message : "Provide at least one of list_workflows." ,
72- } )
99+ . refine (
100+ ( d ) =>
101+ [
102+ d . list_workflows ,
103+ d . execute_workflow ,
104+ d . get_workflow_execution_status ,
105+ ] . filter ( Boolean ) . length >= 1 ,
106+ {
107+ message :
108+ "Provide at least one of list_workflows, execute_workflow, get_workflow_execution_status." ,
109+ }
110+ )
73111 ) ,
74112 } ,
75113 } ,
@@ -78,10 +116,27 @@ export function registerWorkflowsTools(
78116 try {
79117 for ( const action of actions ) {
80118 if ( action . list_workflows ) {
81- const content = await listWorkflows ( {
82- site_id : action . list_workflows . site_id ,
83- token : getToken ( ) ,
84- } ) ;
119+ const content = await apiRequest (
120+ "GET" ,
121+ `/v2/sites/${ action . list_workflows . site_id } /workflows` ,
122+ getToken ( )
123+ ) ;
124+ result . push ( textContent ( content ) ) ;
125+ }
126+ if ( action . execute_workflow ) {
127+ const content = await apiRequest (
128+ "POST" ,
129+ `/v2/sites/${ action . execute_workflow . site_id } /workflows/${ action . execute_workflow . workflow_id } /execute` ,
130+ getToken ( )
131+ ) ;
132+ result . push ( textContent ( content ) ) ;
133+ }
134+ if ( action . get_workflow_execution_status ) {
135+ const content = await apiRequest (
136+ "GET" ,
137+ `/v2/sites/${ action . get_workflow_execution_status . site_id } /workflows/executions/${ action . get_workflow_execution_status . execution_id } ` ,
138+ getToken ( )
139+ ) ;
85140 result . push ( textContent ( content ) ) ;
86141 }
87142 }
0 commit comments