@mastra/client-js 0.0.0-mcp-server-deploy-20250507160341 → 0.0.0-memory-system-message-error-20250813233316

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.
Files changed (84) hide show
  1. package/CHANGELOG.md +1278 -2
  2. package/LICENSE.md +11 -42
  3. package/README.md +2 -1
  4. package/dist/adapters/agui.d.ts +23 -0
  5. package/dist/adapters/agui.d.ts.map +1 -0
  6. package/dist/client.d.ts +270 -0
  7. package/dist/client.d.ts.map +1 -0
  8. package/dist/example.d.ts +2 -0
  9. package/dist/example.d.ts.map +1 -0
  10. package/dist/index.cjs +1607 -152
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.ts +4 -760
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +1606 -155
  15. package/dist/index.js.map +1 -0
  16. package/dist/resources/a2a.d.ts +41 -0
  17. package/dist/resources/a2a.d.ts.map +1 -0
  18. package/dist/resources/agent.d.ts +123 -0
  19. package/dist/resources/agent.d.ts.map +1 -0
  20. package/dist/resources/base.d.ts +13 -0
  21. package/dist/resources/base.d.ts.map +1 -0
  22. package/dist/resources/index.d.ts +11 -0
  23. package/dist/resources/index.d.ts.map +1 -0
  24. package/dist/resources/legacy-workflow.d.ts +87 -0
  25. package/dist/resources/legacy-workflow.d.ts.map +1 -0
  26. package/dist/resources/mcp-tool.d.ts +27 -0
  27. package/dist/resources/mcp-tool.d.ts.map +1 -0
  28. package/dist/resources/memory-thread.d.ts +53 -0
  29. package/dist/resources/memory-thread.d.ts.map +1 -0
  30. package/dist/resources/network-memory-thread.d.ts +47 -0
  31. package/dist/resources/network-memory-thread.d.ts.map +1 -0
  32. package/dist/resources/network.d.ts +30 -0
  33. package/dist/resources/network.d.ts.map +1 -0
  34. package/dist/resources/tool.d.ts +23 -0
  35. package/dist/resources/tool.d.ts.map +1 -0
  36. package/dist/resources/vNextNetwork.d.ts +42 -0
  37. package/dist/resources/vNextNetwork.d.ts.map +1 -0
  38. package/dist/resources/vector.d.ts +48 -0
  39. package/dist/resources/vector.d.ts.map +1 -0
  40. package/dist/resources/workflow.d.ts +154 -0
  41. package/dist/resources/workflow.d.ts.map +1 -0
  42. package/dist/types.d.ts +422 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/dist/utils/index.d.ts +3 -0
  45. package/dist/utils/index.d.ts.map +1 -0
  46. package/dist/utils/process-client-tools.d.ts +3 -0
  47. package/dist/utils/process-client-tools.d.ts.map +1 -0
  48. package/dist/utils/zod-to-json-schema.d.ts +105 -0
  49. package/dist/utils/zod-to-json-schema.d.ts.map +1 -0
  50. package/integration-tests/agui-adapter.test.ts +122 -0
  51. package/integration-tests/package.json +18 -0
  52. package/integration-tests/src/mastra/index.ts +35 -0
  53. package/integration-tests/vitest.config.ts +9 -0
  54. package/package.json +32 -19
  55. package/src/adapters/agui.test.ts +322 -0
  56. package/src/adapters/agui.ts +257 -0
  57. package/src/client.ts +398 -33
  58. package/src/example.ts +59 -29
  59. package/src/index.test.ts +522 -6
  60. package/src/index.ts +1 -0
  61. package/src/resources/a2a.ts +98 -0
  62. package/src/resources/agent.ts +641 -48
  63. package/src/resources/base.ts +7 -1
  64. package/src/resources/index.ts +4 -3
  65. package/src/resources/{vnext-workflow.ts → legacy-workflow.ts} +124 -139
  66. package/src/resources/mcp-tool.ts +48 -0
  67. package/src/resources/memory-thread.test.ts +285 -0
  68. package/src/resources/memory-thread.ts +49 -3
  69. package/src/resources/network-memory-thread.test.ts +269 -0
  70. package/src/resources/network-memory-thread.ts +81 -0
  71. package/src/resources/network.ts +10 -16
  72. package/src/resources/tool.ts +9 -2
  73. package/src/resources/vNextNetwork.ts +194 -0
  74. package/src/resources/workflow.ts +255 -96
  75. package/src/types.ts +258 -29
  76. package/src/utils/index.ts +11 -0
  77. package/src/utils/process-client-tools.ts +32 -0
  78. package/src/utils/zod-to-json-schema.ts +10 -0
  79. package/src/v2-messages.test.ts +180 -0
  80. package/tsconfig.build.json +9 -0
  81. package/tsconfig.json +1 -1
  82. package/tsup.config.ts +17 -0
  83. package/dist/index.d.cts +0 -760
  84. package/src/resources/mcp.ts +0 -22
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,9 +9,12 @@ import {
6
9
  Vector,
7
10
  BaseResource,
8
11
  Network,
9
- VNextWorkflow,
10
- MCPServer,
12
+ A2A,
13
+ MCPTool,
14
+ LegacyWorkflow,
11
15
  } from './resources';
16
+ import { NetworkMemoryThread } from './resources/network-memory-thread';
17
+ import { VNextNetwork } from './resources/vNextNetwork';
12
18
  import type {
13
19
  ClientOptions,
14
20
  CreateMemoryThreadParams,
@@ -17,17 +23,29 @@ import type {
17
23
  GetLogParams,
18
24
  GetLogsParams,
19
25
  GetLogsResponse,
20
- GetMCPServerResponse,
21
26
  GetMemoryThreadParams,
22
27
  GetMemoryThreadResponse,
23
28
  GetNetworkResponse,
24
29
  GetTelemetryParams,
25
30
  GetTelemetryResponse,
26
31
  GetToolResponse,
27
- GetVNextWorkflowResponse,
28
32
  GetWorkflowResponse,
29
33
  SaveMessageToMemoryParams,
30
34
  SaveMessageToMemoryResponse,
35
+ McpServerListResponse,
36
+ McpServerToolListResponse,
37
+ GetLegacyWorkflowResponse,
38
+ GetVNextNetworkResponse,
39
+ GetNetworkMemoryThreadParams,
40
+ CreateNetworkMemoryThreadParams,
41
+ SaveNetworkMessageToMemoryParams,
42
+ GetScorerResponse,
43
+ GetScoresByScorerIdParams,
44
+ GetScoresResponse,
45
+ GetScoresByRunIdParams,
46
+ GetScoresByEntityIdParams,
47
+ SaveScoreParams,
48
+ SaveScoreResponse,
31
49
  } from './types';
32
50
 
33
51
  export class MastraClient extends BaseResource {
@@ -43,6 +61,25 @@ export class MastraClient extends BaseResource {
43
61
  return this.request('/api/agents');
44
62
  }
45
63
 
64
+ public async getAGUI({ resourceId }: { resourceId: string }): Promise<Record<string, AbstractAgent>> {
65
+ const agents = await this.getAgents();
66
+
67
+ return Object.entries(agents).reduce(
68
+ (acc, [agentId]) => {
69
+ const agent = this.getAgent(agentId);
70
+
71
+ acc[agentId] = new AGUIAdapter({
72
+ agentId,
73
+ agent,
74
+ resourceId,
75
+ });
76
+
77
+ return acc;
78
+ },
79
+ {} as Record<string, AbstractAgent>,
80
+ );
81
+ }
82
+
46
83
  /**
47
84
  * Gets an agent instance by ID
48
85
  * @param agentId - ID of the agent to retrieve
@@ -99,6 +136,53 @@ export class MastraClient extends BaseResource {
99
136
  return this.request(`/api/memory/status?agentId=${agentId}`);
100
137
  }
101
138
 
139
+ /**
140
+ * Retrieves memory threads for a resource
141
+ * @param params - Parameters containing the resource ID
142
+ * @returns Promise containing array of memory threads
143
+ */
144
+ public getNetworkMemoryThreads(params: GetNetworkMemoryThreadParams): Promise<GetMemoryThreadResponse> {
145
+ return this.request(`/api/memory/network/threads?resourceid=${params.resourceId}&networkId=${params.networkId}`);
146
+ }
147
+
148
+ /**
149
+ * Creates a new memory thread
150
+ * @param params - Parameters for creating the memory thread
151
+ * @returns Promise containing the created memory thread
152
+ */
153
+ public createNetworkMemoryThread(params: CreateNetworkMemoryThreadParams): Promise<CreateMemoryThreadResponse> {
154
+ return this.request(`/api/memory/network/threads?networkId=${params.networkId}`, { method: 'POST', body: params });
155
+ }
156
+
157
+ /**
158
+ * Gets a memory thread instance by ID
159
+ * @param threadId - ID of the memory thread to retrieve
160
+ * @returns MemoryThread instance
161
+ */
162
+ public getNetworkMemoryThread(threadId: string, networkId: string) {
163
+ return new NetworkMemoryThread(this.options, threadId, networkId);
164
+ }
165
+
166
+ /**
167
+ * Saves messages to memory
168
+ * @param params - Parameters containing messages to save
169
+ * @returns Promise containing the saved messages
170
+ */
171
+ public saveNetworkMessageToMemory(params: SaveNetworkMessageToMemoryParams): Promise<SaveMessageToMemoryResponse> {
172
+ return this.request(`/api/memory/network/save-messages?networkId=${params.networkId}`, {
173
+ method: 'POST',
174
+ body: params,
175
+ });
176
+ }
177
+
178
+ /**
179
+ * Gets the status of the memory system
180
+ * @returns Promise containing memory system status
181
+ */
182
+ public getNetworkMemoryStatus(networkId: string): Promise<{ result: boolean }> {
183
+ return this.request(`/api/memory/network/status?networkId=${networkId}`);
184
+ }
185
+
102
186
  /**
103
187
  * Retrieves all available tools
104
188
  * @returns Promise containing map of tool IDs to tool details
@@ -116,6 +200,23 @@ export class MastraClient extends BaseResource {
116
200
  return new Tool(this.options, toolId);
117
201
  }
118
202
 
203
+ /**
204
+ * Retrieves all available legacy workflows
205
+ * @returns Promise containing map of legacy workflow IDs to legacy workflow details
206
+ */
207
+ public getLegacyWorkflows(): Promise<Record<string, GetLegacyWorkflowResponse>> {
208
+ return this.request('/api/workflows/legacy');
209
+ }
210
+
211
+ /**
212
+ * Gets a legacy workflow instance by ID
213
+ * @param workflowId - ID of the legacy workflow to retrieve
214
+ * @returns Legacy Workflow instance
215
+ */
216
+ public getLegacyWorkflow(workflowId: string) {
217
+ return new LegacyWorkflow(this.options, workflowId);
218
+ }
219
+
119
220
  /**
120
221
  * Retrieves all available workflows
121
222
  * @returns Promise containing map of workflow IDs to workflow details
@@ -133,23 +234,6 @@ export class MastraClient extends BaseResource {
133
234
  return new Workflow(this.options, workflowId);
134
235
  }
135
236
 
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
237
  /**
154
238
  * Gets a vector instance by name
155
239
  * @param vectorName - Name of the vector to retrieve
@@ -165,7 +249,43 @@ export class MastraClient extends BaseResource {
165
249
  * @returns Promise containing array of log messages
166
250
  */
167
251
  public getLogs(params: GetLogsParams): Promise<GetLogsResponse> {
168
- return this.request(`/api/logs?transportId=${params.transportId}`);
252
+ const { transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
253
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
254
+
255
+ const searchParams = new URLSearchParams();
256
+ if (transportId) {
257
+ searchParams.set('transportId', transportId);
258
+ }
259
+ if (fromDate) {
260
+ searchParams.set('fromDate', fromDate.toISOString());
261
+ }
262
+ if (toDate) {
263
+ searchParams.set('toDate', toDate.toISOString());
264
+ }
265
+ if (logLevel) {
266
+ searchParams.set('logLevel', logLevel);
267
+ }
268
+ if (page) {
269
+ searchParams.set('page', String(page));
270
+ }
271
+ if (perPage) {
272
+ searchParams.set('perPage', String(perPage));
273
+ }
274
+ if (_filters) {
275
+ if (Array.isArray(_filters)) {
276
+ for (const filter of _filters) {
277
+ searchParams.append('filters', filter);
278
+ }
279
+ } else {
280
+ searchParams.set('filters', _filters);
281
+ }
282
+ }
283
+
284
+ if (searchParams.size) {
285
+ return this.request(`/api/logs?${searchParams}`);
286
+ } else {
287
+ return this.request(`/api/logs`);
288
+ }
169
289
  }
170
290
 
171
291
  /**
@@ -174,7 +294,47 @@ export class MastraClient extends BaseResource {
174
294
  * @returns Promise containing array of log messages
175
295
  */
176
296
  public getLogForRun(params: GetLogParams): Promise<GetLogsResponse> {
177
- return this.request(`/api/logs/${params.runId}?transportId=${params.transportId}`);
297
+ const { runId, transportId, fromDate, toDate, logLevel, filters, page, perPage } = params;
298
+
299
+ const _filters = filters ? Object.entries(filters).map(([key, value]) => `${key}:${value}`) : [];
300
+ const searchParams = new URLSearchParams();
301
+ if (runId) {
302
+ searchParams.set('runId', runId);
303
+ }
304
+ if (transportId) {
305
+ searchParams.set('transportId', transportId);
306
+ }
307
+ if (fromDate) {
308
+ searchParams.set('fromDate', fromDate.toISOString());
309
+ }
310
+ if (toDate) {
311
+ searchParams.set('toDate', toDate.toISOString());
312
+ }
313
+ if (logLevel) {
314
+ searchParams.set('logLevel', logLevel);
315
+ }
316
+ if (page) {
317
+ searchParams.set('page', String(page));
318
+ }
319
+ if (perPage) {
320
+ searchParams.set('perPage', String(perPage));
321
+ }
322
+
323
+ if (_filters) {
324
+ if (Array.isArray(_filters)) {
325
+ for (const filter of _filters) {
326
+ searchParams.append('filters', filter);
327
+ }
328
+ } else {
329
+ searchParams.set('filters', _filters);
330
+ }
331
+ }
332
+
333
+ if (searchParams.size) {
334
+ return this.request(`/api/logs/${runId}?${searchParams}`);
335
+ } else {
336
+ return this.request(`/api/logs/${runId}`);
337
+ }
178
338
  }
179
339
 
180
340
  /**
@@ -234,10 +394,18 @@ export class MastraClient extends BaseResource {
234
394
  * Retrieves all available networks
235
395
  * @returns Promise containing map of network IDs to network details
236
396
  */
237
- public getNetworks(): Promise<Record<string, GetNetworkResponse>> {
397
+ public getNetworks(): Promise<Array<GetNetworkResponse>> {
238
398
  return this.request('/api/networks');
239
399
  }
240
400
 
401
+ /**
402
+ * Retrieves all available vNext networks
403
+ * @returns Promise containing map of vNext network IDs to vNext network details
404
+ */
405
+ public getVNextNetworks(): Promise<Array<GetVNextNetworkResponse>> {
406
+ return this.request('/api/networks/v-next');
407
+ }
408
+
241
409
  /**
242
410
  * Gets a network instance by ID
243
411
  * @param networkId - ID of the network to retrieve
@@ -248,19 +416,216 @@ export class MastraClient extends BaseResource {
248
416
  }
249
417
 
250
418
  /**
251
- * Retrieves all available MCP servers
252
- * @returns Promise containing map of MCP server IDs to server details
419
+ * Gets a vNext network instance by ID
420
+ * @param networkId - ID of the vNext network to retrieve
421
+ * @returns vNext Network instance
422
+ */
423
+ public getVNextNetwork(networkId: string) {
424
+ return new VNextNetwork(this.options, networkId);
425
+ }
426
+
427
+ /**
428
+ * Retrieves a list of available MCP servers.
429
+ * @param params - Optional parameters for pagination (limit, offset).
430
+ * @returns Promise containing the list of MCP servers and pagination info.
431
+ */
432
+ public getMcpServers(params?: { limit?: number; offset?: number }): Promise<McpServerListResponse> {
433
+ const searchParams = new URLSearchParams();
434
+ if (params?.limit !== undefined) {
435
+ searchParams.set('limit', String(params.limit));
436
+ }
437
+ if (params?.offset !== undefined) {
438
+ searchParams.set('offset', String(params.offset));
439
+ }
440
+ const queryString = searchParams.toString();
441
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ''}`);
442
+ }
443
+
444
+ /**
445
+ * Retrieves detailed information for a specific MCP server.
446
+ * @param serverId - The ID of the MCP server to retrieve.
447
+ * @param params - Optional parameters, e.g., specific version.
448
+ * @returns Promise containing the detailed MCP server information.
253
449
  */
254
- public getMCPServers(): Promise<Record<string, GetMCPServerResponse>> {
255
- return this.request('/api/mcp/servers');
450
+ public getMcpServerDetails(serverId: string, params?: { version?: string }): Promise<ServerDetailInfo> {
451
+ const searchParams = new URLSearchParams();
452
+ if (params?.version) {
453
+ searchParams.set('version', params.version);
454
+ }
455
+ const queryString = searchParams.toString();
456
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ''}`);
457
+ }
458
+
459
+ /**
460
+ * Retrieves a list of tools for a specific MCP server.
461
+ * @param serverId - The ID of the MCP server.
462
+ * @returns Promise containing the list of tools.
463
+ */
464
+ public getMcpServerTools(serverId: string): Promise<McpServerToolListResponse> {
465
+ return this.request(`/api/mcp/${serverId}/tools`);
466
+ }
467
+
468
+ /**
469
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
470
+ * This instance can then be used to fetch details or execute the tool.
471
+ * @param serverId - The ID of the MCP server.
472
+ * @param toolId - The ID of the tool.
473
+ * @returns MCPTool instance.
474
+ */
475
+ public getMcpServerTool(serverId: string, toolId: string): MCPTool {
476
+ return new MCPTool(this.options, serverId, toolId);
477
+ }
478
+
479
+ /**
480
+ * Gets an A2A client for interacting with an agent via the A2A protocol
481
+ * @param agentId - ID of the agent to interact with
482
+ * @returns A2A client instance
483
+ */
484
+ public getA2A(agentId: string) {
485
+ return new A2A(this.options, agentId);
486
+ }
487
+
488
+ /**
489
+ * Retrieves the working memory for a specific thread (optionally resource-scoped).
490
+ * @param agentId - ID of the agent.
491
+ * @param threadId - ID of the thread.
492
+ * @param resourceId - Optional ID of the resource.
493
+ * @returns Working memory for the specified thread or resource.
494
+ */
495
+ public getWorkingMemory({
496
+ agentId,
497
+ threadId,
498
+ resourceId,
499
+ }: {
500
+ agentId: string;
501
+ threadId: string;
502
+ resourceId?: string;
503
+ }) {
504
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}&resourceId=${resourceId}`);
505
+ }
506
+
507
+ /**
508
+ * Updates the working memory for a specific thread (optionally resource-scoped).
509
+ * @param agentId - ID of the agent.
510
+ * @param threadId - ID of the thread.
511
+ * @param workingMemory - The new working memory content.
512
+ * @param resourceId - Optional ID of the resource.
513
+ */
514
+ public updateWorkingMemory({
515
+ agentId,
516
+ threadId,
517
+ workingMemory,
518
+ resourceId,
519
+ }: {
520
+ agentId: string;
521
+ threadId: string;
522
+ workingMemory: string;
523
+ resourceId?: string;
524
+ }) {
525
+ return this.request(`/api/memory/threads/${threadId}/working-memory?agentId=${agentId}`, {
526
+ method: 'POST',
527
+ body: {
528
+ workingMemory,
529
+ resourceId,
530
+ },
531
+ });
532
+ }
533
+
534
+ /**
535
+ * Retrieves all available scorers
536
+ * @returns Promise containing list of available scorers
537
+ */
538
+ public getScorers(): Promise<Record<string, GetScorerResponse>> {
539
+ return this.request('/api/scores/scorers');
540
+ }
541
+
542
+ /**
543
+ * Retrieves a scorer by ID
544
+ * @param scorerId - ID of the scorer to retrieve
545
+ * @returns Promise containing the scorer
546
+ */
547
+ public getScorer(scorerId: string): Promise<GetScorerResponse> {
548
+ return this.request(`/api/scores/scorers/${scorerId}`);
549
+ }
550
+
551
+ public getScoresByScorerId(params: GetScoresByScorerIdParams): Promise<GetScoresResponse> {
552
+ const { page, perPage, scorerId, entityId, entityType } = params;
553
+ const searchParams = new URLSearchParams();
554
+
555
+ if (entityId) {
556
+ searchParams.set('entityId', entityId);
557
+ }
558
+ if (entityType) {
559
+ searchParams.set('entityType', entityType);
560
+ }
561
+
562
+ if (page !== undefined) {
563
+ searchParams.set('page', String(page));
564
+ }
565
+ if (perPage !== undefined) {
566
+ searchParams.set('perPage', String(perPage));
567
+ }
568
+ const queryString = searchParams.toString();
569
+ return this.request(`/api/scores/scorer/${scorerId}${queryString ? `?${queryString}` : ''}`);
570
+ }
571
+
572
+ /**
573
+ * Retrieves scores by run ID
574
+ * @param params - Parameters containing run ID and pagination options
575
+ * @returns Promise containing scores and pagination info
576
+ */
577
+ public getScoresByRunId(params: GetScoresByRunIdParams): Promise<GetScoresResponse> {
578
+ const { runId, page, perPage } = params;
579
+ const searchParams = new URLSearchParams();
580
+
581
+ if (page !== undefined) {
582
+ searchParams.set('page', String(page));
583
+ }
584
+ if (perPage !== undefined) {
585
+ searchParams.set('perPage', String(perPage));
586
+ }
587
+
588
+ const queryString = searchParams.toString();
589
+ return this.request(`/api/scores/run/${runId}${queryString ? `?${queryString}` : ''}`);
590
+ }
591
+
592
+ /**
593
+ * Retrieves scores by entity ID and type
594
+ * @param params - Parameters containing entity ID, type, and pagination options
595
+ * @returns Promise containing scores and pagination info
596
+ */
597
+ public getScoresByEntityId(params: GetScoresByEntityIdParams): Promise<GetScoresResponse> {
598
+ const { entityId, entityType, page, perPage } = params;
599
+ const searchParams = new URLSearchParams();
600
+
601
+ if (page !== undefined) {
602
+ searchParams.set('page', String(page));
603
+ }
604
+ if (perPage !== undefined) {
605
+ searchParams.set('perPage', String(perPage));
606
+ }
607
+
608
+ const queryString = searchParams.toString();
609
+ return this.request(`/api/scores/entity/${entityType}/${entityId}${queryString ? `?${queryString}` : ''}`);
610
+ }
611
+
612
+ /**
613
+ * Saves a score
614
+ * @param params - Parameters containing the score data to save
615
+ * @returns Promise containing the saved score
616
+ */
617
+ public saveScore(params: SaveScoreParams): Promise<SaveScoreResponse> {
618
+ return this.request('/api/scores', {
619
+ method: 'POST',
620
+ body: params,
621
+ });
256
622
  }
257
623
 
258
624
  /**
259
- * Gets an MCP server instance by ID
260
- * @param serverId - ID of the MCP server to retrieve
261
- * @returns MCPServer instance
625
+ * Retrieves model providers with available keys
626
+ * @returns Promise containing model providers with available keys
262
627
  */
263
- public getMCPServer(serverId: string) {
264
- return new MCPServer(this.options, serverId);
628
+ getModelProviders(): Promise<string[]> {
629
+ return this.request(`/api/model-providers`);
265
630
  }
266
631
  }
package/src/example.ts CHANGED
@@ -1,40 +1,70 @@
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
- // });
11
+ console.log('Starting agent...');
10
12
 
11
- // console.log('Starting agent...');
13
+ try {
14
+ const agent = client.getAgent('weatherAgent');
15
+ const response = await agent.stream({
16
+ messages: 'what is the weather in new york?',
17
+ output: z.object({
18
+ weather: z.string(),
19
+ temperature: z.number(),
20
+ humidity: z.number(),
21
+ windSpeed: z.number(),
22
+ windDirection: z.string(),
23
+ windGust: z.number(),
24
+ windChill: z.number(),
25
+ }),
26
+ });
12
27
 
13
- // try {
14
- // const agent = client.getAgent('weatherAgent');
15
- // const response = await agent.stream({
16
- // messages: 'what is the weather in new york?',
17
- // })
28
+ // Process data stream - unstructured output
18
29
 
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
- // });
30
+ // response.processDataStream({
31
+ // onTextPart: text => {
32
+ // process.stdout.write(text);
33
+ // },
34
+ // onFilePart: file => {
35
+ // console.log(file);
36
+ // },
37
+ // onDataPart: data => {
38
+ // console.log(data);
39
+ // },
40
+ // onErrorPart: error => {
41
+ // console.error(error);
42
+ // },
43
+ // onToolCallPart(streamPart) {
44
+ // console.log(streamPart);
45
+ // },
46
+ // });
33
47
 
34
- // } catch (error) {
35
- // console.error(error);
36
- // }
37
- // })();
48
+ // Process text stream - structured output
49
+
50
+ // response.processTextStream({
51
+ // onTextPart: text => {
52
+ // process.stdout.write(text);
53
+ // },
54
+ // });
55
+
56
+ // read the response body directly
57
+
58
+ // const reader = response.body!.getReader();
59
+ // while (true) {
60
+ // const { done, value } = await reader.read();
61
+ // if (done) break;
62
+ // console.log(new TextDecoder().decode(value));
63
+ // }
64
+ } catch (error) {
65
+ console.error(error);
66
+ }
67
+ })();
38
68
 
39
69
  // Workflow
40
70
  // (async () => {