Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ModelContextProtocol.Core/Protocol/CreateTaskResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public sealed class CreateTaskResult : Result
/// Gets or sets the time-to-live duration from creation in milliseconds, or <see langword="null"/> for unlimited.
/// </summary>
[JsonPropertyName("ttlMs")]
public long? TtlMs { get; set; }
public long? TimeToLiveMs { get; set; }
Comment thread
PranavSenthilnathan marked this conversation as resolved.
Outdated

/// <summary>
/// Gets or sets the suggested polling interval in milliseconds.
Expand Down
8 changes: 4 additions & 4 deletions src/ModelContextProtocol.Core/Protocol/GetTaskResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private protected GetTaskResult()
/// Gets or sets the time-to-live duration from creation in milliseconds, or <see langword="null"/> for unlimited.
/// </summary>
[JsonPropertyName("ttlMs")]
public long? TtlMs { get; set; }
public long? TimeToLiveMs { get; set; }

/// <summary>
/// Gets or sets the suggested polling interval in milliseconds.
Expand Down Expand Up @@ -245,7 +245,7 @@ internal sealed class Converter : JsonConverter<GetTaskResult>
};

taskResult.StatusMessage = statusMessage;
taskResult.TtlMs = ttlMs;
taskResult.TimeToLiveMs = ttlMs;
taskResult.PollIntervalMs = pollIntervalMs;
taskResult.ResultType = resultType;
taskResult.Meta = meta;
Expand Down Expand Up @@ -287,9 +287,9 @@ public override void Write(Utf8JsonWriter writer, GetTaskResult value, JsonSeria
writer.WriteString("createdAt", value.CreatedAt);
writer.WriteString("lastUpdatedAt", value.LastUpdatedAt);

if (value.TtlMs is not null)
if (value.TimeToLiveMs is not null)
{
writer.WriteNumber("ttlMs", value.TtlMs.Value);
writer.WriteNumber("ttlMs", value.TimeToLiveMs.Value);
}

if (value.PollIntervalMs is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private protected TaskStatusNotificationParams()
/// Gets or sets the time-to-live duration from creation in milliseconds, or <see langword="null"/> for unlimited.
/// </summary>
[JsonPropertyName("ttlMs")]
public long? TtlMs { get; set; }
public long? TimeToLiveMs { get; set; }

/// <summary>
/// Gets or sets the suggested polling interval in milliseconds.
Expand Down Expand Up @@ -247,7 +247,7 @@ internal sealed class Converter : JsonConverter<TaskStatusNotificationParams>
};

notification.StatusMessage = statusMessage;
notification.TtlMs = ttlMs;
notification.TimeToLiveMs = ttlMs;
notification.PollIntervalMs = pollIntervalMs;
notification.Meta = meta;

Expand Down Expand Up @@ -283,9 +283,9 @@ public override void Write(Utf8JsonWriter writer, TaskStatusNotificationParams v
writer.WriteString("createdAt", value.CreatedAt);
writer.WriteString("lastUpdatedAt", value.LastUpdatedAt);

if (value.TtlMs is not null)
if (value.TimeToLiveMs is not null)
{
writer.WriteNumber("ttlMs", value.TtlMs.Value);
writer.WriteNumber("ttlMs", value.TimeToLiveMs.Value);
}

if (value.PollIntervalMs is not null)
Expand Down
4 changes: 2 additions & 2 deletions src/ModelContextProtocol.Core/Server/InMemoryMcpTaskStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ public class InMemoryMcpTaskStore : IMcpTaskStore
/// <summary>
/// Gets or sets the default time-to-live in milliseconds for new tasks, or <see langword="null"/> for unlimited.
/// </summary>
public long? DefaultTtlMs { get; set; }
public long? DefaultTimeToLiveMs { get; set; }

/// <inheritdoc/>
public Task<McpTaskInfo> CreateTaskAsync(CancellationToken cancellationToken = default)
{
var taskId = Guid.NewGuid().ToString("N");
var now = DateTimeOffset.UtcNow;

var info = new McpTaskInfo(taskId, McpTaskStatus.Working, now, now, DefaultTtlMs, DefaultPollIntervalMs);
var info = new McpTaskInfo(taskId, McpTaskStatus.Working, now, now, DefaultTimeToLiveMs, DefaultPollIntervalMs);
_tasks[taskId] = info;

return Task.FromResult(info);
Expand Down
12 changes: 6 additions & 6 deletions src/ModelContextProtocol.Core/Server/McpServerImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ await originalListToolsHandler(request, cancellationToken).ConfigureAwait(false)
Status = info.Status,
CreatedAt = info.CreatedAt,
LastUpdatedAt = info.LastUpdatedAt,
TtlMs = info.TtlMs,
TimeToLiveMs = info.TimeToLiveMs,
PollIntervalMs = info.PollIntervalMs,
StatusMessage = info.StatusMessage,
ResultType = "task",
Expand All @@ -1022,7 +1022,7 @@ await originalListToolsHandler(request, cancellationToken).ConfigureAwait(false)
TaskId = info.TaskId,
CreatedAt = info.CreatedAt,
LastUpdatedAt = info.LastUpdatedAt,
TtlMs = info.TtlMs,
TimeToLiveMs = info.TimeToLiveMs,
PollIntervalMs = info.PollIntervalMs,
StatusMessage = info.StatusMessage,
ResultType = "complete",
Expand All @@ -1032,7 +1032,7 @@ await originalListToolsHandler(request, cancellationToken).ConfigureAwait(false)
TaskId = info.TaskId,
CreatedAt = info.CreatedAt,
LastUpdatedAt = info.LastUpdatedAt,
TtlMs = info.TtlMs,
TimeToLiveMs = info.TimeToLiveMs,
PollIntervalMs = info.PollIntervalMs,
StatusMessage = info.StatusMessage,
Result = info.Result ?? throw new InvalidOperationException($"Task '{info.TaskId}' is completed but has no result."),
Expand All @@ -1043,7 +1043,7 @@ await originalListToolsHandler(request, cancellationToken).ConfigureAwait(false)
TaskId = info.TaskId,
CreatedAt = info.CreatedAt,
LastUpdatedAt = info.LastUpdatedAt,
TtlMs = info.TtlMs,
TimeToLiveMs = info.TimeToLiveMs,
PollIntervalMs = info.PollIntervalMs,
StatusMessage = info.StatusMessage,
Error = info.Error ?? throw new InvalidOperationException($"Task '{info.TaskId}' is failed but has no error."),
Expand All @@ -1054,7 +1054,7 @@ await originalListToolsHandler(request, cancellationToken).ConfigureAwait(false)
TaskId = info.TaskId,
CreatedAt = info.CreatedAt,
LastUpdatedAt = info.LastUpdatedAt,
TtlMs = info.TtlMs,
TimeToLiveMs = info.TimeToLiveMs,
PollIntervalMs = info.PollIntervalMs,
StatusMessage = info.StatusMessage,
ResultType = "complete",
Expand All @@ -1064,7 +1064,7 @@ await originalListToolsHandler(request, cancellationToken).ConfigureAwait(false)
TaskId = info.TaskId,
CreatedAt = info.CreatedAt,
LastUpdatedAt = info.LastUpdatedAt,
TtlMs = info.TtlMs,
TimeToLiveMs = info.TimeToLiveMs,
PollIntervalMs = info.PollIntervalMs,
StatusMessage = info.StatusMessage,
// McpTaskInfo.InputRequests is IReadOnlyDictionary (covers immutable store
Expand Down
2 changes: 1 addition & 1 deletion src/ModelContextProtocol.Core/Server/McpTaskInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed record McpTaskInfo(
McpTaskStatus Status,
DateTimeOffset CreatedAt,
DateTimeOffset LastUpdatedAt,
long? TtlMs = null,
long? TimeToLiveMs = null,
long? PollIntervalMs = null,
string? StatusMessage = null,
JsonElement? Result = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void CreateTaskResult_SerializationRoundTrip_PreservesAllPropertie
StatusMessage = "Processing...",
CreatedAt = new DateTimeOffset(2025, 6, 1, 12, 0, 0, TimeSpan.Zero),
LastUpdatedAt = new DateTimeOffset(2025, 6, 1, 12, 5, 0, TimeSpan.Zero),
TtlMs = 3600000,
TimeToLiveMs = 3600000,
PollIntervalMs = 5000,
ResultType = "task",
Meta = new JsonObject { ["key"] = "value" }
Expand All @@ -36,7 +36,7 @@ public static void CreateTaskResult_SerializationRoundTrip_PreservesAllPropertie
Assert.Equal("Processing...", deserialized.StatusMessage);
Assert.Equal(original.CreatedAt, deserialized.CreatedAt);
Assert.Equal(original.LastUpdatedAt, deserialized.LastUpdatedAt);
Assert.Equal(3600000, deserialized.TtlMs);
Assert.Equal(3600000, deserialized.TimeToLiveMs);
Assert.Equal(5000, deserialized.PollIntervalMs);
Assert.Equal("task", deserialized.ResultType);
Assert.NotNull(deserialized.Meta);
Expand All @@ -52,7 +52,7 @@ public static void CreateTaskResult_UsesCorrectWireFieldNames()
Status = McpTaskStatus.Working,
CreatedAt = DateTimeOffset.UtcNow,
LastUpdatedAt = DateTimeOffset.UtcNow,
TtlMs = 60000,
TimeToLiveMs = 60000,
PollIntervalMs = 1000,
ResultType = "task",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public async Task CreateTaskAsync_UsesDefaultPollInterval()
}

[Fact]
public async Task CreateTaskAsync_UsesDefaultTtl()
public async Task CreateTaskAsync_UsesDefaultTimeToLive()
{
var store = new InMemoryMcpTaskStore { DefaultTtlMs = 30000 };
var store = new InMemoryMcpTaskStore { DefaultTimeToLiveMs = 30000 };

var result = await store.CreateTaskAsync(CT);

Assert.Equal(30000, result.TtlMs);
Assert.Equal(30000, result.TimeToLiveMs);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected override void ConfigureServices(ServiceCollection services, IMcpServer
options.TaskStore = new InMemoryMcpTaskStore
{
DefaultPollIntervalMs = 50,
DefaultTtlMs = 5000,
DefaultTimeToLiveMs = 5000,
};
});

Expand Down