Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
4 changes: 2 additions & 2 deletions packages/core/src/experimental/tasks/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import type {
* @experimental
*/
export type CreateTaskServerContext = ServerContext & {
task: { store: RequestTaskStore; requestedTtl?: number | null };
task: { store: RequestTaskStore; requestedTtl?: number };
};

/**
* Server context with guaranteed task ID and store for task operations.
* @experimental
*/
export type TaskServerContext = ServerContext & {
task: { id: string; store: RequestTaskStore; requestedTtl?: number | null };
task: { id: string; store: RequestTaskStore; requestedTtl?: number };
};

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/shared/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export interface RequestTaskStore {
export type TaskContext = {
id?: string;
store: RequestTaskStore;
requestedTtl?: number | null;
requestedTtl?: number;
};

/**
Expand Down
5 changes: 2 additions & 3 deletions packages/core/src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ export const CursorSchema = z.string();
*/
export const TaskCreationParamsSchema = z.looseObject({
/**
* Time in milliseconds to keep task results available after completion.
* If `null`, the task has unlimited lifetime until manually cleaned up.
* Requested duration in milliseconds to retain task from creation.
*/
ttl: z.union([z.number(), z.null()]).optional(),
ttl: z.number().optional(),

/**
* Time in milliseconds to wait between task status requests.
Comment thread
claude[bot] marked this conversation as resolved.
Outdated
Expand Down
11 changes: 5 additions & 6 deletions packages/core/test/experimental/inMemory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,17 +488,16 @@ describe('InMemoryTaskStore', () => {
expect(task).toBeNull();
});

it('should support null TTL for unlimited lifetime', async () => {
// Test that null TTL means unlimited lifetime
const taskParams: TaskCreationParams = {
ttl: null
};
it('should support omitted TTL for unlimited lifetime', async () => {
// Test that omitting TTL means unlimited lifetime (server returns null)
// Per spec: clients omit ttl to let server decide, server returns null for unlimited
const taskParams: TaskCreationParams = {};
const createdTask = await store.createTask(taskParams, 2222, {
method: 'tools/call',
params: {}
});

// The returned task should have null TTL
// The returned task should have null TTL (unlimited)
expect(createdTask.ttl).toBeNull();

// Task should not be cleaned up even after a long time
Expand Down
31 changes: 29 additions & 2 deletions test/integration/test/experimental/tasks/task.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isTerminal } from '@modelcontextprotocol/core';
import type { Task } from '@modelcontextprotocol/server';
import type { Task } from '@modelcontextprotocol/core';
import { isTerminal, TaskCreationParamsSchema } from '@modelcontextprotocol/core';
import { describe, expect, it } from 'vitest';

describe('Task utility functions', () => {
Expand Down Expand Up @@ -115,3 +115,30 @@ describe('Task Schema Validation', () => {
}
});
});

describe('TaskCreationParams Schema Validation', () => {
it('should accept ttl as a number', () => {
const result = TaskCreationParamsSchema.safeParse({ ttl: 60_000 });
expect(result.success).toBe(true);
});

it('should accept missing ttl (optional)', () => {
const result = TaskCreationParamsSchema.safeParse({});
expect(result.success).toBe(true);
});

it('should reject null ttl (not allowed in request, only response)', () => {
const result = TaskCreationParamsSchema.safeParse({ ttl: null });
expect(result.success).toBe(false);
});
Comment thread
claude[bot] marked this conversation as resolved.

it('should accept pollInterval as a number', () => {
const result = TaskCreationParamsSchema.safeParse({ pollInterval: 1000 });
expect(result.success).toBe(true);
});

it('should accept both ttl and pollInterval', () => {
const result = TaskCreationParamsSchema.safeParse({ ttl: 60_000, pollInterval: 1000 });
expect(result.success).toBe(true);
});
});
Loading