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
5 changes: 5 additions & 0 deletions .changeset/default-get-task-result-schema.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@modelcontextprotocol/sdk': patch
---

Default `resultSchema` to `CallToolResultSchema` in `ExperimentalClientTasks.getTaskResult`
6 changes: 4 additions & 2 deletions src/experimental/tasks/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,15 @@ 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 CallToolResultSchema)
* @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 typeof CallToolResultSchema | typeof CompatibilityCallToolResultSchema | AnyObjectSchema = typeof CallToolResultSchema
>(taskId: string, resultSchema: T = CallToolResultSchema as T, options?: RequestOptions): Promise<SchemaOutput<T>> {
// Delegate to the client's underlying Protocol method
return (
this._client as unknown as {
Expand Down
10 changes: 7 additions & 3 deletions test/client/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2576,9 +2576,13 @@ describe('Task-based execution', () => {

expect(taskId).toBeDefined();

// 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!' }]);
// Query task result using the captured task ID with default schema
const defaultResult = await client.experimental.tasks.getTaskResult(taskId!);
expect(defaultResult.content).toEqual([{ type: 'text', text: 'Result data!' }]);

// Query task result with explicit schema
const explicitResult = await client.experimental.tasks.getTaskResult(taskId!, CallToolResultSchema);
expect(explicitResult.content).toEqual([{ type: 'text', text: 'Result data!' }]);
});

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