@@ -49,6 +49,7 @@ impl OperationDescriptor {
4949 self
5050 }
5151
52+ /// Time-to-live in milliseconds, matching `TaskMetadata.ttl` from the MCP spec.
5253 pub fn with_ttl ( mut self , ttl : u64 ) -> Self {
5354 self . ttl = Some ( ttl) ;
5455 self
@@ -75,7 +76,11 @@ pub trait OperationResultTransport: Send + Sync + 'static {
7576}
7677
7778// ===== Operation Processor =====
78- pub const DEFAULT_TASK_TIMEOUT_SECS : u64 = 300 ; // 5 minutes
79+ #[ deprecated( note = "use DEFAULT_TASK_TIMEOUT_MS; ttl values are milliseconds per the MCP spec" ) ]
80+ pub const DEFAULT_TASK_TIMEOUT_SECS : u64 = 300 ;
81+ /// Default execution timeout (5 minutes), in milliseconds, applied when a
82+ /// descriptor does not specify a `ttl`.
83+ pub const DEFAULT_TASK_TIMEOUT_MS : u64 = 300_000 ;
7984/// Operation processor that coordinates extractors and handlers
8085pub struct OperationProcessor {
8186 /// Currently running tasks keyed by id
@@ -165,13 +170,13 @@ impl OperationProcessor {
165170 fn spawn_async_task ( & mut self , message : OperationMessage ) {
166171 let OperationMessage { descriptor, future } = message;
167172 let task_id = descriptor. operation_id . clone ( ) ;
168- let timeout_secs = descriptor. ttl . or ( Some ( DEFAULT_TASK_TIMEOUT_SECS ) ) ;
173+ let timeout_ms = descriptor. ttl . or ( Some ( DEFAULT_TASK_TIMEOUT_MS ) ) ;
169174 let sender = self . task_result_sender . clone ( ) ;
170175 let descriptor_for_result = descriptor. clone ( ) ;
171176
172177 let timed_future = async move {
173- if let Some ( secs ) = timeout_secs {
174- match timeout ( Duration :: from_secs ( secs ) , future) . await {
178+ if let Some ( ms ) = timeout_ms {
179+ match timeout ( Duration :: from_millis ( ms ) , future) . await {
175180 Ok ( result) => result,
176181 Err ( _) => Err ( Error :: TaskError ( "Operation timed out" . to_string ( ) ) ) ,
177182 }
@@ -191,7 +196,7 @@ impl OperationProcessor {
191196 let running_task = RunningTask {
192197 task_handle : handle,
193198 started_at : std:: time:: Instant :: now ( ) ,
194- timeout : timeout_secs ,
199+ timeout : timeout_ms ,
195200 descriptor,
196201 } ;
197202 self . running_tasks . insert ( task_id, running_task) ;
@@ -213,7 +218,7 @@ impl OperationProcessor {
213218
214219 for ( task_id, task) in & self . running_tasks {
215220 if let Some ( timeout_duration) = task. timeout {
216- if now. duration_since ( task. started_at ) . as_secs ( ) > timeout_duration {
221+ if now. duration_since ( task. started_at ) . as_millis ( ) > u128 :: from ( timeout_duration) {
217222 task. task_handle . abort ( ) ;
218223 timed_out_tasks. push ( task_id. clone ( ) ) ;
219224 }
0 commit comments