@mastra/client-js 0.0.0-mcp-server-update-parse-20250421171139 → 0.0.0-mcp-server-deploy-20250507160341

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/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
+ import { processDataStream } from '@ai-sdk/ui-utils';
1
2
  import { ZodSchema } from 'zod';
2
3
  import { zodToJsonSchema } from 'zod-to-json-schema';
3
- import { processDataStream } from '@ai-sdk/ui-utils';
4
4
 
5
5
  // src/resources/agent.ts
6
6
 
@@ -371,6 +371,34 @@ var Workflow = class extends BaseResource {
371
371
  details() {
372
372
  return this.request(`/api/workflows/${this.workflowId}`);
373
373
  }
374
+ /**
375
+ * Retrieves all runs for a workflow
376
+ * @param params - Parameters for filtering runs
377
+ * @returns Promise containing workflow runs array
378
+ */
379
+ runs(params) {
380
+ const searchParams = new URLSearchParams();
381
+ if (params?.fromDate) {
382
+ searchParams.set("fromDate", params.fromDate.toISOString());
383
+ }
384
+ if (params?.toDate) {
385
+ searchParams.set("toDate", params.toDate.toISOString());
386
+ }
387
+ if (params?.limit) {
388
+ searchParams.set("limit", String(params.limit));
389
+ }
390
+ if (params?.offset) {
391
+ searchParams.set("offset", String(params.offset));
392
+ }
393
+ if (params?.resourceId) {
394
+ searchParams.set("resourceId", params.resourceId);
395
+ }
396
+ if (searchParams.size) {
397
+ return this.request(`/api/workflows/${this.workflowId}/runs?${searchParams}`);
398
+ } else {
399
+ return this.request(`/api/workflows/${this.workflowId}/runs`);
400
+ }
401
+ }
374
402
  /**
375
403
  * @deprecated Use `startAsync` instead
376
404
  * Executes the workflow with the provided parameters
@@ -487,7 +515,7 @@ var Workflow = class extends BaseResource {
487
515
  }
488
516
  }
489
517
  }
490
- } catch (error) {
518
+ } catch {
491
519
  }
492
520
  }
493
521
  if (buffer) {
@@ -541,13 +569,216 @@ var Tool = class extends BaseResource {
541
569
  * @returns Promise containing the tool execution results
542
570
  */
543
571
  execute(params) {
544
- return this.request(`/api/tools/${this.toolId}/execute`, {
572
+ const url = new URLSearchParams();
573
+ if (params.runId) {
574
+ url.set("runId", params.runId);
575
+ }
576
+ return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
545
577
  method: "POST",
546
- body: params
578
+ body: params.data
547
579
  });
548
580
  }
549
581
  };
550
582
 
583
+ // src/resources/vnext-workflow.ts
584
+ var RECORD_SEPARATOR2 = "";
585
+ var VNextWorkflow = class extends BaseResource {
586
+ constructor(options, workflowId) {
587
+ super(options);
588
+ this.workflowId = workflowId;
589
+ }
590
+ /**
591
+ * Creates an async generator that processes a readable stream and yields vNext workflow records
592
+ * separated by the Record Separator character (\x1E)
593
+ *
594
+ * @param stream - The readable stream to process
595
+ * @returns An async generator that yields parsed records
596
+ */
597
+ async *streamProcessor(stream) {
598
+ const reader = stream.getReader();
599
+ let doneReading = false;
600
+ let buffer = "";
601
+ try {
602
+ while (!doneReading) {
603
+ const { done, value } = await reader.read();
604
+ doneReading = done;
605
+ if (done && !value) continue;
606
+ try {
607
+ const decoded = value ? new TextDecoder().decode(value) : "";
608
+ const chunks = (buffer + decoded).split(RECORD_SEPARATOR2);
609
+ buffer = chunks.pop() || "";
610
+ for (const chunk of chunks) {
611
+ if (chunk) {
612
+ if (typeof chunk === "string") {
613
+ try {
614
+ const parsedChunk = JSON.parse(chunk);
615
+ yield parsedChunk;
616
+ } catch {
617
+ }
618
+ }
619
+ }
620
+ }
621
+ } catch {
622
+ }
623
+ }
624
+ if (buffer) {
625
+ try {
626
+ yield JSON.parse(buffer);
627
+ } catch {
628
+ }
629
+ }
630
+ } finally {
631
+ reader.cancel().catch(() => {
632
+ });
633
+ }
634
+ }
635
+ /**
636
+ * Retrieves details about the vNext workflow
637
+ * @returns Promise containing vNext workflow details including steps and graphs
638
+ */
639
+ details() {
640
+ return this.request(`/api/workflows/v-next/${this.workflowId}`);
641
+ }
642
+ /**
643
+ * Retrieves all runs for a vNext workflow
644
+ * @param params - Parameters for filtering runs
645
+ * @returns Promise containing vNext workflow runs array
646
+ */
647
+ runs(params) {
648
+ const searchParams = new URLSearchParams();
649
+ if (params?.fromDate) {
650
+ searchParams.set("fromDate", params.fromDate.toISOString());
651
+ }
652
+ if (params?.toDate) {
653
+ searchParams.set("toDate", params.toDate.toISOString());
654
+ }
655
+ if (params?.limit) {
656
+ searchParams.set("limit", String(params.limit));
657
+ }
658
+ if (params?.offset) {
659
+ searchParams.set("offset", String(params.offset));
660
+ }
661
+ if (params?.resourceId) {
662
+ searchParams.set("resourceId", params.resourceId);
663
+ }
664
+ if (searchParams.size) {
665
+ return this.request(`/api/workflows/v-next/${this.workflowId}/runs?${searchParams}`);
666
+ } else {
667
+ return this.request(`/api/workflows/v-next/${this.workflowId}/runs`);
668
+ }
669
+ }
670
+ /**
671
+ * Creates a new vNext workflow run
672
+ * @param params - Optional object containing the optional runId
673
+ * @returns Promise containing the runId of the created run
674
+ */
675
+ createRun(params) {
676
+ const searchParams = new URLSearchParams();
677
+ if (!!params?.runId) {
678
+ searchParams.set("runId", params.runId);
679
+ }
680
+ return this.request(`/api/workflows/v-next/${this.workflowId}/create-run?${searchParams.toString()}`, {
681
+ method: "POST"
682
+ });
683
+ }
684
+ /**
685
+ * Starts a vNext workflow run synchronously without waiting for the workflow to complete
686
+ * @param params - Object containing the runId, inputData and runtimeContext
687
+ * @returns Promise containing success message
688
+ */
689
+ start(params) {
690
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start?runId=${params.runId}`, {
691
+ method: "POST",
692
+ body: { inputData: params?.inputData, runtimeContext: params.runtimeContext }
693
+ });
694
+ }
695
+ /**
696
+ * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
697
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
698
+ * @returns Promise containing success message
699
+ */
700
+ resume({
701
+ step,
702
+ runId,
703
+ resumeData,
704
+ runtimeContext
705
+ }) {
706
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume?runId=${runId}`, {
707
+ method: "POST",
708
+ stream: true,
709
+ body: {
710
+ step,
711
+ resumeData,
712
+ runtimeContext
713
+ }
714
+ });
715
+ }
716
+ /**
717
+ * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
718
+ * @param params - Object containing the optional runId, inputData and runtimeContext
719
+ * @returns Promise containing the vNext workflow execution results
720
+ */
721
+ startAsync(params) {
722
+ const searchParams = new URLSearchParams();
723
+ if (!!params?.runId) {
724
+ searchParams.set("runId", params.runId);
725
+ }
726
+ return this.request(`/api/workflows/v-next/${this.workflowId}/start-async?${searchParams.toString()}`, {
727
+ method: "POST",
728
+ body: { inputData: params.inputData, runtimeContext: params.runtimeContext }
729
+ });
730
+ }
731
+ /**
732
+ * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
733
+ * @param params - Object containing the runId, step, resumeData and runtimeContext
734
+ * @returns Promise containing the vNext workflow resume results
735
+ */
736
+ resumeAsync(params) {
737
+ return this.request(`/api/workflows/v-next/${this.workflowId}/resume-async?runId=${params.runId}`, {
738
+ method: "POST",
739
+ body: {
740
+ step: params.step,
741
+ resumeData: params.resumeData,
742
+ runtimeContext: params.runtimeContext
743
+ }
744
+ });
745
+ }
746
+ /**
747
+ * Watches vNext workflow transitions in real-time
748
+ * @param runId - Optional run ID to filter the watch stream
749
+ * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
750
+ */
751
+ async watch({ runId }, onRecord) {
752
+ const response = await this.request(`/api/workflows/v-next/${this.workflowId}/watch?runId=${runId}`, {
753
+ stream: true
754
+ });
755
+ if (!response.ok) {
756
+ throw new Error(`Failed to watch vNext workflow: ${response.statusText}`);
757
+ }
758
+ if (!response.body) {
759
+ throw new Error("Response body is null");
760
+ }
761
+ for await (const record of this.streamProcessor(response.body)) {
762
+ onRecord(record);
763
+ }
764
+ }
765
+ };
766
+
767
+ // src/resources/mcp.ts
768
+ var MCPServer = class extends BaseResource {
769
+ constructor(options, serverId) {
770
+ super(options);
771
+ this.serverId = serverId;
772
+ }
773
+ /**
774
+ * Get details about the MCP server
775
+ * @returns Promise containing server details
776
+ */
777
+ details() {
778
+ return this.request(`/api/mcp/servers/${this.serverId}`);
779
+ }
780
+ };
781
+
551
782
  // src/client.ts
552
783
  var MastraClient = class extends BaseResource {
553
784
  constructor(options) {
@@ -640,6 +871,21 @@ var MastraClient = class extends BaseResource {
640
871
  getWorkflow(workflowId) {
641
872
  return new Workflow(this.options, workflowId);
642
873
  }
874
+ /**
875
+ * Retrieves all available vNext workflows
876
+ * @returns Promise containing map of vNext workflow IDs to vNext workflow details
877
+ */
878
+ getVNextWorkflows() {
879
+ return this.request("/api/workflows/v-next");
880
+ }
881
+ /**
882
+ * Gets a vNext workflow instance by ID
883
+ * @param workflowId - ID of the vNext workflow to retrieve
884
+ * @returns vNext Workflow instance
885
+ */
886
+ getVNextWorkflow(workflowId) {
887
+ return new VNextWorkflow(this.options, workflowId);
888
+ }
643
889
  /**
644
890
  * Gets a vector instance by name
645
891
  * @param vectorName - Name of the vector to retrieve
@@ -677,7 +923,7 @@ var MastraClient = class extends BaseResource {
677
923
  * @returns Promise containing telemetry data
678
924
  */
679
925
  getTelemetry(params) {
680
- const { name, scope, page, perPage, attribute } = params || {};
926
+ const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
681
927
  const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
682
928
  const searchParams = new URLSearchParams();
683
929
  if (name) {
@@ -701,6 +947,12 @@ var MastraClient = class extends BaseResource {
701
947
  searchParams.set("attribute", _attribute);
702
948
  }
703
949
  }
950
+ if (fromDate) {
951
+ searchParams.set("fromDate", fromDate.toISOString());
952
+ }
953
+ if (toDate) {
954
+ searchParams.set("toDate", toDate.toISOString());
955
+ }
704
956
  if (searchParams.size) {
705
957
  return this.request(`/api/telemetry?${searchParams}`);
706
958
  } else {
@@ -722,6 +974,21 @@ var MastraClient = class extends BaseResource {
722
974
  getNetwork(networkId) {
723
975
  return new Network(this.options, networkId);
724
976
  }
977
+ /**
978
+ * Retrieves all available MCP servers
979
+ * @returns Promise containing map of MCP server IDs to server details
980
+ */
981
+ getMCPServers() {
982
+ return this.request("/api/mcp/servers");
983
+ }
984
+ /**
985
+ * Gets an MCP server instance by ID
986
+ * @param serverId - ID of the MCP server to retrieve
987
+ * @returns MCPServer instance
988
+ */
989
+ getMCPServer(serverId) {
990
+ return new MCPServer(this.options, serverId);
991
+ }
725
992
  };
726
993
 
727
994
  export { MastraClient };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.0.0-mcp-server-update-parse-20250421171139",
3
+ "version": "0.0.0-mcp-server-deploy-20250507160341",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -26,7 +26,10 @@
26
26
  "json-schema": "^0.4.0",
27
27
  "zod": "^3.24.2",
28
28
  "zod-to-json-schema": "^3.24.3",
29
- "@mastra/core": "0.0.0-mcp-server-update-parse-20250421171139"
29
+ "@mastra/core": "0.0.0-mcp-server-deploy-20250507160341"
30
+ },
31
+ "peerDependencies": {
32
+ "zod": "^3.24.2"
30
33
  },
31
34
  "devDependencies": {
32
35
  "@babel/preset-env": "^7.26.9",
@@ -36,7 +39,7 @@
36
39
  "@types/node": "^20.17.27",
37
40
  "tsup": "^8.4.0",
38
41
  "typescript": "^5.8.2",
39
- "vitest": "^3.0.9",
42
+ "vitest": "^3.1.2",
40
43
  "@internal/lint": "0.0.2"
41
44
  },
42
45
  "scripts": {
package/src/client.ts CHANGED
@@ -1,4 +1,14 @@
1
- import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network } from './resources';
1
+ import {
2
+ Agent,
3
+ MemoryThread,
4
+ Tool,
5
+ Workflow,
6
+ Vector,
7
+ BaseResource,
8
+ Network,
9
+ VNextWorkflow,
10
+ MCPServer,
11
+ } from './resources';
2
12
  import type {
3
13
  ClientOptions,
4
14
  CreateMemoryThreadParams,
@@ -7,14 +17,15 @@ import type {
7
17
  GetLogParams,
8
18
  GetLogsParams,
9
19
  GetLogsResponse,
20
+ GetMCPServerResponse,
10
21
  GetMemoryThreadParams,
11
22
  GetMemoryThreadResponse,
12
23
  GetNetworkResponse,
13
24
  GetTelemetryParams,
14
25
  GetTelemetryResponse,
15
26
  GetToolResponse,
27
+ GetVNextWorkflowResponse,
16
28
  GetWorkflowResponse,
17
- RequestOptions,
18
29
  SaveMessageToMemoryParams,
19
30
  SaveMessageToMemoryResponse,
20
31
  } from './types';
@@ -122,6 +133,23 @@ export class MastraClient extends BaseResource {
122
133
  return new Workflow(this.options, workflowId);
123
134
  }
124
135
 
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
+
125
153
  /**
126
154
  * Gets a vector instance by name
127
155
  * @param vectorName - Name of the vector to retrieve
@@ -163,17 +191,9 @@ export class MastraClient extends BaseResource {
163
191
  * @returns Promise containing telemetry data
164
192
  */
165
193
  public getTelemetry(params?: GetTelemetryParams): Promise<GetTelemetryResponse> {
166
- const { name, scope, page, perPage, attribute } = params || {};
194
+ const { name, scope, page, perPage, attribute, fromDate, toDate } = params || {};
167
195
  const _attribute = attribute ? Object.entries(attribute).map(([key, value]) => `${key}:${value}`) : [];
168
196
 
169
- const queryObj = {
170
- ...(name ? { name } : {}),
171
- ...(scope ? { scope } : {}),
172
- ...(page ? { page: String(page) } : {}),
173
- ...(perPage ? { perPage: String(perPage) } : {}),
174
- ...(_attribute?.length ? { attribute: _attribute } : {}),
175
- } as const;
176
-
177
197
  const searchParams = new URLSearchParams();
178
198
  if (name) {
179
199
  searchParams.set('name', name);
@@ -196,6 +216,12 @@ export class MastraClient extends BaseResource {
196
216
  searchParams.set('attribute', _attribute);
197
217
  }
198
218
  }
219
+ if (fromDate) {
220
+ searchParams.set('fromDate', fromDate.toISOString());
221
+ }
222
+ if (toDate) {
223
+ searchParams.set('toDate', toDate.toISOString());
224
+ }
199
225
 
200
226
  if (searchParams.size) {
201
227
  return this.request(`/api/telemetry?${searchParams}`);
@@ -220,4 +246,21 @@ export class MastraClient extends BaseResource {
220
246
  public getNetwork(networkId: string) {
221
247
  return new Network(this.options, networkId);
222
248
  }
249
+
250
+ /**
251
+ * Retrieves all available MCP servers
252
+ * @returns Promise containing map of MCP server IDs to server details
253
+ */
254
+ public getMCPServers(): Promise<Record<string, GetMCPServerResponse>> {
255
+ return this.request('/api/mcp/servers');
256
+ }
257
+
258
+ /**
259
+ * Gets an MCP server instance by ID
260
+ * @param serverId - ID of the MCP server to retrieve
261
+ * @returns MCPServer instance
262
+ */
263
+ public getMCPServer(serverId: string) {
264
+ return new MCPServer(this.options, serverId);
265
+ }
223
266
  }
package/src/index.test.ts CHANGED
@@ -1,4 +1,3 @@
1
- import type { MessageType } from '@mastra/core';
2
1
  import { describe, expect, beforeEach, it, vi } from 'vitest';
3
2
 
4
3
  import { MastraClient } from './client';
@@ -489,7 +488,7 @@ describe('MastraClient Resources', () => {
489
488
  const result = await memoryThread.update({
490
489
  title: 'Updated Thread',
491
490
  metadata: { updated: true },
492
- resourceid: 'test-resource',
491
+ resourceId: 'test-resource',
493
492
  });
494
493
  expect(result).toEqual(mockResponse);
495
494
  expect(global.fetch).toHaveBeenCalledWith(
@@ -536,6 +535,7 @@ describe('MastraClient Resources', () => {
536
535
  content: 'test',
537
536
  role: 'user' as const,
538
537
  threadId: 'test-thread',
538
+ resourceId: 'test-resource',
539
539
  createdAt: new Date('2025-03-26T10:40:55.116Z'),
540
540
  },
541
541
  ];
@@ -584,10 +584,10 @@ describe('MastraClient Resources', () => {
584
584
  it('should execute tool', async () => {
585
585
  const mockResponse = { data: 'test' };
586
586
  mockFetchResponse(mockResponse);
587
- const result = await tool.execute({ data: '' });
587
+ const result = await tool.execute({ data: '', runId: 'test-run-id' });
588
588
  expect(result).toEqual(mockResponse);
589
589
  expect(global.fetch).toHaveBeenCalledWith(
590
- `${clientOptions.baseUrl}/api/tools/test-tool/execute`,
590
+ `${clientOptions.baseUrl}/api/tools/test-tool/execute?runId=test-run-id`,
591
591
  expect.objectContaining({
592
592
  method: 'POST',
593
593
  headers: expect.objectContaining({
@@ -1,8 +1,8 @@
1
+ import { processDataStream } from '@ai-sdk/ui-utils';
1
2
  import type { GenerateReturn } from '@mastra/core';
2
3
  import type { JSONSchema7 } from 'json-schema';
3
4
  import { ZodSchema } from 'zod';
4
5
  import { zodToJsonSchema } from 'zod-to-json-schema';
5
- import { processDataStream } from '@ai-sdk/ui-utils';
6
6
 
7
7
  import type {
8
8
  GenerateParams,
@@ -29,7 +29,6 @@ export class AgentTool extends BaseResource {
29
29
  * @param params - Parameters required for tool execution
30
30
  * @returns Promise containing tool execution results
31
31
  */
32
- /** @deprecated use CreateRun/startRun */
33
32
  execute(params: { data: any }): Promise<any> {
34
33
  return this.request(`/api/agents/${this.agentId}/tools/${this.toolId}/execute`, {
35
34
  method: 'POST',
@@ -1,4 +1,4 @@
1
- import type { RequestFunction, RequestOptions, ClientOptions } from '../types';
1
+ import type { RequestOptions, ClientOptions } from '../types';
2
2
 
3
3
  export class BaseResource {
4
4
  readonly options: ClientOptions;
@@ -5,3 +5,5 @@ export * from './vector';
5
5
  export * from './workflow';
6
6
  export * from './tool';
7
7
  export * from './base';
8
+ export * from './vnext-workflow';
9
+ export * from './mcp';
@@ -0,0 +1,22 @@
1
+ import type { ClientOptions, GetMCPServerResponse } from '../types';
2
+ import { BaseResource } from './base';
3
+
4
+ /**
5
+ * MCP Server resource for interacting with MCP servers
6
+ */
7
+ export class MCPServer extends BaseResource {
8
+ constructor(
9
+ options: ClientOptions,
10
+ private serverId: string,
11
+ ) {
12
+ super(options);
13
+ }
14
+
15
+ /**
16
+ * Get details about the MCP server
17
+ * @returns Promise containing server details
18
+ */
19
+ details(): Promise<GetMCPServerResponse> {
20
+ return this.request(`/api/mcp/servers/${this.serverId}`);
21
+ }
22
+ }
@@ -1,13 +1,6 @@
1
1
  import type { StorageThreadType } from '@mastra/core';
2
2
 
3
- import type {
4
- CreateMemoryThreadParams,
5
- GetMemoryThreadMessagesResponse,
6
- GetMemoryThreadResponse,
7
- ClientOptions,
8
- SaveMessageToMemoryParams,
9
- UpdateMemoryThreadParams,
10
- } from '../types';
3
+ import type { GetMemoryThreadMessagesResponse, ClientOptions, UpdateMemoryThreadParams } from '../types';
11
4
 
12
5
  import { BaseResource } from './base';
13
6
 
@@ -1,3 +1,4 @@
1
+ import { processDataStream } from '@ai-sdk/ui-utils';
1
2
  import type { GenerateReturn } from '@mastra/core';
2
3
  import type { JSONSchema7 } from 'json-schema';
3
4
  import { ZodSchema } from 'zod';
@@ -6,7 +7,6 @@ import { zodToJsonSchema } from 'zod-to-json-schema';
6
7
  import type { GenerateParams, ClientOptions, StreamParams, GetNetworkResponse } from '../types';
7
8
 
8
9
  import { BaseResource } from './base';
9
- import { processDataStream } from '@ai-sdk/ui-utils';
10
10
 
11
11
  export class Network extends BaseResource {
12
12
  constructor(
@@ -23,10 +23,16 @@ export class Tool extends BaseResource {
23
23
  * @param params - Parameters required for tool execution
24
24
  * @returns Promise containing the tool execution results
25
25
  */
26
- execute(params: { data: any }): Promise<any> {
27
- return this.request(`/api/tools/${this.toolId}/execute`, {
26
+ execute(params: { data: any; runId?: string }): Promise<any> {
27
+ const url = new URLSearchParams();
28
+
29
+ if (params.runId) {
30
+ url.set('runId', params.runId);
31
+ }
32
+
33
+ return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
28
34
  method: 'POST',
29
- body: params,
35
+ body: params.data,
30
36
  });
31
37
  }
32
38
  }