@@ -35,6 +35,44 @@ async function apiRequest(
3535 return response . json ( ) ;
3636}
3737
38+ async function handleWorkflowActions (
39+ actions : Array < {
40+ list_workflows ?: { site_id : string } ;
41+ execute_workflow ?: { site_id : string ; workflow_id : string } ;
42+ get_workflow_execution_status ?: { site_id : string ; execution_id : string } ;
43+ } > ,
44+ getToken : ( ) => string
45+ ) : Promise < Content [ ] > {
46+ const result : Content [ ] = [ ] ;
47+ for ( const action of actions ) {
48+ if ( action . list_workflows ) {
49+ const content = await apiRequest (
50+ "GET" ,
51+ `/v2/sites/${ action . list_workflows . site_id } /workflows` ,
52+ getToken ( )
53+ ) ;
54+ result . push ( textContent ( content ) ) ;
55+ }
56+ if ( action . execute_workflow ) {
57+ const content = await apiRequest (
58+ "POST" ,
59+ `/v2/sites/${ action . execute_workflow . site_id } /workflows/${ action . execute_workflow . workflow_id } /execute` ,
60+ getToken ( )
61+ ) ;
62+ result . push ( textContent ( content ) ) ;
63+ }
64+ if ( action . get_workflow_execution_status ) {
65+ const content = await apiRequest (
66+ "GET" ,
67+ `/v2/sites/${ action . get_workflow_execution_status . site_id } /workflows/executions/${ action . get_workflow_execution_status . execution_id } ` ,
68+ getToken ( )
69+ ) ;
70+ result . push ( textContent ( content ) ) ;
71+ }
72+ }
73+ return result ;
74+ }
75+
3876export function registerWorkflowsTools (
3977 server : McpServer ,
4078 getToken : ( ) => string
@@ -112,34 +150,8 @@ export function registerWorkflowsTools(
112150 } ,
113151 } ,
114152 async ( { actions } ) => {
115- const result : Content [ ] = [ ] ;
116153 try {
117- for ( const action of actions ) {
118- if ( action . list_workflows ) {
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- ) ;
140- result . push ( textContent ( content ) ) ;
141- }
142- }
154+ const result = await handleWorkflowActions ( actions , getToken ) ;
143155 return toolResponse ( result ) ;
144156 } catch ( error ) {
145157 return formatErrorResponse ( error ) ;
0 commit comments