@mastra/client-js 0.1.22 → 0.2.0-alpha.1

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.d.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  import { AbstractAgent } from '@ag-ui/client';
2
+ import { ServerInfo, ServerDetailInfo } from '@mastra/core/mcp';
2
3
  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';
4
+ import { CoreMessage, AiMessageType, StorageThreadType, MessageType, LegacyWorkflowRuns, WorkflowRuns, QueryResult, GenerateReturn } from '@mastra/core';
4
5
  import { JSONSchema7 } from 'json-schema';
5
6
  import { ZodSchema } from 'zod';
7
+ import { BaseLogMessage } from '@mastra/core/logger';
6
8
  import { AgentGenerateOptions, AgentStreamOptions } from '@mastra/core/agent';
7
- 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';
9
+ import { RuntimeContext } from '@mastra/core/runtime-context';
10
+ import { Workflow as Workflow$1, WorkflowResult, WatchEvent } from '@mastra/core/workflows';
11
+ import { StepAction, StepGraph, LegacyWorkflowRunResult as LegacyWorkflowRunResult$1 } from '@mastra/core/workflows/legacy';
10
12
  import { AgentCard, TaskSendParams, Task, TaskQueryParams, TaskIdParams } from '@mastra/core/a2a';
11
13
 
12
14
  interface ClientOptions {
@@ -28,6 +30,11 @@ interface RequestOptions {
28
30
  stream?: boolean;
29
31
  signal?: AbortSignal;
30
32
  }
33
+ type WithoutMethods<T> = {
34
+ [K in keyof T as T[K] extends (...args: any[]) => any ? never : T[K] extends {
35
+ (): any;
36
+ } ? never : T[K] extends undefined | ((...args: any[]) => any) ? never : K]: T[K];
37
+ };
31
38
  interface GetAgentResponse {
32
39
  name: string;
33
40
  instructions: string;
@@ -38,10 +45,16 @@ interface GetAgentResponse {
38
45
  }
39
46
  type GenerateParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
40
47
  messages: string | string[] | CoreMessage[] | AiMessageType[];
41
- } & Partial<Omit<AgentGenerateOptions<T>, 'experimental_generateMessageId'>>;
48
+ output?: T;
49
+ experimental_output?: T;
50
+ runtimeContext?: RuntimeContext | Record<string, any>;
51
+ } & WithoutMethods<Omit<AgentGenerateOptions<T>, 'output' | 'experimental_output' | 'runtimeContext'>>;
42
52
  type StreamParams<T extends JSONSchema7 | ZodSchema | undefined = undefined> = {
43
53
  messages: string | string[] | CoreMessage[] | AiMessageType[];
44
- } & Omit<AgentStreamOptions<T>, 'onFinish' | 'onStepFinish' | 'telemetry' | 'experimental_generateMessageId'>;
54
+ output?: T;
55
+ experimental_output?: T;
56
+ runtimeContext?: RuntimeContext | Record<string, any>;
57
+ } & WithoutMethods<Omit<AgentStreamOptions<T>, 'output' | 'experimental_output' | 'runtimeContext'>>;
45
58
  interface GetEvalsByAgentIdResponse extends GetAgentResponse {
46
59
  evals: any[];
47
60
  instructions: string;
@@ -54,7 +67,7 @@ interface GetToolResponse {
54
67
  inputSchema: string;
55
68
  outputSchema: string;
56
69
  }
57
- interface GetWorkflowResponse {
70
+ interface GetLegacyWorkflowResponse {
58
71
  name: string;
59
72
  triggerSchema: string;
60
73
  steps: Record<string, StepAction<any, any, any, any>>;
@@ -69,19 +82,21 @@ interface GetWorkflowRunsParams {
69
82
  offset?: number;
70
83
  resourceId?: string;
71
84
  }
85
+ type GetLegacyWorkflowRunsResponse = LegacyWorkflowRuns;
72
86
  type GetWorkflowRunsResponse = WorkflowRuns;
73
- type WorkflowRunResult = {
87
+ type LegacyWorkflowRunResult = {
74
88
  activePaths: Record<string, {
75
89
  status: string;
76
90
  suspendPayload?: any;
77
91
  stepPath: string[];
78
92
  }>;
79
- results: WorkflowRunResult$1<any, any, any>['results'];
93
+ results: LegacyWorkflowRunResult$1<any, any, any>['results'];
80
94
  timestamp: number;
81
95
  runId: string;
82
96
  };
83
- interface GetVNextWorkflowResponse {
97
+ interface GetWorkflowResponse {
84
98
  name: string;
99
+ description?: string;
85
100
  steps: {
86
101
  [key: string]: {
87
102
  id: string;
@@ -92,14 +107,14 @@ interface GetVNextWorkflowResponse {
92
107
  suspendSchema: string;
93
108
  };
94
109
  };
95
- stepGraph: NewWorkflow['serializedStepGraph'];
110
+ stepGraph: Workflow$1['serializedStepGraph'];
96
111
  inputSchema: string;
97
112
  outputSchema: string;
98
113
  }
99
- type VNextWorkflowWatchResult = WatchEvent & {
114
+ type WorkflowWatchResult = WatchEvent & {
100
115
  runId: string;
101
116
  };
102
- type VNextWorkflowRunResult = WorkflowResult<any, any>;
117
+ type WorkflowRunResult = WorkflowResult<any, any>;
103
118
  interface UpsertVectorParams {
104
119
  indexName: string;
105
120
  vectors: number[][];
@@ -231,6 +246,20 @@ interface GetNetworkResponse {
231
246
  };
232
247
  state?: Record<string, any>;
233
248
  }
249
+ interface McpServerListResponse {
250
+ servers: ServerInfo[];
251
+ next: string | null;
252
+ total_count: number;
253
+ }
254
+ interface McpToolInfo {
255
+ id: string;
256
+ name: string;
257
+ description?: string;
258
+ inputSchema: string;
259
+ }
260
+ interface McpServerToolListResponse {
261
+ tools: McpToolInfo[];
262
+ }
234
263
 
235
264
  declare class BaseResource {
236
265
  readonly options: ClientOptions;
@@ -426,29 +455,22 @@ declare class Vector extends BaseResource {
426
455
  query(params: QueryVectorParams): Promise<QueryVectorResponse>;
427
456
  }
428
457
 
429
- declare class Workflow extends BaseResource {
458
+ declare class LegacyWorkflow extends BaseResource {
430
459
  private workflowId;
431
460
  constructor(options: ClientOptions, workflowId: string);
432
461
  /**
433
- * Retrieves details about the workflow
434
- * @returns Promise containing workflow details including steps and graphs
462
+ * Retrieves details about the legacy workflow
463
+ * @returns Promise containing legacy workflow details including steps and graphs
435
464
  */
436
- details(): Promise<GetWorkflowResponse>;
465
+ details(): Promise<GetLegacyWorkflowResponse>;
437
466
  /**
438
- * Retrieves all runs for a workflow
467
+ * Retrieves all runs for a legacy workflow
439
468
  * @param params - Parameters for filtering runs
440
- * @returns Promise containing workflow runs array
441
- */
442
- runs(params?: GetWorkflowRunsParams): Promise<GetWorkflowRunsResponse>;
443
- /**
444
- * @deprecated Use `startAsync` instead
445
- * Executes the workflow with the provided parameters
446
- * @param params - Parameters required for workflow execution
447
- * @returns Promise containing the workflow execution results
469
+ * @returns Promise containing legacy workflow runs array
448
470
  */
449
- execute(params: Record<string, any>): Promise<WorkflowRunResult>;
471
+ runs(params?: GetWorkflowRunsParams): Promise<GetLegacyWorkflowRunsResponse>;
450
472
  /**
451
- * Creates a new workflow run
473
+ * Creates a new legacy workflow run
452
474
  * @returns Promise containing the generated run ID
453
475
  */
454
476
  createRun(params?: {
@@ -457,7 +479,7 @@ declare class Workflow extends BaseResource {
457
479
  runId: string;
458
480
  }>;
459
481
  /**
460
- * Starts a workflow run synchronously without waiting for the workflow to complete
482
+ * Starts a legacy workflow run synchronously without waiting for the workflow to complete
461
483
  * @param params - Object containing the runId and triggerData
462
484
  * @returns Promise containing success message
463
485
  */
@@ -468,11 +490,11 @@ declare class Workflow extends BaseResource {
468
490
  message: string;
469
491
  }>;
470
492
  /**
471
- * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
493
+ * Resumes a suspended legacy workflow step synchronously without waiting for the workflow to complete
472
494
  * @param stepId - ID of the step to resume
473
- * @param runId - ID of the workflow run
474
- * @param context - Context to resume the workflow with
475
- * @returns Promise containing the workflow resume results
495
+ * @param runId - ID of the legacy workflow run
496
+ * @param context - Context to resume the legacy workflow with
497
+ * @returns Promise containing the legacy workflow resume results
476
498
  */
477
499
  resume({ stepId, runId, context, }: {
478
500
  stepId: string;
@@ -489,9 +511,9 @@ declare class Workflow extends BaseResource {
489
511
  startAsync(params: {
490
512
  runId?: string;
491
513
  triggerData: Record<string, any>;
492
- }): Promise<WorkflowRunResult>;
514
+ }): Promise<LegacyWorkflowRunResult>;
493
515
  /**
494
- * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
516
+ * Resumes a suspended legacy workflow step asynchronously and returns a promise that resolves when the workflow is complete
495
517
  * @param params - Object containing the runId, stepId, and context
496
518
  * @returns Promise containing the workflow resume results
497
519
  */
@@ -499,7 +521,7 @@ declare class Workflow extends BaseResource {
499
521
  runId: string;
500
522
  stepId: string;
501
523
  context: Record<string, any>;
502
- }): Promise<WorkflowRunResult>;
524
+ }): Promise<LegacyWorkflowRunResult>;
503
525
  /**
504
526
  * Creates an async generator that processes a readable stream and yields records
505
527
  * separated by the Record Separator character (\x1E)
@@ -509,13 +531,13 @@ declare class Workflow extends BaseResource {
509
531
  */
510
532
  private streamProcessor;
511
533
  /**
512
- * Watches workflow transitions in real-time
534
+ * Watches legacy workflow transitions in real-time
513
535
  * @param runId - Optional run ID to filter the watch stream
514
- * @returns AsyncGenerator that yields parsed records from the workflow watch stream
536
+ * @returns AsyncGenerator that yields parsed records from the legacy workflow watch stream
515
537
  */
516
538
  watch({ runId }: {
517
539
  runId?: string;
518
- }, onRecord: (record: WorkflowRunResult) => void): Promise<void>;
540
+ }, onRecord: (record: LegacyWorkflowRunResult) => void): Promise<void>;
519
541
  }
520
542
 
521
543
  declare class Tool extends BaseResource {
@@ -534,15 +556,15 @@ declare class Tool extends BaseResource {
534
556
  execute(params: {
535
557
  data: any;
536
558
  runId?: string;
537
- runtimeContext?: RuntimeContext;
559
+ runtimeContext?: RuntimeContext | Record<string, any>;
538
560
  }): Promise<any>;
539
561
  }
540
562
 
541
- declare class VNextWorkflow extends BaseResource {
563
+ declare class Workflow extends BaseResource {
542
564
  private workflowId;
543
565
  constructor(options: ClientOptions, workflowId: string);
544
566
  /**
545
- * Creates an async generator that processes a readable stream and yields vNext workflow records
567
+ * Creates an async generator that processes a readable stream and yields workflow records
546
568
  * separated by the Record Separator character (\x1E)
547
569
  *
548
570
  * @param stream - The readable stream to process
@@ -550,18 +572,18 @@ declare class VNextWorkflow extends BaseResource {
550
572
  */
551
573
  private streamProcessor;
552
574
  /**
553
- * Retrieves details about the vNext workflow
554
- * @returns Promise containing vNext workflow details including steps and graphs
575
+ * Retrieves details about the workflow
576
+ * @returns Promise containing workflow details including steps and graphs
555
577
  */
556
- details(): Promise<GetVNextWorkflowResponse>;
578
+ details(): Promise<GetWorkflowResponse>;
557
579
  /**
558
- * Retrieves all runs for a vNext workflow
580
+ * Retrieves all runs for a workflow
559
581
  * @param params - Parameters for filtering runs
560
- * @returns Promise containing vNext workflow runs array
582
+ * @returns Promise containing workflow runs array
561
583
  */
562
584
  runs(params?: GetWorkflowRunsParams): Promise<GetWorkflowRunsResponse>;
563
585
  /**
564
- * Creates a new vNext workflow run
586
+ * Creates a new workflow run
565
587
  * @param params - Optional object containing the optional runId
566
588
  * @returns Promise containing the runId of the created run
567
589
  */
@@ -571,19 +593,19 @@ declare class VNextWorkflow extends BaseResource {
571
593
  runId: string;
572
594
  }>;
573
595
  /**
574
- * Starts a vNext workflow run synchronously without waiting for the workflow to complete
596
+ * Starts a workflow run synchronously without waiting for the workflow to complete
575
597
  * @param params - Object containing the runId, inputData and runtimeContext
576
598
  * @returns Promise containing success message
577
599
  */
578
600
  start(params: {
579
601
  runId: string;
580
602
  inputData: Record<string, any>;
581
- runtimeContext?: RuntimeContext$1;
603
+ runtimeContext?: RuntimeContext | Record<string, any>;
582
604
  }): Promise<{
583
605
  message: string;
584
606
  }>;
585
607
  /**
586
- * Resumes a suspended vNext workflow step synchronously without waiting for the vNext workflow to complete
608
+ * Resumes a suspended workflow step synchronously without waiting for the workflow to complete
587
609
  * @param params - Object containing the runId, step, resumeData and runtimeContext
588
610
  * @returns Promise containing success message
589
611
  */
@@ -591,39 +613,39 @@ declare class VNextWorkflow extends BaseResource {
591
613
  step: string | string[];
592
614
  runId: string;
593
615
  resumeData?: Record<string, any>;
594
- runtimeContext?: RuntimeContext$1;
616
+ runtimeContext?: RuntimeContext | Record<string, any>;
595
617
  }): Promise<{
596
618
  message: string;
597
619
  }>;
598
620
  /**
599
- * Starts a vNext workflow run asynchronously and returns a promise that resolves when the vNext workflow is complete
621
+ * Starts a workflow run asynchronously and returns a promise that resolves when the workflow is complete
600
622
  * @param params - Object containing the optional runId, inputData and runtimeContext
601
- * @returns Promise containing the vNext workflow execution results
623
+ * @returns Promise containing the workflow execution results
602
624
  */
603
625
  startAsync(params: {
604
626
  runId?: string;
605
627
  inputData: Record<string, any>;
606
- runtimeContext?: RuntimeContext$1;
607
- }): Promise<VNextWorkflowRunResult>;
628
+ runtimeContext?: RuntimeContext | Record<string, any>;
629
+ }): Promise<WorkflowRunResult>;
608
630
  /**
609
- * Resumes a suspended vNext workflow step asynchronously and returns a promise that resolves when the vNext workflow is complete
631
+ * Resumes a suspended workflow step asynchronously and returns a promise that resolves when the workflow is complete
610
632
  * @param params - Object containing the runId, step, resumeData and runtimeContext
611
- * @returns Promise containing the vNext workflow resume results
633
+ * @returns Promise containing the workflow resume results
612
634
  */
613
635
  resumeAsync(params: {
614
636
  runId: string;
615
637
  step: string | string[];
616
638
  resumeData?: Record<string, any>;
617
- runtimeContext?: RuntimeContext$1;
618
- }): Promise<VNextWorkflowRunResult>;
639
+ runtimeContext?: RuntimeContext | Record<string, any>;
640
+ }): Promise<WorkflowRunResult>;
619
641
  /**
620
- * Watches vNext workflow transitions in real-time
642
+ * Watches workflow transitions in real-time
621
643
  * @param runId - Optional run ID to filter the watch stream
622
- * @returns AsyncGenerator that yields parsed records from the vNext workflow watch stream
644
+ * @returns AsyncGenerator that yields parsed records from the workflow watch stream
623
645
  */
624
646
  watch({ runId }: {
625
647
  runId?: string;
626
- }, onRecord: (record: VNextWorkflowWatchResult) => void): Promise<void>;
648
+ }, onRecord: (record: WorkflowWatchResult) => void): Promise<void>;
627
649
  }
628
650
 
629
651
  /**
@@ -667,6 +689,30 @@ declare class A2A extends BaseResource {
667
689
  sendAndSubscribe(params: TaskSendParams): Promise<Response>;
668
690
  }
669
691
 
692
+ /**
693
+ * Represents a specific tool available on a specific MCP server.
694
+ * Provides methods to get details and execute the tool.
695
+ */
696
+ declare class MCPTool extends BaseResource {
697
+ private serverId;
698
+ private toolId;
699
+ constructor(options: ClientOptions, serverId: string, toolId: string);
700
+ /**
701
+ * Retrieves details about this specific tool from the MCP server.
702
+ * @returns Promise containing the tool's information (name, description, schema).
703
+ */
704
+ details(): Promise<McpToolInfo>;
705
+ /**
706
+ * Executes this specific tool on the MCP server.
707
+ * @param params - Parameters for tool execution, including data/args and optional runtimeContext.
708
+ * @returns Promise containing the result of the tool execution.
709
+ */
710
+ execute(params: {
711
+ data?: any;
712
+ runtimeContext?: RuntimeContext;
713
+ }): Promise<any>;
714
+ }
715
+
670
716
  declare class MastraClient extends BaseResource {
671
717
  constructor(options: ClientOptions);
672
718
  /**
@@ -725,6 +771,17 @@ declare class MastraClient extends BaseResource {
725
771
  * @returns Tool instance
726
772
  */
727
773
  getTool(toolId: string): Tool;
774
+ /**
775
+ * Retrieves all available legacy workflows
776
+ * @returns Promise containing map of legacy workflow IDs to legacy workflow details
777
+ */
778
+ getLegacyWorkflows(): Promise<Record<string, GetLegacyWorkflowResponse>>;
779
+ /**
780
+ * Gets a legacy workflow instance by ID
781
+ * @param workflowId - ID of the legacy workflow to retrieve
782
+ * @returns Legacy Workflow instance
783
+ */
784
+ getLegacyWorkflow(workflowId: string): LegacyWorkflow;
728
785
  /**
729
786
  * Retrieves all available workflows
730
787
  * @returns Promise containing map of workflow IDs to workflow details
@@ -736,17 +793,6 @@ declare class MastraClient extends BaseResource {
736
793
  * @returns Workflow instance
737
794
  */
738
795
  getWorkflow(workflowId: string): Workflow;
739
- /**
740
- * Retrieves all available vNext workflows
741
- * @returns Promise containing map of vNext workflow IDs to vNext workflow details
742
- */
743
- getVNextWorkflows(): Promise<Record<string, GetVNextWorkflowResponse>>;
744
- /**
745
- * Gets a vNext workflow instance by ID
746
- * @param workflowId - ID of the vNext workflow to retrieve
747
- * @returns vNext Workflow instance
748
- */
749
- getVNextWorkflow(workflowId: string): VNextWorkflow;
750
796
  /**
751
797
  * Gets a vector instance by name
752
798
  * @param vectorName - Name of the vector to retrieve
@@ -789,6 +835,38 @@ declare class MastraClient extends BaseResource {
789
835
  * @returns Network instance
790
836
  */
791
837
  getNetwork(networkId: string): Network;
838
+ /**
839
+ * Retrieves a list of available MCP servers.
840
+ * @param params - Optional parameters for pagination (limit, offset).
841
+ * @returns Promise containing the list of MCP servers and pagination info.
842
+ */
843
+ getMcpServers(params?: {
844
+ limit?: number;
845
+ offset?: number;
846
+ }): Promise<McpServerListResponse>;
847
+ /**
848
+ * Retrieves detailed information for a specific MCP server.
849
+ * @param serverId - The ID of the MCP server to retrieve.
850
+ * @param params - Optional parameters, e.g., specific version.
851
+ * @returns Promise containing the detailed MCP server information.
852
+ */
853
+ getMcpServerDetails(serverId: string, params?: {
854
+ version?: string;
855
+ }): Promise<ServerDetailInfo>;
856
+ /**
857
+ * Retrieves a list of tools for a specific MCP server.
858
+ * @param serverId - The ID of the MCP server.
859
+ * @returns Promise containing the list of tools.
860
+ */
861
+ getMcpServerTools(serverId: string): Promise<McpServerToolListResponse>;
862
+ /**
863
+ * Gets an MCPTool resource instance for a specific tool on an MCP server.
864
+ * This instance can then be used to fetch details or execute the tool.
865
+ * @param serverId - The ID of the MCP server.
866
+ * @param toolId - The ID of the tool.
867
+ * @returns MCPTool instance.
868
+ */
869
+ getMcpServerTool(serverId: string, toolId: string): MCPTool;
792
870
  /**
793
871
  * Gets an A2A client for interacting with an agent via the A2A protocol
794
872
  * @param agentId - ID of the agent to interact with
@@ -797,4 +875,4 @@ declare class MastraClient extends BaseResource {
797
875
  getA2A(agentId: string): A2A;
798
876
  }
799
877
 
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 };
878
+ export { type ClientOptions, type CreateIndexParams, type CreateMemoryThreadParams, type CreateMemoryThreadResponse, type GenerateParams, type GetAgentResponse, type GetEvalsByAgentIdResponse, type GetLegacyWorkflowResponse, type GetLegacyWorkflowRunsResponse, type GetLogParams, type GetLogsParams, type GetLogsResponse, type GetMemoryThreadMessagesParams, type GetMemoryThreadMessagesResponse, type GetMemoryThreadParams, type GetMemoryThreadResponse, type GetNetworkResponse, type GetTelemetryParams, type GetTelemetryResponse, type GetToolResponse, type GetVectorIndexResponse, type GetWorkflowResponse, type GetWorkflowRunsParams, type GetWorkflowRunsResponse, type LegacyWorkflowRunResult, 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 WorkflowRunResult, type WorkflowWatchResult };