File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed
Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -133,6 +133,55 @@ server.tool(
133133 }
134134) ;
135135
136+ server . tool (
137+ "cancel-run" ,
138+ "Cancel an in-progress run. Runs that have already completed cannot be cancelled." ,
139+ {
140+ runId : z . string ( ) . describe ( "The ID of the task run to cancel" ) ,
141+ } ,
142+ async ( { runId } ) => {
143+ const run = await sdkApiClient . retrieveRun ( runId ) ;
144+
145+ if ( run ?. status === "COMPLETED" ) {
146+ return {
147+ content : [
148+ {
149+ type : "text" ,
150+ text : JSON . stringify (
151+ { message : "This run is already completed, no action taken." , run } ,
152+ null ,
153+ 2
154+ ) ,
155+ } ,
156+ ] ,
157+ } ;
158+ }
159+
160+ await sdkApiClient . cancelRun ( runId ) ;
161+ // we could also skip fetching the run again, but it provides more context to the LLM
162+ // and one extra API call is no big deal
163+ const updatedRun = await sdkApiClient . retrieveRun ( runId ) ;
164+
165+ return {
166+ content : [
167+ {
168+ type : "text" ,
169+ text : JSON . stringify (
170+ {
171+ message : "Task run was cancelled" ,
172+ previousStatus : run . status ,
173+ currentStatus : updatedRun . status ,
174+ updatedTaskRun : updatedRun ,
175+ } ,
176+ null ,
177+ 2
178+ ) ,
179+ } ,
180+ ] ,
181+ } ;
182+ }
183+ ) ;
184+
136185const app = polka ( ) ;
137186app . get ( "/sse" , ( _req , res ) => {
138187 mcpTransport = new SSEServerTransport ( "/messages" , res ) ;
You can’t perform that action at this time.
0 commit comments