@mastra/client-js 0.1.22 → 0.1.23-alpha.0

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @mastra/client-js@0.1.22-alpha.4 build /home/runner/work/mastra/mastra/client-sdks/client-js
2
+ > @mastra/client-js@0.1.23-alpha.0 build /home/runner/work/mastra/mastra/client-sdks/client-js
3
3
  > tsup src/index.ts --format esm,cjs --dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -9,11 +9,11 @@
9
9
  CLI Cleaning output folder
10
10
  ESM Build start
11
11
  CJS Build start
12
- ESM dist/index.js 38.25 KB
13
- ESM ⚡️ Build success in 1681ms
14
- CJS dist/index.cjs 38.52 KB
15
- CJS ⚡️ Build success in 1692ms
12
+ CJS dist/index.cjs 41.58 KB
13
+ CJS ⚡️ Build success in 1056ms
14
+ ESM dist/index.js 41.31 KB
15
+ ESM ⚡️ Build success in 1067ms
16
16
  DTS Build start
17
- DTS ⚡️ Build success in 14091ms
18
- DTS dist/index.d.ts 27.63 KB
19
- DTS dist/index.d.cts 27.63 KB
17
+ DTS ⚡️ Build success in 13556ms
18
+ DTS dist/index.d.ts 30.71 KB
19
+ DTS dist/index.d.cts 30.71 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # @mastra/client-js
2
2
 
3
+ ## 0.1.23-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - f53a6ac: Add VNextWorkflowRuns type
8
+ - ccdabdc: Remove trailing / from mastraClient baseUrl
9
+ - a6e3881: Remove non serializable options from agent stream,generate
10
+ - fddae56: Add telemetry to cliend SDK streamParams
11
+ - 23f258c: Add new list and get routes for mcp servers. Changed route make-up for more consistency with existing API routes. Lastly, added in a lot of extra detail that can be optionally passed to the mcp server per the mcp spec.
12
+ - 2672a05: Add MCP servers and tool call execution to playground
13
+ - Updated dependencies [f53a6ac]
14
+ - Updated dependencies [eabdcd9]
15
+ - Updated dependencies [90be034]
16
+ - Updated dependencies [99f050a]
17
+ - Updated dependencies [d0ee3c6]
18
+ - Updated dependencies [23f258c]
19
+ - Updated dependencies [2672a05]
20
+ - @mastra/core@0.9.5-alpha.0
21
+
3
22
  ## 0.1.22
4
23
 
5
24
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -220,7 +220,7 @@ var BaseResource = class {
220
220
  let delay = backoffMs;
221
221
  for (let attempt = 0; attempt <= retries; attempt++) {
222
222
  try {
223
- const response = await fetch(`${baseUrl}${path}`, {
223
+ const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
224
224
  ...options,
225
225
  headers: {
226
226
  ...headers,
@@ -331,8 +331,8 @@ var Agent = class extends BaseResource {
331
331
  generate(params) {
332
332
  const processedParams = {
333
333
  ...params,
334
- output: zodToJsonSchema(params.output),
335
- experimental_output: zodToJsonSchema(params.experimental_output),
334
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
335
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
336
336
  runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
337
337
  };
338
338
  return this.request(`/api/agents/${this.agentId}/generate`, {
@@ -348,8 +348,8 @@ var Agent = class extends BaseResource {
348
348
  async stream(params) {
349
349
  const processedParams = {
350
350
  ...params,
351
- output: zodToJsonSchema(params.output),
352
- experimental_output: zodToJsonSchema(params.experimental_output),
351
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
352
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
353
353
  runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
354
354
  };
355
355
  const response = await this.request(`/api/agents/${this.agentId}/stream`, {
@@ -804,6 +804,8 @@ var Tool = class extends BaseResource {
804
804
  });
805
805
  }
806
806
  };
807
+
808
+ // src/resources/vnext-workflow.ts
807
809
  var RECORD_SEPARATOR2 = "";
808
810
  var VNextWorkflow = class extends BaseResource {
809
811
  constructor(options, workflowId) {
@@ -1065,6 +1067,40 @@ var A2A = class extends BaseResource {
1065
1067
  }
1066
1068
  };
1067
1069
 
1070
+ // src/resources/mcp-tool.ts
1071
+ var MCPTool = class extends BaseResource {
1072
+ serverId;
1073
+ toolId;
1074
+ constructor(options, serverId, toolId) {
1075
+ super(options);
1076
+ this.serverId = serverId;
1077
+ this.toolId = toolId;
1078
+ }
1079
+ /**
1080
+ * Retrieves details about this specific tool from the MCP server.
1081
+ * @returns Promise containing the tool's information (name, description, schema).
1082
+ */
1083
+ details() {
1084
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
1085
+ }
1086
+ /**
1087
+ * Executes this specific tool on the MCP server.
1088
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
1089
+ * @returns Promise containing the result of the tool execution.
1090
+ */
1091
+ execute(params) {
1092
+ const body = {};
1093
+ if (params.data !== void 0) body.data = params.data;
1094
+ if (params.runtimeContext !== void 0) {
1095
+ body.runtimeContext = params.runtimeContext;
1096
+ }
1097
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
1098
+ method: "POST",
1099
+ body: Object.keys(body).length > 0 ? body : void 0
1100
+ });
1101
+ }
1102
+ };
1103
+
1068
1104
  // src/client.ts
1069
1105
  var MastraClient = class extends BaseResource {
1070
1106
  constructor(options) {
@@ -1275,6 +1311,54 @@ var MastraClient = class extends BaseResource {
1275
1311
  getNetwork(networkId) {
1276
1312
  return new Network(this.options, networkId);
1277
1313
  }
1314
+ /**
1315
+ * Retrieves a list of available MCP servers.
1316
+ * @param params - Optional parameters for pagination (limit, offset).
1317
+ * @returns Promise containing the list of MCP servers and pagination info.
1318
+ */
1319
+ getMcpServers(params) {
1320
+ const searchParams = new URLSearchParams();
1321
+ if (params?.limit !== void 0) {
1322
+ searchParams.set("limit", String(params.limit));
1323
+ }
1324
+ if (params?.offset !== void 0) {
1325
+ searchParams.set("offset", String(params.offset));
1326
+ }
1327
+ const queryString = searchParams.toString();
1328
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
1329
+ }
1330
+ /**
1331
+ * Retrieves detailed information for a specific MCP server.
1332
+ * @param serverId - The ID of the MCP server to retrieve.
1333
+ * @param params - Optional parameters, e.g., specific version.
1334
+ * @returns Promise containing the detailed MCP server information.
1335
+ */
1336
+ getMcpServerDetails(serverId, params) {
1337
+ const searchParams = new URLSearchParams();
1338
+ if (params?.version) {
1339
+ searchParams.set("version", params.version);
1340
+ }
1341
+ const queryString = searchParams.toString();
1342
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
1343
+ }
1344
+ /**
1345
+ * Retrieves a list of tools for a specific MCP server.
1346
+ * @param serverId - The ID of the MCP server.
1347
+ * @returns Promise containing the list of tools.
1348
+ */
1349
+ getMcpServerTools(serverId) {
1350
+ return this.request(`/api/mcp/${serverId}/tools`);
1351
+ }
1352
+ /**
1353
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
1354
+ * This instance can then be used to fetch details or execute the tool.
1355
+ * @param serverId - The ID of the MCP server.
1356
+ * @param toolId - The ID of the tool.
1357
+ * @returns MCPTool instance.
1358
+ */
1359
+ getMcpServerTool(serverId, toolId) {
1360
+ return new MCPTool(this.options, serverId, toolId);
1361
+ }
1278
1362
  /**
1279
1363
  * Gets an A2A client for interacting with an agent via the A2A protocol
1280
1364
  * @param agentId - ID of the agent to interact with
package/dist/index.d.cts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { AbstractAgent } from '@ag-ui/client';
2
2
  import { processDataStream } from '@ai-sdk/ui-utils';
3
- import { StepAction, StepGraph, CoreMessage, AiMessageType, StorageThreadType, MessageType, WorkflowRuns, WorkflowRunResult as WorkflowRunResult$1, QueryResult, BaseLogMessage, GenerateReturn } from '@mastra/core';
3
+ import { StepAction, StepGraph, CoreMessage, AiMessageType, StorageThreadType, MessageType, WorkflowRuns, WorkflowRunResult as WorkflowRunResult$1, VNextWorkflowRuns, QueryResult, BaseLogMessage, GenerateReturn } from '@mastra/core';
4
4
  import { JSONSchema7 } from 'json-schema';
5
5
  import { ZodSchema } from 'zod';
6
6
  import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
7
+ import { RuntimeContext } from '@mastra/core/runtime-context';
8
+ import { ServerInfo, ServerDetailInfo } from '@mastra/core/mcp';
7
9
  import { NewWorkflow, WorkflowResult, WatchEvent } from '@mastra/core/workflows/vNext';
8
- import { RuntimeContext } from '@mastra/core/di';
9
- import { RuntimeContext as RuntimeContext$1 } from '@mastra/core/runtime-context';
10
+ import { RuntimeContext as RuntimeContext$1 } from '@mastra/core/di';
10
11
  import { AgentCard, TaskSendParams, Task, TaskQueryParams, TaskIdParams } from '@mastra/core/a2a';
11
12
 
12
13
  interface ClientOptions {
@@ -28,6 +29,11 @@ interface RequestOptions {
28
29
  stream?: boolean;
29
30
  signal?: AbortSignal;
30
31
  }
32
+ type WithoutMethods<T> = {
33
+ [K in keyof T as T[K] extends (...args: any[]) => any ? never : T[K] extends {
34
+ (): any;
35
+ } ? never : T[K] extends undefined | ((...args: any[]) => any) ? never : K]: T[K];
36
+ };
31
37
  interface GetAgentResponse {
32
38
  name: string;
33
39
  instructions: string;
@@ -38,10 +44,16 @@ interface GetAgentResponse {
38
44
  }
39
45
  type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
40
46
  messages: string | string[] | CoreMessage[] | AiMessageType[];
41
- } & Partial<Omit<AgentGenerateOptions<T>, 'experimental_generateMessageId'>>;
47
+ output?: T;
48
+ experimental_output?: T;
49
+ runtimeContext?: RuntimeContext;
50
+ } & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext'>>;
42
51
  type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
43
52
  messages: string | string[] | CoreMessage[] | AiMessageType[];
44
- } & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry' | 'experimental_generateMessageId'>;
53
+ output?: T;
54
+ experimental_output?: T;
55
+ runtimeContext?: RuntimeContext;
56
+ } & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext'>>;
45
57
  interface GetEvalsByAgentIdResponse extends GetAgentResponse {
46
58
  evals: any[];
47
59
  instructions: string;
@@ -70,6 +82,7 @@ interface GetWorkflowRunsParams {
70
82
  resourceId?: string;
71
83
  }
72
84
  type GetWorkflowRunsResponse = WorkflowRuns;
85
+ type GetVNextWorkflowRunsResponse = VNextWorkflowRuns;
73
86
  type WorkflowRunResult = {
74
87
  activePaths: Record<string, {
75
88
  status: string;
@@ -231,6 +244,20 @@ interface GetNetworkResponse {
231
244
  };
232
245
  state?: Record<string, any>;
233
246
  }
247
+ interface McpServerListResponse {
248
+ servers: ServerInfo[];
249
+ next: string | null;
250
+ total_count: number;
251
+ }
252
+ interface McpToolInfo {
253
+ id: string;
254
+ name: string;
255
+ description?: string;
256
+ inputSchema: string;
257
+ }
258
+ interface McpServerToolListResponse {
259
+ tools: McpToolInfo[];
260
+ }
234
261
 
235
262
  declare class BaseResource {
236
263
  readonly options: ClientOptions;
@@ -312,7 +339,7 @@ declare class Agent extends BaseResource {
312
339
  */
313
340
  executeTool(toolId: string, params: {
314
341
  data: any;
315
- runtimeContext?: RuntimeContext;
342
+ runtimeContext?: RuntimeContext$1;
316
343
  }): Promise<any>;
317
344
  /**
318
345
  * Retrieves evaluation results for the agent
@@ -534,7 +561,7 @@ declare class Tool extends BaseResource {
534
561
  execute(params: {
535
562
  data: any;
536
563
  runId?: string;
537
- runtimeContext?: RuntimeContext;
564
+ runtimeContext?: RuntimeContext$1;
538
565
  }): Promise<any>;
539
566
  }
540
567
 
@@ -559,7 +586,7 @@ declare class VNextWorkflow extends BaseResource {
559
586
  * @param params - Parameters for filtering runs
560
587
  * @returns Promise containing vNext workflow runs array
561
588
  */
562
- runs(params?: GetWorkflowRunsParams): Promise<GetWorkflowRunsResponse>;
589
+ runs(params?: GetWorkflowRunsParams): Promise<GetVNextWorkflowRunsResponse>;
563
590
  /**
564
591
  * Creates a new vNext workflow run
565
592
  * @param params - Optional object containing the optional runId
@@ -578,7 +605,7 @@ declare class VNextWorkflow extends BaseResource {
578
605
  start(params: {
579
606
  runId: string;
580
607
  inputData: Record<string, any>;
581
- runtimeContext?: RuntimeContext$1;
608
+ runtimeContext?: RuntimeContext;
582
609
  }): Promise<{
583
610
  message: string;
584
611
  }>;
@@ -591,7 +618,7 @@ declare class VNextWorkflow extends BaseResource {
591
618
  step: string | string[];
592
619
  runId: string;
593
620
  resumeData?: Record<string, any>;
594
- runtimeContext?: RuntimeContext$1;
621
+ runtimeContext?: RuntimeContext;
595
622
  }): Promise<{
596
623
  message: string;
597
624
  }>;
@@ -603,7 +630,7 @@ declare class VNextWorkflow extends BaseResource {
603
630
  startAsync(params: {
604
631
  runId?: string;
605
632
  inputData: Record<string, any>;
606
- runtimeContext?: RuntimeContext$1;
633
+ runtimeContext?: RuntimeContext;
607
634
  }): Promise<VNextWorkflowRunResult>;
608
635
  /**
609
636
  * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
@@ -614,7 +641,7 @@ declare class VNextWorkflow extends BaseResource {
614
641
  runId: string;
615
642
  step: string | string[];
616
643
  resumeData?: Record<string, any>;
617
- runtimeContext?: RuntimeContext$1;
644
+ runtimeContext?: RuntimeContext;
618
645
  }): Promise<VNextWorkflowRunResult>;
619
646
  /**
620
647
  * Watches vNext workflow transitions in real-time
@@ -667,6 +694,30 @@ declare class A2A extends BaseResource {
667
694
  sendAndSubscribe(params: TaskSendParams): Promise<Response>;
668
695
  }
669
696
 
697
+ /**
698
+ * Represents a specific tool available on a specific MCP server.
699
+ * Provides methods to get details and execute the tool.
700
+ */
701
+ declare class MCPTool extends BaseResource {
702
+ private serverId;
703
+ private toolId;
704
+ constructor(options: ClientOptions, serverId: string, toolId: string);
705
+ /**
706
+ * Retrieves details about this specific tool from the MCP server.
707
+ * @returns Promise containing the tool's information (name, description, schema).
708
+ */
709
+ details(): Promise<McpToolInfo>;
710
+ /**
711
+ * Executes this specific tool on the MCP server.
712
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
713
+ * @returns Promise containing the result of the tool execution.
714
+ */
715
+ execute(params: {
716
+ data?: any;
717
+ runtimeContext?: RuntimeContext;
718
+ }): Promise<any>;
719
+ }
720
+
670
721
  declare class MastraClient extends BaseResource {
671
722
  constructor(options: ClientOptions);
672
723
  /**
@@ -789,6 +840,38 @@ declare class MastraClient extends BaseResource {
789
840
  * @returns Network instance
790
841
  */
791
842
  getNetwork(networkId: string): Network;
843
+ /**
844
+ * Retrieves a list of available MCP servers.
845
+ * @param params - Optional parameters for pagination (limit, offset).
846
+ * @returns Promise containing the list of MCP servers and pagination info.
847
+ */
848
+ getMcpServers(params?: {
849
+ limit?: number;
850
+ offset?: number;
851
+ }): Promise<McpServerListResponse>;
852
+ /**
853
+ * Retrieves detailed information for a specific MCP server.
854
+ * @param serverId - The ID of the MCP server to retrieve.
855
+ * @param params - Optional parameters, e.g., specific version.
856
+ * @returns Promise containing the detailed MCP server information.
857
+ */
858
+ getMcpServerDetails(serverId: string, params?: {
859
+ version?: string;
860
+ }): Promise<ServerDetailInfo>;
861
+ /**
862
+ * Retrieves a list of tools for a specific MCP server.
863
+ * @param serverId - The ID of the MCP server.
864
+ * @returns Promise containing the list of tools.
865
+ */
866
+ getMcpServerTools(serverId: string): Promise<McpServerToolListResponse>;
867
+ /**
868
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
869
+ * This instance can then be used to fetch details or execute the tool.
870
+ * @param serverId - The ID of the MCP server.
871
+ * @param toolId - The ID of the tool.
872
+ * @returns MCPTool instance.
873
+ */
874
+ getMcpServerTool(serverId: string, toolId: string): MCPTool;
792
875
  /**
793
876
  * Gets an A2A client for interacting with an agent via the A2A protocol
794
877
  * @param agentId - ID of the agent to interact with
@@ -797,4 +880,4 @@ declare class MastraClient extends BaseResource {
797
880
  getA2A(agentId: string): A2A;
798
881
  }
799
882
 
800
- export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesParams, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextWorkflowResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type VNextWorkflowRunResult, type VNextWorkflowWatchResult, type WorkflowRunResult };
883
+ export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesParams, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextWorkflowResponse, type GetVNextWorkflowRunsResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, MastraClient, type McpServerListResponse, type McpServerToolListResponse, type McpToolInfo, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type VNextWorkflowRunResult, type VNextWorkflowWatchResult, type WorkflowRunResult };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  import { AbstractAgent } from '@ag-ui/client';
2
2
  import { processDataStream } from '@ai-sdk/ui-utils';
3
- import { StepAction, StepGraph, CoreMessage, AiMessageType, StorageThreadType, MessageType, WorkflowRuns, WorkflowRunResult as WorkflowRunResult$1, QueryResult, BaseLogMessage, GenerateReturn } from '@mastra/core';
3
+ import { StepAction, StepGraph, CoreMessage, AiMessageType, StorageThreadType, MessageType, WorkflowRuns, WorkflowRunResult as WorkflowRunResult$1, VNextWorkflowRuns, QueryResult, BaseLogMessage, GenerateReturn } from '@mastra/core';
4
4
  import { JSONSchema7 } from 'json-schema';
5
5
  import { ZodSchema } from 'zod';
6
6
  import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
7
+ import { RuntimeContext } from '@mastra/core/runtime-context';
8
+ import { ServerInfo, ServerDetailInfo } from '@mastra/core/mcp';
7
9
  import { NewWorkflow, WorkflowResult, WatchEvent } from '@mastra/core/workflows/vNext';
8
- import { RuntimeContext } from '@mastra/core/di';
9
- import { RuntimeContext as RuntimeContext$1 } from '@mastra/core/runtime-context';
10
+ import { RuntimeContext as RuntimeContext$1 } from '@mastra/core/di';
10
11
  import { AgentCard, TaskSendParams, Task, TaskQueryParams, TaskIdParams } from '@mastra/core/a2a';
11
12
 
12
13
  interface ClientOptions {
@@ -28,6 +29,11 @@ interface RequestOptions {
28
29
  stream?: boolean;
29
30
  signal?: AbortSignal;
30
31
  }
32
+ type WithoutMethods<T> = {
33
+ [K in keyof T as T[K] extends (...args: any[]) => any ? never : T[K] extends {
34
+ (): any;
35
+ } ? never : T[K] extends undefined | ((...args: any[]) => any) ? never : K]: T[K];
36
+ };
31
37
  interface GetAgentResponse {
32
38
  name: string;
33
39
  instructions: string;
@@ -38,10 +44,16 @@ interface GetAgentResponse {
38
44
  }
39
45
  type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
40
46
  messages: string | string[] | CoreMessage[] | AiMessageType[];
41
- } & Partial<Omit<AgentGenerateOptions<T>, 'experimental_generateMessageId'>>;
47
+ output?: T;
48
+ experimental_output?: T;
49
+ runtimeContext?: RuntimeContext;
50
+ } & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext'>>;
42
51
  type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
43
52
  messages: string | string[] | CoreMessage[] | AiMessageType[];
44
- } & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry' | 'experimental_generateMessageId'>;
53
+ output?: T;
54
+ experimental_output?: T;
55
+ runtimeContext?: RuntimeContext;
56
+ } & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext'>>;
45
57
  interface GetEvalsByAgentIdResponse extends GetAgentResponse {
46
58
  evals: any[];
47
59
  instructions: string;
@@ -70,6 +82,7 @@ interface GetWorkflowRunsParams {
70
82
  resourceId?: string;
71
83
  }
72
84
  type GetWorkflowRunsResponse = WorkflowRuns;
85
+ type GetVNextWorkflowRunsResponse = VNextWorkflowRuns;
73
86
  type WorkflowRunResult = {
74
87
  activePaths: Record<string, {
75
88
  status: string;
@@ -231,6 +244,20 @@ interface GetNetworkResponse {
231
244
  };
232
245
  state?: Record<string, any>;
233
246
  }
247
+ interface McpServerListResponse {
248
+ servers: ServerInfo[];
249
+ next: string | null;
250
+ total_count: number;
251
+ }
252
+ interface McpToolInfo {
253
+ id: string;
254
+ name: string;
255
+ description?: string;
256
+ inputSchema: string;
257
+ }
258
+ interface McpServerToolListResponse {
259
+ tools: McpToolInfo[];
260
+ }
234
261
 
235
262
  declare class BaseResource {
236
263
  readonly options: ClientOptions;
@@ -312,7 +339,7 @@ declare class Agent extends BaseResource {
312
339
  */
313
340
  executeTool(toolId: string, params: {
314
341
  data: any;
315
- runtimeContext?: RuntimeContext;
342
+ runtimeContext?: RuntimeContext$1;
316
343
  }): Promise<any>;
317
344
  /**
318
345
  * Retrieves evaluation results for the agent
@@ -534,7 +561,7 @@ declare class Tool extends BaseResource {
534
561
  execute(params: {
535
562
  data: any;
536
563
  runId?: string;
537
- runtimeContext?: RuntimeContext;
564
+ runtimeContext?: RuntimeContext$1;
538
565
  }): Promise<any>;
539
566
  }
540
567
 
@@ -559,7 +586,7 @@ declare class VNextWorkflow extends BaseResource {
559
586
  * @param params - Parameters for filtering runs
560
587
  * @returns Promise containing vNext workflow runs array
561
588
  */
562
- runs(params?: GetWorkflowRunsParams): Promise<GetWorkflowRunsResponse>;
589
+ runs(params?: GetWorkflowRunsParams): Promise<GetVNextWorkflowRunsResponse>;
563
590
  /**
564
591
  * Creates a new vNext workflow run
565
592
  * @param params - Optional object containing the optional runId
@@ -578,7 +605,7 @@ declare class VNextWorkflow extends BaseResource {
578
605
  start(params: {
579
606
  runId: string;
580
607
  inputData: Record<string, any>;
581
- runtimeContext?: RuntimeContext$1;
608
+ runtimeContext?: RuntimeContext;
582
609
  }): Promise<{
583
610
  message: string;
584
611
  }>;
@@ -591,7 +618,7 @@ declare class VNextWorkflow extends BaseResource {
591
618
  step: string | string[];
592
619
  runId: string;
593
620
  resumeData?: Record<string, any>;
594
- runtimeContext?: RuntimeContext$1;
621
+ runtimeContext?: RuntimeContext;
595
622
  }): Promise<{
596
623
  message: string;
597
624
  }>;
@@ -603,7 +630,7 @@ declare class VNextWorkflow extends BaseResource {
603
630
  startAsync(params: {
604
631
  runId?: string;
605
632
  inputData: Record<string, any>;
606
- runtimeContext?: RuntimeContext$1;
633
+ runtimeContext?: RuntimeContext;
607
634
  }): Promise<VNextWorkflowRunResult>;
608
635
  /**
609
636
  * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
@@ -614,7 +641,7 @@ declare class VNextWorkflow extends BaseResource {
614
641
  runId: string;
615
642
  step: string | string[];
616
643
  resumeData?: Record<string, any>;
617
- runtimeContext?: RuntimeContext$1;
644
+ runtimeContext?: RuntimeContext;
618
645
  }): Promise<VNextWorkflowRunResult>;
619
646
  /**
620
647
  * Watches vNext workflow transitions in real-time
@@ -667,6 +694,30 @@ declare class A2A extends BaseResource {
667
694
  sendAndSubscribe(params: TaskSendParams): Promise<Response>;
668
695
  }
669
696
 
697
+ /**
698
+ * Represents a specific tool available on a specific MCP server.
699
+ * Provides methods to get details and execute the tool.
700
+ */
701
+ declare class MCPTool extends BaseResource {
702
+ private serverId;
703
+ private toolId;
704
+ constructor(options: ClientOptions, serverId: string, toolId: string);
705
+ /**
706
+ * Retrieves details about this specific tool from the MCP server.
707
+ * @returns Promise containing the tool's information (name, description, schema).
708
+ */
709
+ details(): Promise<McpToolInfo>;
710
+ /**
711
+ * Executes this specific tool on the MCP server.
712
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
713
+ * @returns Promise containing the result of the tool execution.
714
+ */
715
+ execute(params: {
716
+ data?: any;
717
+ runtimeContext?: RuntimeContext;
718
+ }): Promise<any>;
719
+ }
720
+
670
721
  declare class MastraClient extends BaseResource {
671
722
  constructor(options: ClientOptions);
672
723
  /**
@@ -789,6 +840,38 @@ declare class MastraClient extends BaseResource {
789
840
  * @returns Network instance
790
841
  */
791
842
  getNetwork(networkId: string): Network;
843
+ /**
844
+ * Retrieves a list of available MCP servers.
845
+ * @param params - Optional parameters for pagination (limit, offset).
846
+ * @returns Promise containing the list of MCP servers and pagination info.
847
+ */
848
+ getMcpServers(params?: {
849
+ limit?: number;
850
+ offset?: number;
851
+ }): Promise<McpServerListResponse>;
852
+ /**
853
+ * Retrieves detailed information for a specific MCP server.
854
+ * @param serverId - The ID of the MCP server to retrieve.
855
+ * @param params - Optional parameters, e.g., specific version.
856
+ * @returns Promise containing the detailed MCP server information.
857
+ */
858
+ getMcpServerDetails(serverId: string, params?: {
859
+ version?: string;
860
+ }): Promise<ServerDetailInfo>;
861
+ /**
862
+ * Retrieves a list of tools for a specific MCP server.
863
+ * @param serverId - The ID of the MCP server.
864
+ * @returns Promise containing the list of tools.
865
+ */
866
+ getMcpServerTools(serverId: string): Promise<McpServerToolListResponse>;
867
+ /**
868
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
869
+ * This instance can then be used to fetch details or execute the tool.
870
+ * @param serverId - The ID of the MCP server.
871
+ * @param toolId - The ID of the tool.
872
+ * @returns MCPTool instance.
873
+ */
874
+ getMcpServerTool(serverId: string, toolId: string): MCPTool;
792
875
  /**
793
876
  * Gets an A2A client for interacting with an agent via the A2A protocol
794
877
  * @param agentId - ID of the agent to interact with
@@ -797,4 +880,4 @@ declare class MastraClient extends BaseResource {
797
880
  getA2A(agentId: string): A2A;
798
881
  }
799
882
 
800
- export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesParams, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextWorkflowResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, MastraClient, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type VNextWorkflowRunResult, type VNextWorkflowWatchResult, type WorkflowRunResult };
883
+ export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesParams, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVNextWorkflowResponse, type GetVNextWorkflowRunsResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, MastraClient, type McpServerListResponse, type McpServerToolListResponse, type McpToolInfo, type QueryVectorParams, type QueryVectorResponse, type RequestFunction, type RequestOptions, type SaveMessageToMemoryParams, type SaveMessageToMemoryResponse, type StreamParams, type UpdateMemoryThreadParams, type UpsertVectorParams, type VNextWorkflowRunResult, type VNextWorkflowWatchResult, type WorkflowRunResult };
package/dist/index.js CHANGED
@@ -214,7 +214,7 @@ var BaseResource = class {
214
214
  let delay = backoffMs;
215
215
  for (let attempt = 0; attempt <= retries; attempt++) {
216
216
  try {
217
- const response = await fetch(`${baseUrl}${path}`, {
217
+ const response = await fetch(`${baseUrl.replace(/\/$/, "")}${path}`, {
218
218
  ...options,
219
219
  headers: {
220
220
  ...headers,
@@ -325,8 +325,8 @@ var Agent = class extends BaseResource {
325
325
  generate(params) {
326
326
  const processedParams = {
327
327
  ...params,
328
- output: zodToJsonSchema(params.output),
329
- experimental_output: zodToJsonSchema(params.experimental_output),
328
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
329
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
330
330
  runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
331
331
  };
332
332
  return this.request(`/api/agents/${this.agentId}/generate`, {
@@ -342,8 +342,8 @@ var Agent = class extends BaseResource {
342
342
  async stream(params) {
343
343
  const processedParams = {
344
344
  ...params,
345
- output: zodToJsonSchema(params.output),
346
- experimental_output: zodToJsonSchema(params.experimental_output),
345
+ output: params.output ? zodToJsonSchema(params.output) : void 0,
346
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : void 0,
347
347
  runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : void 0
348
348
  };
349
349
  const response = await this.request(`/api/agents/${this.agentId}/stream`, {
@@ -798,6 +798,8 @@ var Tool = class extends BaseResource {
798
798
  });
799
799
  }
800
800
  };
801
+
802
+ // src/resources/vnext-workflow.ts
801
803
  var RECORD_SEPARATOR2 = "";
802
804
  var VNextWorkflow = class extends BaseResource {
803
805
  constructor(options, workflowId) {
@@ -1059,6 +1061,40 @@ var A2A = class extends BaseResource {
1059
1061
  }
1060
1062
  };
1061
1063
 
1064
+ // src/resources/mcp-tool.ts
1065
+ var MCPTool = class extends BaseResource {
1066
+ serverId;
1067
+ toolId;
1068
+ constructor(options, serverId, toolId) {
1069
+ super(options);
1070
+ this.serverId = serverId;
1071
+ this.toolId = toolId;
1072
+ }
1073
+ /**
1074
+ * Retrieves details about this specific tool from the MCP server.
1075
+ * @returns Promise containing the tool's information (name, description, schema).
1076
+ */
1077
+ details() {
1078
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
1079
+ }
1080
+ /**
1081
+ * Executes this specific tool on the MCP server.
1082
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
1083
+ * @returns Promise containing the result of the tool execution.
1084
+ */
1085
+ execute(params) {
1086
+ const body = {};
1087
+ if (params.data !== void 0) body.data = params.data;
1088
+ if (params.runtimeContext !== void 0) {
1089
+ body.runtimeContext = params.runtimeContext;
1090
+ }
1091
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
1092
+ method: "POST",
1093
+ body: Object.keys(body).length > 0 ? body : void 0
1094
+ });
1095
+ }
1096
+ };
1097
+
1062
1098
  // src/client.ts
1063
1099
  var MastraClient = class extends BaseResource {
1064
1100
  constructor(options) {
@@ -1269,6 +1305,54 @@ var MastraClient = class extends BaseResource {
1269
1305
  getNetwork(networkId) {
1270
1306
  return new Network(this.options, networkId);
1271
1307
  }
1308
+ /**
1309
+ * Retrieves a list of available MCP servers.
1310
+ * @param params - Optional parameters for pagination (limit, offset).
1311
+ * @returns Promise containing the list of MCP servers and pagination info.
1312
+ */
1313
+ getMcpServers(params) {
1314
+ const searchParams = new URLSearchParams();
1315
+ if (params?.limit !== void 0) {
1316
+ searchParams.set("limit", String(params.limit));
1317
+ }
1318
+ if (params?.offset !== void 0) {
1319
+ searchParams.set("offset", String(params.offset));
1320
+ }
1321
+ const queryString = searchParams.toString();
1322
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ""}`);
1323
+ }
1324
+ /**
1325
+ * Retrieves detailed information for a specific MCP server.
1326
+ * @param serverId - The ID of the MCP server to retrieve.
1327
+ * @param params - Optional parameters, e.g., specific version.
1328
+ * @returns Promise containing the detailed MCP server information.
1329
+ */
1330
+ getMcpServerDetails(serverId, params) {
1331
+ const searchParams = new URLSearchParams();
1332
+ if (params?.version) {
1333
+ searchParams.set("version", params.version);
1334
+ }
1335
+ const queryString = searchParams.toString();
1336
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ""}`);
1337
+ }
1338
+ /**
1339
+ * Retrieves a list of tools for a specific MCP server.
1340
+ * @param serverId - The ID of the MCP server.
1341
+ * @returns Promise containing the list of tools.
1342
+ */
1343
+ getMcpServerTools(serverId) {
1344
+ return this.request(`/api/mcp/${serverId}/tools`);
1345
+ }
1346
+ /**
1347
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
1348
+ * This instance can then be used to fetch details or execute the tool.
1349
+ * @param serverId - The ID of the MCP server.
1350
+ * @param toolId - The ID of the tool.
1351
+ * @returns MCPTool instance.
1352
+ */
1353
+ getMcpServerTool(serverId, toolId) {
1354
+ return new MCPTool(this.options, serverId, toolId);
1355
+ }
1272
1356
  /**
1273
1357
  * Gets an A2A client for interacting with an agent via the A2A protocol
1274
1358
  * @param agentId - ID of the agent to interact with
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/client-js",
3
- "version": "0.1.22",
3
+ "version": "0.1.23-alpha.0",
4
4
  "description": "The official TypeScript library for the Mastra Client API",
5
5
  "author": "",
6
6
  "type": "module",
@@ -28,7 +28,7 @@
28
28
  "rxjs": "7.8.1",
29
29
  "zod": "^3.24.3",
30
30
  "zod-to-json-schema": "^3.24.5",
31
- "@mastra/core": "^0.9.4"
31
+ "@mastra/core": "^0.9.5-alpha.0"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "zod": "^3.0.0"
package/src/client.ts CHANGED
@@ -1,6 +1,17 @@
1
1
  import type { AbstractAgent } from '@ag-ui/client';
2
2
  import { AGUIAdapter } from './adapters/agui';
3
- import { Agent, MemoryThread, Tool, Workflow, Vector, BaseResource, Network, VNextWorkflow, A2A } from './resources';
3
+ import {
4
+ Agent,
5
+ MemoryThread,
6
+ Tool,
7
+ Workflow,
8
+ Vector,
9
+ BaseResource,
10
+ Network,
11
+ VNextWorkflow,
12
+ A2A,
13
+ MCPTool,
14
+ } from './resources';
4
15
  import type {
5
16
  ClientOptions,
6
17
  CreateMemoryThreadParams,
@@ -19,7 +30,11 @@ import type {
19
30
  GetWorkflowResponse,
20
31
  SaveMessageToMemoryParams,
21
32
  SaveMessageToMemoryResponse,
33
+ McpServerListResponse,
34
+ McpServerToolListResponse,
35
+ McpToolInfo,
22
36
  } from './types';
37
+ import type { ServerDetailInfo } from '@mastra/core/mcp';
23
38
 
24
39
  export class MastraClient extends BaseResource {
25
40
  constructor(options: ClientOptions) {
@@ -257,6 +272,58 @@ export class MastraClient extends BaseResource {
257
272
  return new Network(this.options, networkId);
258
273
  }
259
274
 
275
+ /**
276
+ * Retrieves a list of available MCP servers.
277
+ * @param params - Optional parameters for pagination (limit, offset).
278
+ * @returns Promise containing the list of MCP servers and pagination info.
279
+ */
280
+ public getMcpServers(params?: { limit?: number; offset?: number }): Promise<McpServerListResponse> {
281
+ const searchParams = new URLSearchParams();
282
+ if (params?.limit !== undefined) {
283
+ searchParams.set('limit', String(params.limit));
284
+ }
285
+ if (params?.offset !== undefined) {
286
+ searchParams.set('offset', String(params.offset));
287
+ }
288
+ const queryString = searchParams.toString();
289
+ return this.request(`/api/mcp/v0/servers${queryString ? `?${queryString}` : ''}`);
290
+ }
291
+
292
+ /**
293
+ * Retrieves detailed information for a specific MCP server.
294
+ * @param serverId - The ID of the MCP server to retrieve.
295
+ * @param params - Optional parameters, e.g., specific version.
296
+ * @returns Promise containing the detailed MCP server information.
297
+ */
298
+ public getMcpServerDetails(serverId: string, params?: { version?: string }): Promise<ServerDetailInfo> {
299
+ const searchParams = new URLSearchParams();
300
+ if (params?.version) {
301
+ searchParams.set('version', params.version);
302
+ }
303
+ const queryString = searchParams.toString();
304
+ return this.request(`/api/mcp/v0/servers/${serverId}${queryString ? `?${queryString}` : ''}`);
305
+ }
306
+
307
+ /**
308
+ * Retrieves a list of tools for a specific MCP server.
309
+ * @param serverId - The ID of the MCP server.
310
+ * @returns Promise containing the list of tools.
311
+ */
312
+ public getMcpServerTools(serverId: string): Promise<McpServerToolListResponse> {
313
+ return this.request(`/api/mcp/${serverId}/tools`);
314
+ }
315
+
316
+ /**
317
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
318
+ * This instance can then be used to fetch details or execute the tool.
319
+ * @param serverId - The ID of the MCP server.
320
+ * @param toolId - The ID of the tool.
321
+ * @returns MCPTool instance.
322
+ */
323
+ public getMcpServerTool(serverId: string, toolId: string): MCPTool {
324
+ return new MCPTool(this.options, serverId, toolId);
325
+ }
326
+
260
327
  /**
261
328
  * Gets an A2A client for interacting with an agent via the A2A protocol
262
329
  * @param agentId - ID of the agent to interact with
package/src/example.ts CHANGED
@@ -1,40 +1,39 @@
1
- // import { MastraClient } from './client';
1
+ import { MastraClient } from './client';
2
2
  // import type { WorkflowRunResult } from './types';
3
3
 
4
4
  // Agent
5
5
 
6
- // (async () => {
7
- // const client = new MastraClient({
8
- // baseUrl: 'http://localhost:4111',
9
- // });
6
+ (async () => {
7
+ const client = new MastraClient({
8
+ baseUrl: 'http://localhost:4111',
9
+ });
10
10
 
11
- // console.log('Starting agent...');
11
+ console.log('Starting agent...');
12
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
- // })
13
+ try {
14
+ const agent = client.getAgent('weatherAgent');
15
+ const response = await agent.stream({
16
+ messages: 'what is the weather in new york?',
17
+ });
18
18
 
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
- // });
33
-
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
+ });
33
+ } catch (error) {
34
+ console.error(error);
35
+ }
36
+ })();
38
37
 
39
38
  // Workflow
40
39
  // (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();
@@ -737,4 +737,94 @@ describe('MastraClient Resources', () => {
737
737
  );
738
738
  });
739
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
+ });
740
830
  });
@@ -100,8 +100,8 @@ export class Agent extends BaseResource {
100
100
  ): Promise<GenerateReturn<T>> {
101
101
  const processedParams = {
102
102
  ...params,
103
- output: zodToJsonSchema(params.output),
104
- experimental_output: zodToJsonSchema(params.experimental_output),
103
+ output: params.output ? zodToJsonSchema(params.output) : undefined,
104
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : undefined,
105
105
  runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
106
106
  };
107
107
 
@@ -125,8 +125,8 @@ export class Agent extends BaseResource {
125
125
  > {
126
126
  const processedParams = {
127
127
  ...params,
128
- output: zodToJsonSchema(params.output),
129
- experimental_output: zodToJsonSchema(params.experimental_output),
128
+ output: params.output ? zodToJsonSchema(params.output) : undefined,
129
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : undefined,
130
130
  runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
131
131
  };
132
132
 
@@ -21,7 +21,7 @@ export class BaseResource {
21
21
 
22
22
  for (let attempt = 0; attempt <= retries; attempt++) {
23
23
  try {
24
- const response = await fetch(`${baseUrl}${path}`, {
24
+ const response = await fetch(`${baseUrl.replace(/\/$/, '')}${path}`, {
25
25
  ...options,
26
26
  headers: {
27
27
  ...headers,
@@ -7,3 +7,4 @@ export * from './tool';
7
7
  export * from './base';
8
8
  export * from './vnext-workflow';
9
9
  export * from './a2a';
10
+ export * from './mcp-tool';
@@ -0,0 +1,48 @@
1
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
2
+ import type { ClientOptions, McpToolInfo } from '../types';
3
+ import { BaseResource } from './base';
4
+
5
+ /**
6
+ * Represents a specific tool available on a specific MCP server.
7
+ * Provides methods to get details and execute the tool.
8
+ */
9
+ export class MCPTool extends BaseResource {
10
+ private serverId: string;
11
+ private toolId: string;
12
+
13
+ constructor(options: ClientOptions, serverId: string, toolId: string) {
14
+ super(options);
15
+ this.serverId = serverId;
16
+ this.toolId = toolId;
17
+ }
18
+
19
+ /**
20
+ * Retrieves details about this specific tool from the MCP server.
21
+ * @returns Promise containing the tool's information (name, description, schema).
22
+ */
23
+ details(): Promise<McpToolInfo> {
24
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}`);
25
+ }
26
+
27
+ /**
28
+ * Executes this specific tool on the MCP server.
29
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
30
+ * @returns Promise containing the result of the tool execution.
31
+ */
32
+ execute(params: { data?: any; runtimeContext?: RuntimeContext }): Promise<any> {
33
+ const body: any = {};
34
+ if (params.data !== undefined) body.data = params.data;
35
+ // If none of data, args the body might be empty or just contain runtimeContext.
36
+ // The handler will look for these, so an empty args object might be appropriate if that's the intent.
37
+ // else body.data = {}; // Or let it be empty if no specific input fields are used
38
+
39
+ if (params.runtimeContext !== undefined) {
40
+ body.runtimeContext = params.runtimeContext;
41
+ }
42
+
43
+ return this.request(`/api/mcp/${this.serverId}/tools/${this.toolId}/execute`, {
44
+ method: 'POST',
45
+ body: Object.keys(body).length > 0 ? body : undefined,
46
+ });
47
+ }
48
+ }
@@ -1,9 +1,9 @@
1
- import { RuntimeContext } from '@mastra/core/runtime-context';
1
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
2
2
  import type {
3
3
  ClientOptions,
4
4
  GetVNextWorkflowResponse,
5
+ GetVNextWorkflowRunsResponse,
5
6
  GetWorkflowRunsParams,
6
- GetWorkflowRunsResponse,
7
7
  VNextWorkflowRunResult,
8
8
  VNextWorkflowWatchResult,
9
9
  } from '../types';
@@ -104,7 +104,7 @@ export class VNextWorkflow extends BaseResource {
104
104
  * @param params - Parameters for filtering runs
105
105
  * @returns Promise containing vNext workflow runs array
106
106
  */
107
- runs(params?: GetWorkflowRunsParams): Promise<GetWorkflowRunsResponse> {
107
+ runs(params?: GetWorkflowRunsParams): Promise<GetVNextWorkflowRunsResponse> {
108
108
  const searchParams = new URLSearchParams();
109
109
  if (params?.fromDate) {
110
110
  searchParams.set('fromDate', params.fromDate.toISOString());
package/src/types.ts CHANGED
@@ -8,10 +8,13 @@ import type {
8
8
  StorageThreadType,
9
9
  BaseLogMessage,
10
10
  WorkflowRunResult as CoreWorkflowRunResult,
11
+ VNextWorkflowRuns,
11
12
  WorkflowRuns,
12
13
  } from '@mastra/core';
13
14
 
14
15
  import type { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
16
+ import type { RuntimeContext } from '@mastra/core/runtime-context';
17
+ import type { ServerInfo } from '@mastra/core/mcp';
15
18
  import type { NewWorkflow, WatchEvent, WorkflowResult as VNextWorkflowResult } from '@mastra/core/workflows/vNext';
16
19
  import type { JSONSchema7 } from 'json-schema';
17
20
  import type { ZodSchema } from 'zod';
@@ -38,6 +41,16 @@ export interface RequestOptions {
38
41
  signal?: AbortSignal;
39
42
  }
40
43
 
44
+ type WithoutMethods<T> = {
45
+ [K in keyof T as T[K] extends (...args: any[]) => any
46
+ ? never
47
+ : T[K] extends { (): any }
48
+ ? never
49
+ : T[K] extends undefined | ((...args: any[]) => any)
50
+ ? never
51
+ : K]: T[K];
52
+ };
53
+
41
54
  export interface GetAgentResponse {
42
55
  name: string;
43
56
  instructions: string;
@@ -49,11 +62,17 @@ export interface GetAgentResponse {
49
62
 
50
63
  export type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
51
64
  messages: string | string[] | CoreMessage[] | AiMessageType[];
52
- } & Partial<Omit<AgentGenerateOptions<T>, 'experimental_generateMessageId'>>;
65
+ output?: T;
66
+ experimental_output?: T;
67
+ runtimeContext?: RuntimeContext;
68
+ } & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext'>>;
53
69
 
54
70
  export type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
55
71
  messages: string | string[] | CoreMessage[] | AiMessageType[];
56
- } & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry' | 'experimental_generateMessageId'>;
72
+ output?: T;
73
+ experimental_output?: T;
74
+ runtimeContext?: RuntimeContext;
75
+ } & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext'>>;
57
76
 
58
77
  export interface GetEvalsByAgentIdResponse extends GetAgentResponse {
59
78
  evals: any[];
@@ -88,6 +107,8 @@ export interface GetWorkflowRunsParams {
88
107
 
89
108
  export type GetWorkflowRunsResponse = WorkflowRuns;
90
109
 
110
+ export type GetVNextWorkflowRunsResponse = VNextWorkflowRuns;
111
+
91
112
  export type WorkflowRunResult = {
92
113
  activePaths: Record<string, { status: string; suspendPayload?: any; stepPath: string[] }>;
93
114
  results: CoreWorkflowRunResult<any, any, any>['results'];
@@ -268,3 +289,20 @@ export interface GetNetworkResponse {
268
289
  };
269
290
  state?: Record<string, any>;
270
291
  }
292
+
293
+ export interface McpServerListResponse {
294
+ servers: ServerInfo[];
295
+ next: string | null;
296
+ total_count: number;
297
+ }
298
+
299
+ export interface McpToolInfo {
300
+ id: string;
301
+ name: string;
302
+ description?: string;
303
+ inputSchema: string;
304
+ }
305
+
306
+ export interface McpServerToolListResponse {
307
+ tools: McpToolInfo[];
308
+ }