@mastra/client-js 0.0.0-mcp-server-deploy-20250507160341 → 0.0.0-mcp-changeset-20250707162621

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/client.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import type { AbstractAgent } from '@ag-ui/client';
2
+ import type { ServerDetailInfo } from '@mastra/core/mcp';
3
+ import { AGUIAdapter } from './adapters/agui';
1
4
  import {
2
5
  Agent,
3
6
  MemoryThread,
@@ -6,8 +9,9 @@ import {
6
9
  Vector,
7
10
  BaseResource,
8
11
  Network,
9
- VNextWorkflow,
10
- MCPServer,
12
+ A2A,
13
+ MCPTool,
14
+ LegacyWorkflow,
11
15
  } from './resources';
12
16
  import type {
13
17
  ClientOptions,
@@ -17,18 +21,25 @@ import type {
17
21
  GetLogParams,
18
22
  GetLogsParams,
19
23
  GetLogsResponse,
20
- GetMCPServerResponse,
21
24
  GetMemoryThreadParams,
22
25
  GetMemoryThreadResponse,
23
26
  GetNetworkResponse,
24
27
  GetTelemetryParams,
25
28
  GetTelemetryResponse,
26
29
  GetToolResponse,
27
- GetVNextWorkflowResponse,
28
30
  GetWorkflowResponse,
29
31
  SaveMessageToMemoryParams,
30
32
  SaveMessageToMemoryResponse,
33
+ McpServerListResponse,
34
+ McpServerToolListResponse,
35
+ GetLegacyWorkflowResponse,
36
+ GetVNextNetworkResponse,
37
+ GetNetworkMemoryThreadParams,
38
+ CreateNetworkMemoryThreadParams,
39
+ SaveNetworkMessageToMemoryParams,
31
40
  } from './types';
41
+ import { VNextNetwork } from './resources/vNextNetwork';
42
+ import { NetworkMemoryThread } from './resources/network-memory-thread';
32
43
 
33
44
  export class MastraClient extends BaseResource {
34
45
  constructor(options: ClientOptions) {
@@ -43,6 +54,25 @@ export class MastraClient extends BaseResource {
43
54
  return this.request('/api/agents');
44
55
  }
45
56
 
57
+ public async getAGUI({ resourceId }: { resourceId: string }): Promise<Record<string, AbstractAgent>> {
58
+ const agents = await this.getAgents();
59
+
60
+ return Object.entries(agents).reduce(
61
+ (acc, [agentId]) => {
62
+ const agent = this.getAgent(agentId);
63
+
64
+ acc[agentId] = new AGUIAdapter({
65
+ agentId,
66
+ agent,
67
+ resourceId,
68
+ });
69
+
70
+ return acc;
71
+ },
72
+ {} as Record<string, AbstractAgent>,
73
+ );
74
+ }
75
+
46
76
  /**
47
77
  * Gets an agent instance by ID
48
78
  * @param agentId - ID of the agent to retrieve
@@ -99,6 +129,53 @@ export class MastraClient extends BaseResource {
99
129
  return this.request(`/api/memory/status?agentId=${agentId}`);
100
130
  }
101
131
 
132
+ /**
133
+ * Retrieves memory threads for a resource
134
+ * @param params - Parameters containing the resource ID
135
+ * @returns Promise containing array of memory threads
136
+ */
137
+ public getNetworkMemoryThreads(params: GetNetworkMemoryThreadParams): Promise<GetMemoryThreadResponse> {
138
+ return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
139
+ }
140
+
141
+ /**
142
+ * Creates a new memory thread
143
+ * @param params - Parameters for creating the memory thread
144
+ * @returns Promise containing the created memory thread
145
+ */
146
+ public createNetworkMemoryThread(params: CreateNetworkMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
147
+ return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: 'POST', body: params });
148
+ }
149
+
150
+ /**
151
+ * Gets a memory thread instance by ID
152
+ * @param threadId - ID of the memory thread to retrieve
153
+ * @returns MemoryThread instance
154
+ */
155
+ public getNetworkMemoryThread(threadId: string, networkId: string) {
156
+ return new NetworkMemoryThread(this.options, threadId, networkId);
157
+ }
158
+
159
+ /**
160
+ * Saves messages to memory
161
+ * @param params - Parameters containing messages to save
162
+ * @returns Promise containing the saved messages
163
+ */
164
+ public saveNetworkMessageToMemory(params: SaveNetworkMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
165
+ return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
166
+ method: 'POST',
167
+ body: params,
168
+ });
169
+ }
170
+
171
+ /**
172
+ * Gets the status of the memory system
173
+ * @returns Promise containing memory system status
174
+ */
175
+ public getNetworkMemoryStatus(networkId: string): Promise<{ result: boolean }> {
176
+ return this.request(`/api/memory/network/status?networkId=${networkId}`);
177
+ }
178
+
102
179
  /**
103
180
  * Retrieves all available tools
104
181
  * @returns Promise containing map of tool IDs to tool details
@@ -116,6 +193,23 @@ export class MastraClient extends BaseResource {
116
193
  return new Tool(this.options, toolId);
117
194
  }
118
195
 
196
+ /**
197
+ * Retrieves all available legacy workflows
198
+ * @returns Promise containing map of legacy workflow IDs to legacy workflow details
199
+ */
200
+ public getLegacyWorkflows(): Promise<Record<string, GetLegacyWorkflowResponse>> {
201
+ return this.request('/api/workflows/legacy');
202
+ }
203
+
204
+ /**
205
+ * Gets a legacy workflow instance by ID
206
+ * @param workflowId - ID of the legacy workflow to retrieve
207
+ * @returns Legacy Workflow instance
208
+ */
209
+ public getLegacyWorkflow(workflowId: string) {
210
+ return new LegacyWorkflow(this.options, workflowId);
211
+ }
212
+
119
213
  /**
120
214
  * Retrieves all available workflows
121
215
  * @returns Promise containing map of workflow IDs to workflow details
@@ -133,23 +227,6 @@ export class MastraClient extends BaseResource {
133
227
  return new Workflow(this.options, workflowId);
134
228
  }
135
229
 
136
- /**
137
- * Retrieves all available vNext workflows
138
- * @returns Promise containing map of vNext workflow IDs to vNext workflow details
139
- */
140
- public getVNextWorkflows(): Promise<Record<string, GetVNextWorkflowResponse>> {
141
- return this.request('/api/workflows/v-next');
142
- }
143
-
144
- /**
145
- * Gets a vNext workflow instance by ID
146
- * @param workflowId - ID of the vNext workflow to retrieve
147
- * @returns vNext Workflow instance
148
- */
149
- public getVNextWorkflow(workflowId: string) {
150
- return new VNextWorkflow(this.options, workflowId);
151
- }
152
-
153
230
  /**
154
231
  * Gets a vector instance by name
155
232
  * @param vectorName - Name of the vector to retrieve
@@ -165,7 +242,43 @@ export class MastraClient extends BaseResource {
165
242
  * @returns Promise containing array of log messages
166
243
  */
167
244
  public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
168
- return this.request(`/api/logs?transportId=${params.transportId}`);
245
+ const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
246
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
247
+
248
+ const searchParams = new URLSearchParams();
249
+ if (transportId) {
250
+ searchParams.set('transportId', transportId);
251
+ }
252
+ if (fromDate) {
253
+ searchParams.set('fromDate', fromDate.toISOString());
254
+ }
255
+ if (toDate) {
256
+ searchParams.set('toDate', toDate.toISOString());
257
+ }
258
+ if (logLevel) {
259
+ searchParams.set('logLevel', logLevel);
260
+ }
261
+ if (page) {
262
+ searchParams.set('page', String(page));
263
+ }
264
+ if (perPage) {
265
+ searchParams.set('perPage', String(perPage));
266
+ }
267
+ if (_filters) {
268
+ if (Array.isArray(_filters)) {
269
+ for (const filter of _filters) {
270
+ searchParams.append('filters', filter);
271
+ }
272
+ } else {
273
+ searchParams.set('filters', _filters);
274
+ }
275
+ }
276
+
277
+ if (searchParams.size) {
278
+ return this.request(`/api/logs?${searchParams}`);
279
+ } else {
280
+ return this.request(`/api/logs`);
281
+ }
169
282
  }
170
283
 
171
284
  /**
@@ -174,7 +287,47 @@ export class MastraClient extends BaseResource {
174
287
  * @returns Promise containing array of log messages
175
288
  */
176
289
  public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
177
- return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
290
+ const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
291
+
292
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
293
+ const searchParams = new URLSearchParams();
294
+ if (runId) {
295
+ searchParams.set('runId', runId);
296
+ }
297
+ if (transportId) {
298
+ searchParams.set('transportId', transportId);
299
+ }
300
+ if (fromDate) {
301
+ searchParams.set('fromDate', fromDate.toISOString());
302
+ }
303
+ if (toDate) {
304
+ searchParams.set('toDate', toDate.toISOString());
305
+ }
306
+ if (logLevel) {
307
+ searchParams.set('logLevel', logLevel);
308
+ }
309
+ if (page) {
310
+ searchParams.set('page', String(page));
311
+ }
312
+ if (perPage) {
313
+ searchParams.set('perPage', String(perPage));
314
+ }
315
+
316
+ if (_filters) {
317
+ if (Array.isArray(_filters)) {
318
+ for (const filter of _filters) {
319
+ searchParams.append('filters', filter);
320
+ }
321
+ } else {
322
+ searchParams.set('filters', _filters);
323
+ }
324
+ }
325
+
326
+ if (searchParams.size) {
327
+ return this.request(`/api/logs/${runId}?${searchParams}`);
328
+ } else {
329
+ return this.request(`/api/logs/${runId}`);
330
+ }
178
331
  }
179
332
 
180
333
  /**
@@ -234,10 +387,18 @@ export class MastraClient extends BaseResource {
234
387
  * Retrieves all available networks
235
388
  * @returns Promise containing map of network IDs to network details
236
389
  */
237
- public getNetworks(): Promise<Record<string, GetNetworkResponse>> {
390
+ public getNetworks(): Promise<Array<GetNetworkResponse>> {
238
391
  return this.request('/api/networks');
239
392
  }
240
393
 
394
+ /**
395
+ * Retrieves all available vNext networks
396
+ * @returns Promise containing map of vNext network IDs to vNext network details
397
+ */
398
+ public getVNextNetworks(): Promise<Array<GetVNextNetworkResponse>> {
399
+ return this.request('/api/networks/v-next');
400
+ }
401
+
241
402
  /**
242
403
  * Gets a network instance by ID
243
404
  * @param networkId - ID of the network to retrieve
@@ -248,19 +409,72 @@ export class MastraClient extends BaseResource {
248
409
  }
249
410
 
250
411
  /**
251
- * Retrieves all available MCP servers
252
- * @returns Promise containing map of MCP server IDs to server details
412
+ * Gets a vNext network instance by ID
413
+ * @param networkId - ID of the vNext network to retrieve
414
+ * @returns vNext Network instance
415
+ */
416
+ public getVNextNetwork(networkId: string) {
417
+ return new VNextNetwork(this.options, networkId);
418
+ }
419
+
420
+ /**
421
+ * Retrieves a list of available MCP servers.
422
+ * @param params - Optional parameters for pagination (limit, offset).
423
+ * @returns Promise containing the list of MCP servers and pagination info.
424
+ */
425
+ public getMcpServers(params?: { limit?: number; offset?: number }): Promise<McpServerListResponse> {
426
+ const searchParams = new URLSearchParams();
427
+ if (params?.limit !== undefined) {
428
+ searchParams.set('limit', String(params.limit));
429
+ }
430
+ if (params?.offset !== undefined) {
431
+ searchParams.set('offset', String(params.offset));
432
+ }
433
+ const queryString = searchParams.toString();
434
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ''}`);
435
+ }
436
+
437
+ /**
438
+ * Retrieves detailed information for a specific MCP server.
439
+ * @param serverId - The ID of the MCP server to retrieve.
440
+ * @param params - Optional parameters, e.g., specific version.
441
+ * @returns Promise containing the detailed MCP server information.
442
+ */
443
+ public getMcpServerDetails(serverId: string, params?: { version?: string }): Promise<ServerDetailInfo> {
444
+ const searchParams = new URLSearchParams();
445
+ if (params?.version) {
446
+ searchParams.set('version', params.version);
447
+ }
448
+ const queryString = searchParams.toString();
449
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ''}`);
450
+ }
451
+
452
+ /**
453
+ * Retrieves a list of tools for a specific MCP server.
454
+ * @param serverId - The ID of the MCP server.
455
+ * @returns Promise containing the list of tools.
456
+ */
457
+ public getMcpServerTools(serverId: string): Promise<McpServerToolListResponse> {
458
+ return this.request(`/api/mcp/${serverId}/tools`);
459
+ }
460
+
461
+ /**
462
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
463
+ * This instance can then be used to fetch details or execute the tool.
464
+ * @param serverId - The ID of the MCP server.
465
+ * @param toolId - The ID of the tool.
466
+ * @returns MCPTool instance.
253
467
  */
254
- public getMCPServers(): Promise<Record<string, GetMCPServerResponse>> {
255
- return this.request('/api/mcp/servers');
468
+ public getMcpServerTool(serverId: string, toolId: string): MCPTool {
469
+ return new MCPTool(this.options, serverId, toolId);
256
470
  }
257
471
 
258
472
  /**
259
- * Gets an MCP server instance by ID
260
- * @param serverId - ID of the MCP server to retrieve
261
- * @returns MCPServer instance
473
+ * Gets an A2A client for interacting with an agent via the A2A protocol
474
+ * @param agentId - ID of the agent to interact with
475
+ * @returns A2A client instance
262
476
  */
263
- public getMCPServer(serverId: string) {
264
- return new MCPServer(this.options, serverId);
477
+ public getA2A(agentId: string) {
478
+ return new A2A(this.options, agentId);
265
479
  }
266
480
  }
package/src/example.ts CHANGED
@@ -1,40 +1,42 @@
1
- // import { MastraClient } from './client';
1
+ import { MastraClient } from './client';
2
+ import z from 'zod';
2
3
  // import type { WorkflowRunResult } from './types';
3
4
 
4
5
  // Agent
6
+ (async () => {
7
+ const client = new MastraClient({
8
+ baseUrl: 'http://localhost:4111',
9
+ });
5
10
 
6
- // (async () => {
7
- // const client = new MastraClient({
8
- // baseUrl: 'http://localhost:4111',
9
- // });
10
-
11
- // console.log('Starting agent...');
12
-
13
- // try {
14
- // const agent = client.getAgent('weatherAgent');
15
- // const response = await agent.stream({
16
- // messages: 'what is the weather in new york?',
17
- // })
11
+ console.log('Starting agent...');
18
12
 
19
- // response.processDataStream({
20
- // onTextPart: (text) => {
21
- // process.stdout.write(text);
22
- // },
23
- // onFilePart: (file) => {
24
- // console.log(file);
25
- // },
26
- // onDataPart: (data) => {
27
- // console.log(data);
28
- // },
29
- // onErrorPart: (error) => {
30
- // console.error(error);
31
- // },
32
- // });
13
+ try {
14
+ const agent = client.getAgent('weatherAgent');
15
+ const response = await agent.stream({
16
+ messages: 'what is the weather in new york?',
17
+ });
33
18
 
34
- // } catch (error) {
35
- // console.error(error);
36
- // }
37
- // })();
19
+ response.processDataStream({
20
+ onTextPart: text => {
21
+ process.stdout.write(text);
22
+ },
23
+ onFilePart: file => {
24
+ console.log(file);
25
+ },
26
+ onDataPart: data => {
27
+ console.log(data);
28
+ },
29
+ onErrorPart: error => {
30
+ console.error(error);
31
+ },
32
+ onToolCallPart(streamPart) {
33
+ console.log(streamPart);
34
+ },
35
+ });
36
+ } catch (error) {
37
+ console.error(error);
38
+ }
39
+ })();
38
40
 
39
41
  // Workflow
40
42
  // (async () => {
package/src/index.test.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, beforeEach, it, vi } from 'vitest';
2
-
3
2
  import { MastraClient } from './client';
3
+ import type { McpServerListResponse, ServerDetailInfo } from './types';
4
4
 
5
5
  // Mock fetch globally
6
6
  global.fetch = vi.fn();
@@ -236,6 +236,7 @@ describe('MastraClient Resources', () => {
236
236
  model: 'gpt-4',
237
237
  instructions: 'Test instructions',
238
238
  tools: {},
239
+ workflows: {},
239
240
  };
240
241
  mockFetchResponse(mockResponse);
241
242
 
@@ -552,6 +553,35 @@ describe('MastraClient Resources', () => {
552
553
  }),
553
554
  );
554
555
  });
556
+
557
+ it('should get thread messages with limit', async () => {
558
+ const mockResponse = {
559
+ messages: [
560
+ {
561
+ id: '1',
562
+ content: 'test',
563
+ threadId,
564
+ role: 'user',
565
+ type: 'text',
566
+ resourceId: 'test-resource',
567
+ createdAt: new Date(),
568
+ },
569
+ ],
570
+ uiMessages: [],
571
+ };
572
+ mockFetchResponse(mockResponse);
573
+
574
+ const limit = 5;
575
+ const result = await memoryThread.getMessages({ limit });
576
+
577
+ expect(result).toEqual(mockResponse);
578
+ expect(global.fetch).toHaveBeenCalledWith(
579
+ `${clientOptions.baseUrl}/api/memory/threads/${threadId}/messages?agentId=${agentId}&limit=${limit}`,
580
+ expect.objectContaining({
581
+ headers: expect.objectContaining(clientOptions.headers),
582
+ }),
583
+ );
584
+ });
555
585
  });
556
586
 
557
587
  describe('Tool Resource', () => {
@@ -707,4 +737,94 @@ describe('MastraClient Resources', () => {
707
737
  );
708
738
  });
709
739
  });
740
+
741
+ describe('MCP Server Registry Client Methods', () => {
742
+ const mockServerInfo1 = {
743
+ id: 'mcp-server-1',
744
+ name: 'Test MCP Server 1',
745
+ version_detail: { version: '1.0.0', release_date: '2023-01-01T00:00:00Z', is_latest: true },
746
+ };
747
+ const mockServerInfo2 = {
748
+ id: 'mcp-server-2',
749
+ name: 'Test MCP Server 2',
750
+ version_detail: { version: '1.1.0', release_date: '2023-02-01T00:00:00Z', is_latest: true },
751
+ };
752
+
753
+ const mockServerDetail1: ServerDetailInfo = {
754
+ ...mockServerInfo1,
755
+ description: 'Detailed description for server 1',
756
+ package_canonical: 'npm',
757
+ packages: [{ registry_name: 'npm', name: '@example/server1', version: '1.0.0' }],
758
+ remotes: [{ transport_type: 'sse', url: 'http://localhost/sse1' }],
759
+ };
760
+
761
+ describe('getMcpServers()', () => {
762
+ it('should fetch a list of MCP servers', async () => {
763
+ const mockResponse: McpServerListResponse = {
764
+ servers: [mockServerInfo1, mockServerInfo2],
765
+ total_count: 2,
766
+ next: null,
767
+ };
768
+ mockFetchResponse(mockResponse);
769
+
770
+ const result = await client.getMcpServers();
771
+ expect(result).toEqual(mockResponse);
772
+ expect(global.fetch).toHaveBeenCalledWith(
773
+ `${clientOptions.baseUrl}/api/mcp/v0/servers`,
774
+ expect.objectContaining({
775
+ headers: expect.objectContaining(clientOptions.headers),
776
+ }),
777
+ );
778
+ });
779
+
780
+ it('should fetch MCP servers with limit and offset parameters', async () => {
781
+ const mockResponse: McpServerListResponse = {
782
+ servers: [mockServerInfo1],
783
+ total_count: 2,
784
+ next: '/api/mcp/v0/servers?limit=1&offset=1',
785
+ };
786
+ mockFetchResponse(mockResponse);
787
+
788
+ const result = await client.getMcpServers({ limit: 1, offset: 0 });
789
+ expect(result).toEqual(mockResponse);
790
+ expect(global.fetch).toHaveBeenCalledWith(
791
+ `${clientOptions.baseUrl}/api/mcp/v0/servers?limit=1&offset=0`,
792
+ expect.objectContaining({
793
+ headers: expect.objectContaining(clientOptions.headers),
794
+ }),
795
+ );
796
+ });
797
+ });
798
+
799
+ describe('getMcpServerDetails()', () => {
800
+ const serverId = 'mcp-server-1';
801
+
802
+ it('should fetch details for a specific MCP server', async () => {
803
+ mockFetchResponse(mockServerDetail1);
804
+
805
+ const result = await client.getMcpServerDetails(serverId);
806
+ expect(result).toEqual(mockServerDetail1);
807
+ expect(global.fetch).toHaveBeenCalledWith(
808
+ `${clientOptions.baseUrl}/api/mcp/v0/servers/${serverId}`,
809
+ expect.objectContaining({
810
+ headers: expect.objectContaining(clientOptions.headers),
811
+ }),
812
+ );
813
+ });
814
+
815
+ it('should fetch MCP server details with a version parameter', async () => {
816
+ mockFetchResponse(mockServerDetail1);
817
+ const version = '1.0.0';
818
+
819
+ const result = await client.getMcpServerDetails(serverId, { version });
820
+ expect(result).toEqual(mockServerDetail1);
821
+ expect(global.fetch).toHaveBeenCalledWith(
822
+ `${clientOptions.baseUrl}/api/mcp/v0/servers/${serverId}?version=${version}`,
823
+ expect.objectContaining({
824
+ headers: expect.objectContaining(clientOptions.headers),
825
+ }),
826
+ );
827
+ });
828
+ });
829
+ });
710
830
  });
@@ -0,0 +1,88 @@
1
+ import type { TaskSendParams, TaskQueryParams, TaskIdParams, Task, AgentCard, JSONRPCResponse } from '@mastra/core/a2a';
2
+ import type { ClientOptions } from '../types';
3
+ import { BaseResource } from './base';
4
+
5
+ /**
6
+ * Class for interacting with an agent via the A2A protocol
7
+ */
8
+ export class A2A extends BaseResource {
9
+ constructor(
10
+ options: ClientOptions,
11
+ private agentId: string,
12
+ ) {
13
+ super(options);
14
+ }
15
+
16
+ /**
17
+ * Get the agent card with metadata about the agent
18
+ * @returns Promise containing the agent card information
19
+ */
20
+ async getCard(): Promise<AgentCard> {
21
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
22
+ }
23
+
24
+ /**
25
+ * Send a message to the agent and get a response
26
+ * @param params - Parameters for the task
27
+ * @returns Promise containing the task response
28
+ */
29
+ async sendMessage(params: TaskSendParams): Promise<{ task: Task }> {
30
+ const response = await this.request<JSONRPCResponse<Task>>(`/a2a/${this.agentId}`, {
31
+ method: 'POST',
32
+ body: {
33
+ method: 'tasks/send',
34
+ params,
35
+ },
36
+ });
37
+
38
+ return { task: response.result! };
39
+ }
40
+
41
+ /**
42
+ * Get the status and result of a task
43
+ * @param params - Parameters for querying the task
44
+ * @returns Promise containing the task response
45
+ */
46
+ async getTask(params: TaskQueryParams): Promise<Task> {
47
+ const response = await this.request<JSONRPCResponse<Task>>(`/a2a/${this.agentId}`, {
48
+ method: 'POST',
49
+ body: {
50
+ method: 'tasks/get',
51
+ params,
52
+ },
53
+ });
54
+
55
+ return response.result!;
56
+ }
57
+
58
+ /**
59
+ * Cancel a running task
60
+ * @param params - Parameters identifying the task to cancel
61
+ * @returns Promise containing the task response
62
+ */
63
+ async cancelTask(params: TaskIdParams): Promise<{ task: Task }> {
64
+ return this.request(`/a2a/${this.agentId}`, {
65
+ method: 'POST',
66
+ body: {
67
+ method: 'tasks/cancel',
68
+ params,
69
+ },
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Send a message and subscribe to streaming updates (not fully implemented)
75
+ * @param params - Parameters for the task
76
+ * @returns Promise containing the task response
77
+ */
78
+ async sendAndSubscribe(params: TaskSendParams): Promise<Response> {
79
+ return this.request(`/a2a/${this.agentId}`, {
80
+ method: 'POST',
81
+ body: {
82
+ method: 'tasks/sendSubscribe',
83
+ params,
84
+ },
85
+ stream: true,
86
+ });
87
+ }
88
+ }