@mastra/client-js 0.0.0-trigger-playground-ui-package-20250506151043 → 0.0.0-vector-query-sources-20250516172905

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/client.ts CHANGED
@@ -1,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 } 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) {
@@ -256,4 +271,65 @@ export class MastraClient extends BaseResource {
256
271
  public getNetwork(networkId: string) {
257
272
  return new Network(this.options, networkId);
258
273
  }
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
+
327
+ /**
328
+ * Gets an A2A client for interacting with an agent via the A2A protocol
329
+ * @param agentId - ID of the agent to interact with
330
+ * @returns A2A client instance
331
+ */
332
+ public getA2A(agentId: string) {
333
+ return new A2A(this.options, agentId);
334
+ }
259
335
  }
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();
@@ -236,6 +236,7 @@ describe('MastraClient Resources', () => {
236
236
  model: 'gpt-4',
237
237
  instructions: 'Test instructions',
238
238
  tools: {},
239
+ workflows: {},
239
240
  };
240
241
  mockFetchResponse(mockResponse);
241
242
 
@@ -552,6 +553,35 @@ describe('MastraClient Resources', () => {
552
553
  }),
553
554
  );
554
555
  });
556
+
557
+ it('should get thread messages with limit', async () => {
558
+ const mockResponse = {
559
+ messages: [
560
+ {
561
+ id: '1',
562
+ content: 'test',
563
+ threadId,
564
+ role: 'user',
565
+ type: 'text',
566
+ resourceId: 'test-resource',
567
+ createdAt: new Date(),
568
+ },
569
+ ],
570
+ uiMessages: [],
571
+ };
572
+ mockFetchResponse(mockResponse);
573
+
574
+ const limit = 5;
575
+ const result = await memoryThread.getMessages({ limit });
576
+
577
+ expect(result).toEqual(mockResponse);
578
+ expect(global.fetch).toHaveBeenCalledWith(
579
+ `${clientOptions.baseUrl}/api/memory/threads/${threadId}/messages?agentId=${agentId}&limit=${limit}`,
580
+ expect.objectContaining({
581
+ headers: expect.objectContaining(clientOptions.headers),
582
+ }),
583
+ );
584
+ });
555
585
  });
556
586
 
557
587
  describe('Tool Resource', () => {
@@ -707,4 +737,94 @@ describe('MastraClient Resources', () => {
707
737
  );
708
738
  });
709
739
  });
740
+
741
+ describe('MCP Server Registry Client Methods', () => {
742
+ const mockServerInfo1 = {
743
+ id: 'mcp-server-1',
744
+ name: 'Test MCP Server 1',
745
+ version_detail: { version: '1.0.0', release_date: '2023-01-01T00:00:00Z', is_latest: true },
746
+ };
747
+ const mockServerInfo2 = {
748
+ id: 'mcp-server-2',
749
+ name: 'Test MCP Server 2',
750
+ version_detail: { version: '1.1.0', release_date: '2023-02-01T00:00:00Z', is_latest: true },
751
+ };
752
+
753
+ const mockServerDetail1: ServerDetailInfo = {
754
+ ...mockServerInfo1,
755
+ description: 'Detailed description for server 1',
756
+ package_canonical: 'npm',
757
+ packages: [{ registry_name: 'npm', name: '@example/server1', version: '1.0.0' }],
758
+ remotes: [{ transport_type: 'sse', url: 'http://localhost/sse1' }],
759
+ };
760
+
761
+ describe('getMcpServers()', () => {
762
+ it('should fetch a list of MCP servers', async () => {
763
+ const mockResponse: McpServerListResponse = {
764
+ servers: [mockServerInfo1, mockServerInfo2],
765
+ total_count: 2,
766
+ next: null,
767
+ };
768
+ mockFetchResponse(mockResponse);
769
+
770
+ const result = await client.getMcpServers();
771
+ expect(result).toEqual(mockResponse);
772
+ expect(global.fetch).toHaveBeenCalledWith(
773
+ `${clientOptions.baseUrl}/api/mcp/v0/servers`,
774
+ expect.objectContaining({
775
+ headers: expect.objectContaining(clientOptions.headers),
776
+ }),
777
+ );
778
+ });
779
+
780
+ it('should fetch MCP servers with limit and offset parameters', async () => {
781
+ const mockResponse: McpServerListResponse = {
782
+ servers: [mockServerInfo1],
783
+ total_count: 2,
784
+ next: '/api/mcp/v0/servers?limit=1&offset=1',
785
+ };
786
+ mockFetchResponse(mockResponse);
787
+
788
+ const result = await client.getMcpServers({ limit: 1, offset: 0 });
789
+ expect(result).toEqual(mockResponse);
790
+ expect(global.fetch).toHaveBeenCalledWith(
791
+ `${clientOptions.baseUrl}/api/mcp/v0/servers?limit=1&offset=0`,
792
+ expect.objectContaining({
793
+ headers: expect.objectContaining(clientOptions.headers),
794
+ }),
795
+ );
796
+ });
797
+ });
798
+
799
+ describe('getMcpServerDetails()', () => {
800
+ const serverId = 'mcp-server-1';
801
+
802
+ it('should fetch details for a specific MCP server', async () => {
803
+ mockFetchResponse(mockServerDetail1);
804
+
805
+ const result = await client.getMcpServerDetails(serverId);
806
+ expect(result).toEqual(mockServerDetail1);
807
+ expect(global.fetch).toHaveBeenCalledWith(
808
+ `${clientOptions.baseUrl}/api/mcp/v0/servers/${serverId}`,
809
+ expect.objectContaining({
810
+ headers: expect.objectContaining(clientOptions.headers),
811
+ }),
812
+ );
813
+ });
814
+
815
+ it('should fetch MCP server details with a version parameter', async () => {
816
+ mockFetchResponse(mockServerDetail1);
817
+ const version = '1.0.0';
818
+
819
+ const result = await client.getMcpServerDetails(serverId, { version });
820
+ expect(result).toEqual(mockServerDetail1);
821
+ expect(global.fetch).toHaveBeenCalledWith(
822
+ `${clientOptions.baseUrl}/api/mcp/v0/servers/${serverId}?version=${version}`,
823
+ expect.objectContaining({
824
+ headers: expect.objectContaining(clientOptions.headers),
825
+ }),
826
+ );
827
+ });
828
+ });
829
+ });
710
830
  });
@@ -0,0 +1,88 @@
1
+ import type { TaskSendParams, TaskQueryParams, TaskIdParams, Task, AgentCard, JSONRPCResponse } from '@mastra/core/a2a';
2
+ import type { ClientOptions } from '../types';
3
+ import { BaseResource } from './base';
4
+
5
+ /**
6
+ * Class for interacting with an agent via the A2A protocol
7
+ */
8
+ export class A2A extends BaseResource {
9
+ constructor(
10
+ options: ClientOptions,
11
+ private agentId: string,
12
+ ) {
13
+ super(options);
14
+ }
15
+
16
+ /**
17
+ * Get the agent card with metadata about the agent
18
+ * @returns Promise containing the agent card information
19
+ */
20
+ async getCard(): Promise<AgentCard> {
21
+ return this.request(`/.well-known/${this.agentId}/agent.json`);
22
+ }
23
+
24
+ /**
25
+ * Send a message to the agent and get a response
26
+ * @param params - Parameters for the task
27
+ * @returns Promise containing the task response
28
+ */
29
+ async sendMessage(params: TaskSendParams): Promise<{ task: Task }> {
30
+ const response = await this.request<JSONRPCResponse<Task>>(`/a2a/${this.agentId}`, {
31
+ method: 'POST',
32
+ body: {
33
+ method: 'tasks/send',
34
+ params,
35
+ },
36
+ });
37
+
38
+ return { task: response.result! };
39
+ }
40
+
41
+ /**
42
+ * Get the status and result of a task
43
+ * @param params - Parameters for querying the task
44
+ * @returns Promise containing the task response
45
+ */
46
+ async getTask(params: TaskQueryParams): Promise<Task> {
47
+ const response = await this.request<JSONRPCResponse<Task>>(`/a2a/${this.agentId}`, {
48
+ method: 'POST',
49
+ body: {
50
+ method: 'tasks/get',
51
+ params,
52
+ },
53
+ });
54
+
55
+ return response.result!;
56
+ }
57
+
58
+ /**
59
+ * Cancel a running task
60
+ * @param params - Parameters identifying the task to cancel
61
+ * @returns Promise containing the task response
62
+ */
63
+ async cancelTask(params: TaskIdParams): Promise<{ task: Task }> {
64
+ return this.request(`/a2a/${this.agentId}`, {
65
+ method: 'POST',
66
+ body: {
67
+ method: 'tasks/cancel',
68
+ params,
69
+ },
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Send a message and subscribe to streaming updates (not fully implemented)
75
+ * @param params - Parameters for the task
76
+ * @returns Promise containing the task response
77
+ */
78
+ async sendAndSubscribe(params: TaskSendParams): Promise<Response> {
79
+ return this.request(`/a2a/${this.agentId}`, {
80
+ method: 'POST',
81
+ body: {
82
+ method: 'tasks/sendSubscribe',
83
+ params,
84
+ },
85
+ stream: true,
86
+ });
87
+ }
88
+ }
@@ -2,7 +2,7 @@ import { processDataStream } from '@ai-sdk/ui-utils';
2
2
  import type { GenerateReturn } from '@mastra/core';
3
3
  import type { JSONSchema7 } from 'json-schema';
4
4
  import { ZodSchema } from 'zod';
5
- import { zodToJsonSchema } from 'zod-to-json-schema';
5
+ import { zodToJsonSchema } from '../utils/zod-to-json-schema';
6
6
 
7
7
  import type {
8
8
  GenerateParams,
@@ -14,28 +14,7 @@ import type {
14
14
  } from '../types';
15
15
 
16
16
  import { BaseResource } from './base';
17
-
18
- export class AgentTool extends BaseResource {
19
- constructor(
20
- options: ClientOptions,
21
- private agentId: string,
22
- private toolId: string,
23
- ) {
24
- super(options);
25
- }
26
-
27
- /**
28
- * Executes a specific tool for an agent
29
- * @param params - Parameters required for tool execution
30
- * @returns Promise containing tool execution results
31
- */
32
- execute(params: { data: any }): Promise<any> {
33
- return this.request(`/api/agents/${this.agentId}/tools/${this.toolId}/execute`, {
34
- method: 'POST',
35
- body: params,
36
- });
37
- }
38
- }
17
+ import type { RuntimeContext } from '@mastra/core/di';
39
18
 
40
19
  export class AgentVoice extends BaseResource {
41
20
  constructor(
@@ -69,7 +48,7 @@ export class AgentVoice extends BaseResource {
69
48
  * @param options - Optional provider-specific options
70
49
  * @returns Promise containing the transcribed text
71
50
  */
72
- listen(audio: Blob, options?: Record<string, any>): Promise<Response> {
51
+ listen(audio: Blob, options?: Record<string, any>): Promise<{ text: string }> {
73
52
  const formData = new FormData();
74
53
  formData.append('audio', audio);
75
54
 
@@ -121,11 +100,9 @@ export class Agent extends BaseResource {
121
100
  ): Promise<GenerateReturn<T>> {
122
101
  const processedParams = {
123
102
  ...params,
124
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
125
- experimental_output:
126
- params.experimental_output instanceof ZodSchema
127
- ? zodToJsonSchema(params.experimental_output)
128
- : params.experimental_output,
103
+ output: params.output ? zodToJsonSchema(params.output) : undefined,
104
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : undefined,
105
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
129
106
  };
130
107
 
131
108
  return this.request(`/api/agents/${this.agentId}/generate`, {
@@ -148,11 +125,9 @@ export class Agent extends BaseResource {
148
125
  > {
149
126
  const processedParams = {
150
127
  ...params,
151
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
152
- experimental_output:
153
- params.experimental_output instanceof ZodSchema
154
- ? zodToJsonSchema(params.experimental_output)
155
- : params.experimental_output,
128
+ output: params.output ? zodToJsonSchema(params.output) : undefined,
129
+ experimental_output: params.experimental_output ? zodToJsonSchema(params.experimental_output) : undefined,
130
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
156
131
  };
157
132
 
158
133
  const response: Response & {
@@ -186,6 +161,23 @@ export class Agent extends BaseResource {
186
161
  return this.request(`/api/agents/${this.agentId}/tools/${toolId}`);
187
162
  }
188
163
 
164
+ /**
165
+ * Executes a tool for the agent
166
+ * @param toolId - ID of the tool to execute
167
+ * @param params - Parameters required for tool execution
168
+ * @returns Promise containing the tool execution results
169
+ */
170
+ executeTool(toolId: string, params: { data: any; runtimeContext?: RuntimeContext }): Promise<any> {
171
+ const body = {
172
+ data: params.data,
173
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
174
+ };
175
+ return this.request(`/api/agents/${this.agentId}/tools/${toolId}/execute`, {
176
+ method: 'POST',
177
+ body,
178
+ });
179
+ }
180
+
189
181
  /**
190
182
  * Retrieves evaluation results for the agent
191
183
  * @returns Promise containing agent evaluations
@@ -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,
@@ -6,3 +6,5 @@ export * from './workflow';
6
6
  export * from './tool';
7
7
  export * from './base';
8
8
  export * from './vnext-workflow';
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,6 +1,11 @@
1
1
  import type { StorageThreadType } from '@mastra/core';
2
2
 
3
- import type { GetMemoryThreadMessagesResponse, ClientOptions, UpdateMemoryThreadParams } from '../types';
3
+ import type {
4
+ GetMemoryThreadMessagesResponse,
5
+ ClientOptions,
6
+ UpdateMemoryThreadParams,
7
+ GetMemoryThreadMessagesParams,
8
+ } from '../types';
4
9
 
5
10
  import { BaseResource } from './base';
6
11
 
@@ -45,9 +50,14 @@ export class MemoryThread extends BaseResource {
45
50
 
46
51
  /**
47
52
  * Retrieves messages associated with the thread
53
+ * @param params - Optional parameters including limit for number of messages to retrieve
48
54
  * @returns Promise containing thread messages and UI messages
49
55
  */
50
- getMessages(): Promise<GetMemoryThreadMessagesResponse> {
51
- return this.request(`/api/memory/threads/${this.threadId}/messages?agentId=${this.agentId}`);
56
+ getMessages(params?: GetMemoryThreadMessagesParams): Promise<GetMemoryThreadMessagesResponse> {
57
+ const query = new URLSearchParams({
58
+ agentId: this.agentId,
59
+ ...(params?.limit ? { limit: params.limit.toString() } : {}),
60
+ });
61
+ return this.request(`/api/memory/threads/${this.threadId}/messages?${query.toString()}`);
52
62
  }
53
63
  }
@@ -2,7 +2,7 @@ import { processDataStream } from '@ai-sdk/ui-utils';
2
2
  import type { GenerateReturn } from '@mastra/core';
3
3
  import type { JSONSchema7 } from 'json-schema';
4
4
  import { ZodSchema } from 'zod';
5
- import { zodToJsonSchema } from 'zod-to-json-schema';
5
+ import { zodToJsonSchema } from '../utils/zod-to-json-schema';
6
6
 
7
7
  import type { GenerateParams, ClientOptions, StreamParams, GetNetworkResponse } from '../types';
8
8
 
@@ -34,11 +34,8 @@ export class Network extends BaseResource {
34
34
  ): Promise<GenerateReturn<T>> {
35
35
  const processedParams = {
36
36
  ...params,
37
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
38
- experimental_output:
39
- params.experimental_output instanceof ZodSchema
40
- ? zodToJsonSchema(params.experimental_output)
41
- : params.experimental_output,
37
+ output: zodToJsonSchema(params.output),
38
+ experimental_output: zodToJsonSchema(params.experimental_output),
42
39
  };
43
40
 
44
41
  return this.request(`/api/networks/${this.networkId}/generate`, {
@@ -61,11 +58,8 @@ export class Network extends BaseResource {
61
58
  > {
62
59
  const processedParams = {
63
60
  ...params,
64
- output: params.output instanceof ZodSchema ? zodToJsonSchema(params.output) : params.output,
65
- experimental_output:
66
- params.experimental_output instanceof ZodSchema
67
- ? zodToJsonSchema(params.experimental_output)
68
- : params.experimental_output,
61
+ output: zodToJsonSchema(params.output),
62
+ experimental_output: zodToJsonSchema(params.experimental_output),
69
63
  };
70
64
 
71
65
  const response: Response & {
@@ -1,3 +1,4 @@
1
+ import type { RuntimeContext } from '@mastra/core/di';
1
2
  import type { GetToolResponse, ClientOptions } from '../types';
2
3
 
3
4
  import { BaseResource } from './base';
@@ -23,16 +24,21 @@ export class Tool extends BaseResource {
23
24
  * @param params - Parameters required for tool execution
24
25
  * @returns Promise containing the tool execution results
25
26
  */
26
- execute(params: { data: any; runId?: string }): Promise<any> {
27
+ execute(params: { data: any; runId?: string; runtimeContext?: RuntimeContext }): Promise<any> {
27
28
  const url = new URLSearchParams();
28
29
 
29
30
  if (params.runId) {
30
31
  url.set('runId', params.runId);
31
32
  }
32
33
 
34
+ const body = {
35
+ data: params.data,
36
+ runtimeContext: params.runtimeContext ? Object.fromEntries(params.runtimeContext.entries()) : undefined,
37
+ };
38
+
33
39
  return this.request(`/api/tools/${this.toolId}/execute?${url.toString()}`, {
34
40
  method: 'POST',
35
- body: params.data,
41
+ body,
36
42
  });
37
43
  }
38
44
  }