Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 15 additions & 5 deletions src/experimental/tasks/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ import type { RequestOptions } from '../../shared/protocol.js';
import type { ResponseMessage } from '../../shared/responseMessage.js';
import type { AnyObjectSchema, SchemaOutput } from '../../server/zod-compat.js';
import type { CallToolRequest, ClientRequest, Notification, Request, Result } from '../../types.js';
import { CallToolResultSchema, type CompatibilityCallToolResultSchema, McpError, ErrorCode } from '../../types.js';
import {
CallToolResultSchema,
type CompatibilityCallToolResultSchema,
GetTaskPayloadResultSchema,
McpError,
ErrorCode
} from '../../types.js';

import type { GetTaskResult, ListTasksResult, CancelTaskResult } from './types.js';

Expand Down Expand Up @@ -178,23 +184,27 @@ export class ExperimentalClientTasks<
* Retrieves the result of a completed task.
*
* @param taskId - The task identifier
* @param resultSchema - Zod schema for validating the result
* @param resultSchema - Zod schema for validating the result, defaults to `GetTaskPayloadResultSchema`
* @param options - Optional request options
* @returns The task result
*
* @experimental
*/
async getTaskResult<T extends AnyObjectSchema>(taskId: string, resultSchema?: T, options?: RequestOptions): Promise<SchemaOutput<T>> {
async getTaskResult<T extends AnyObjectSchema = typeof GetTaskPayloadResultSchema>(
taskId: string,
resultSchema?: T,
options?: RequestOptions
): Promise<SchemaOutput<T>> {
// Delegate to the client's underlying Protocol method
return (
this._client as unknown as {
getTaskResult: <U extends AnyObjectSchema>(
params: { taskId: string },
resultSchema?: U,
resultSchema: U,
options?: RequestOptions
) => Promise<SchemaOutput<U>>;
}
).getTaskResult({ taskId }, resultSchema, options);
).getTaskResult({ taskId }, (resultSchema ?? GetTaskPayloadResultSchema) as T, options);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions test/client/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2579,6 +2579,10 @@ describe('Task-based execution', () => {
// Query task result using the captured task ID
const result = await client.experimental.tasks.getTaskResult(taskId!, CallToolResultSchema);
expect(result.content).toEqual([{ type: 'text', text: 'Result data!' }]);

// The result schema is optional and falls back to the generic tasks/result schema
const untypedResult = await client.experimental.tasks.getTaskResult(taskId!);
expect(untypedResult.content).toEqual([{ type: 'text', text: 'Result data!' }]);
});

test('should query task list from server using listTasks', async () => {
Expand Down
Loading