@mastra/mcp 0.13.3 → 0.13.4

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.
@@ -5,24 +5,67 @@ interface ResourceClientActionsConfig {
5
5
  client: InternalMastraMCPClient;
6
6
  logger: IMastraLogger;
7
7
  }
8
+ /**
9
+ * Client-side resource actions for interacting with MCP server resources.
10
+ *
11
+ * Provides methods to list, read, subscribe to, and manage resources exposed by an MCP server.
12
+ * Resources represent any kind of data that a server wants to make available (files, database
13
+ * records, API responses, etc.).
14
+ */
8
15
  export declare class ResourceClientActions {
9
16
  private readonly client;
10
17
  private readonly logger;
18
+ /**
19
+ * @internal
20
+ */
11
21
  constructor({ client, logger }: ResourceClientActionsConfig);
12
22
  /**
13
- * Get all resources from the connected MCP server.
14
- * @returns A list of resources.
23
+ * Retrieves all available resources from the connected MCP server.
24
+ *
25
+ * Returns an empty array if the server doesn't support resources (MethodNotFound error).
26
+ *
27
+ * @returns Promise resolving to array of resources
28
+ * @throws {Error} If fetching resources fails (excluding MethodNotFound)
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const resources = await client.resources.list();
33
+ * resources.forEach(resource => {
34
+ * console.log(`${resource.name}: ${resource.uri}`);
35
+ * });
36
+ * ```
15
37
  */
16
38
  list(): Promise<Resource[]>;
17
39
  /**
18
- * Get all resource templates from the connected MCP server.
19
- * @returns A list of resource templates.
40
+ * Retrieves all available resource templates from the connected MCP server.
41
+ *
42
+ * Resource templates are URI templates (RFC 6570) that describe dynamic resources.
43
+ * Returns an empty array if the server doesn't support resource templates.
44
+ *
45
+ * @returns Promise resolving to array of resource templates
46
+ * @throws {Error} If fetching resource templates fails (excluding MethodNotFound)
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * const templates = await client.resources.templates();
51
+ * templates.forEach(template => {
52
+ * console.log(`${template.name}: ${template.uriTemplate}`);
53
+ * });
54
+ * ```
20
55
  */
21
56
  templates(): Promise<ResourceTemplate[]>;
22
57
  /**
23
- * Read a specific resource.
24
- * @param uri The URI of the resource to read.
25
- * @returns The resource content.
58
+ * Reads the content of a specific resource from the MCP server.
59
+ *
60
+ * @param uri - URI of the resource to read (e.g., 'file://path/to/file.txt')
61
+ * @returns Promise resolving to the resource content
62
+ * @throws {Error} If reading the resource fails or resource not found
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * const result = await client.resources.read('file://data/config.json');
67
+ * console.log(result.contents[0].text); // Resource text content
68
+ * ```
26
69
  */
27
70
  read(uri: string): Promise<import("zod").objectOutputType<{
28
71
  _meta: import("zod").ZodOptional<import("zod").ZodObject<{}, "passthrough", import("zod").ZodTypeAny, import("zod").objectOutputType<{}, import("zod").ZodTypeAny, "passthrough">, import("zod").objectInputType<{}, import("zod").ZodTypeAny, "passthrough">>>;
@@ -66,25 +109,72 @@ export declare class ResourceClientActions {
66
109
  }>, import("zod").ZodTypeAny, "passthrough">>]>, "many">;
67
110
  }, import("zod").ZodTypeAny, "passthrough">>;
68
111
  /**
69
- * Subscribe to a specific resource.
70
- * @param uri The URI of the resource to subscribe to.
112
+ * Subscribes to updates for a specific resource.
113
+ *
114
+ * After subscribing, you'll receive notifications via the `onUpdated` handler
115
+ * when the resource content changes.
116
+ *
117
+ * @param uri - URI of the resource to subscribe to
118
+ * @returns Promise resolving when subscription is established
119
+ * @throws {Error} If subscription fails
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * await client.resources.subscribe('file://data/config.json');
124
+ * ```
71
125
  */
72
126
  subscribe(uri: string): Promise<{}>;
73
127
  /**
74
- * Unsubscribe from a specific resource.
75
- * @param uri The URI of the resource to unsubscribe from.
128
+ * Unsubscribes from updates for a specific resource.
129
+ *
130
+ * Stops receiving notifications for this resource URI.
131
+ *
132
+ * @param uri - URI of the resource to unsubscribe from
133
+ * @returns Promise resolving when unsubscription is complete
134
+ * @throws {Error} If unsubscription fails
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * await client.resources.unsubscribe('file://data/config.json');
139
+ * ```
76
140
  */
77
141
  unsubscribe(uri: string): Promise<{}>;
78
142
  /**
79
- * Set a notification handler for when a specific resource is updated.
80
- * @param handler The callback function to handle the notification.
143
+ * Sets a notification handler for when subscribed resources are updated.
144
+ *
145
+ * The handler is called whenever the server sends a resource update notification
146
+ * for any resource you've subscribed to.
147
+ *
148
+ * @param handler - Callback function receiving the updated resource URI
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * await client.resources.onUpdated(async (params) => {
153
+ * console.log(`Resource updated: ${params.uri}`);
154
+ * // Re-fetch the resource
155
+ * const content = await client.resources.read(params.uri);
156
+ * console.log('New content:', content);
157
+ * });
158
+ * ```
81
159
  */
82
160
  onUpdated(handler: (params: {
83
161
  uri: string;
84
162
  }) => void): Promise<void>;
85
163
  /**
86
- * Set a notification handler for when the list of available resources changes.
87
- * @param handler The callback function to handle the notification.
164
+ * Sets a notification handler for when the list of available resources changes.
165
+ *
166
+ * The handler is called when resources are added or removed from the server.
167
+ *
168
+ * @param handler - Callback function invoked when the resource list changes
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * await client.resources.onListChanged(async () => {
173
+ * console.log('Resource list changed, re-fetching...');
174
+ * const resources = await client.resources.list();
175
+ * console.log('Updated resource count:', resources.length);
176
+ * });
177
+ * ```
88
178
  */
89
179
  onListChanged(handler: () => void): Promise<void>;
90
180
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resourceActions.d.ts","sourceRoot":"","sources":["../../src/client/resourceActions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AACrF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAExD,UAAU,2BAA2B;IACnC,MAAM,EAAE,uBAAuB,CAAC;IAChC,MAAM,EAAE,aAAa,CAAC;CACvB;AAED,qBAAa,qBAAqB;IAChC,OAAO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