@mastra/mcp-docs-server 0.13.8 → 0.13.9-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.
Files changed (29) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +14 -14
  2. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +23 -23
  3. package/.docs/organized/changelogs/%40mastra%2Fcloud.md +15 -15
  4. package/.docs/organized/changelogs/%40mastra%2Fcore.md +26 -26
  5. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +24 -24
  6. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +24 -24
  7. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +24 -24
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +25 -25
  9. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +14 -14
  10. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +23 -23
  11. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +14 -14
  12. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +11 -11
  13. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +13 -13
  14. package/.docs/organized/changelogs/%40mastra%2Fpg.md +23 -23
  15. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +28 -28
  16. package/.docs/organized/changelogs/%40mastra%2Frag.md +14 -14
  17. package/.docs/organized/changelogs/%40mastra%2Fserver.md +22 -22
  18. package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +14 -14
  19. package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +14 -14
  20. package/.docs/organized/changelogs/create-mastra.md +15 -15
  21. package/.docs/organized/changelogs/mastra.md +46 -46
  22. package/.docs/organized/code-examples/memory-per-resource-example.md +10 -10
  23. package/.docs/organized/code-examples/memory-with-libsql.md +6 -7
  24. package/.docs/organized/code-examples/memory-with-pg.md +7 -8
  25. package/.docs/raw/agents/agent-memory.mdx +11 -7
  26. package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +1 -0
  27. package/.docs/raw/reference/memory/getThreadsByResourceIdPaginated.mdx +187 -0
  28. package/.docs/raw/reference/tools/mcp-server.mdx +61 -7
  29. package/package.json +5 -5
@@ -0,0 +1,187 @@
1
+ # getThreadsByResourceIdPaginated Reference
2
+
3
+ The `getThreadsByResourceIdPaginated` function retrieves threads associated with a specific resource ID with pagination support. This method addresses performance and memory usage concerns when dealing with large numbers of threads by returning results in manageable chunks with metadata for navigation.
4
+
5
+ ## Usage Example
6
+
7
+ ```typescript
8
+ import { Memory } from "@mastra/core/memory";
9
+
10
+ const memory = new Memory(config);
11
+
12
+ // Basic usage with default parameters
13
+ const result = await memory.getThreadsByResourceIdPaginated({
14
+ resourceId: "resource-123",
15
+ page: 0,
16
+ perPage: 100,
17
+ });
18
+
19
+ console.log(result.threads);
20
+ console.log(result.total);
21
+ console.log(result.hasMore);
22
+
23
+ // Custom pagination with sorting
24
+ const customResult = await memory.getThreadsByResourceIdPaginated({
25
+ resourceId: "resource-123",
26
+ page: 2,
27
+ perPage: 50,
28
+ orderBy: "updatedAt",
29
+ sortDirection: "ASC",
30
+ });
31
+
32
+ // Process paginated results
33
+ let currentPage = 0;
34
+ let hasMorePages = true;
35
+
36
+ while (hasMorePages) {
37
+ const pageResult = await memory.getThreadsByResourceIdPaginated({
38
+ resourceId: "user-456",
39
+ page: currentPage,
40
+ perPage: 25,
41
+ orderBy: "createdAt",
42
+ sortDirection: "DESC",
43
+ });
44
+
45
+ // Process threads
46
+ pageResult.threads.forEach(thread => {
47
+ console.log(`Thread: ${thread.id}, Created: ${thread.createdAt}`);
48
+ });
49
+
50
+ hasMorePages = pageResult.hasMore;
51
+ currentPage++;
52
+ }
53
+ ```
54
+
55
+ ## Parameters
56
+
57
+ <PropertiesTable
58
+ content={[
59
+ {
60
+ name: "resourceId",
61
+ type: "string",
62
+ description: "The ID of the resource whose threads are to be retrieved.",
63
+ isOptional: false,
64
+ },
65
+ {
66
+ name: "page",
67
+ type: "number",
68
+ description: "Page number to retrieve. Must be a positive integer.",
69
+ isOptional: false,
70
+ },
71
+ {
72
+ name: "perPage",
73
+ type: "number",
74
+ description: "Number of threads to return per page. Must be a positive integer.",
75
+ isOptional: false,
76
+ },
77
+ {
78
+ name: "orderBy",
79
+ type: "ThreadOrderBy",
80
+ description: "Field to sort threads by. Accepts 'createdAt' or 'updatedAt'. Default: 'createdAt'",
81
+ isOptional: true,
82
+ },
83
+ {
84
+ name: "sortDirection",
85
+ type: "ThreadSortDirection",
86
+ description: "Sort order direction. Accepts 'ASC' or 'DESC'. Default: 'DESC'",
87
+ isOptional: true,
88
+ },
89
+ ]}
90
+ />
91
+
92
+ ## Type Definitions
93
+
94
+ ```typescript
95
+ type ThreadOrderBy = 'createdAt' | 'updatedAt';
96
+ type ThreadSortDirection = 'ASC' | 'DESC';
97
+
98
+ interface ThreadSortOptions {
99
+ orderBy?: ThreadOrderBy;
100
+ sortDirection?: ThreadSortDirection;
101
+ }
102
+
103
+ interface PaginationInfo {
104
+ total: number; // Total number of threads across all pages
105
+ page: number; // Current page number
106
+ perPage: number; // Number of threads per page
107
+ hasMore: boolean; // Whether additional pages exist
108
+ }
109
+ ```
110
+
111
+ ## Returns
112
+
113
+ <PropertiesTable
114
+ content={[
115
+ {
116
+ name: "threads",
117
+ type: "StorageThreadType[]",
118
+ description: "Array of threads for the current page, sorted according to the specified criteria.",
119
+ },
120
+ {
121
+ name: "total",
122
+ type: "number",
123
+ description: "Total number of threads associated with the resource ID across all pages.",
124
+ },
125
+ {
126
+ name: "page",
127
+ type: "number",
128
+ description: "Current page number.",
129
+ },
130
+ {
131
+ name: "perPage",
132
+ type: "number",
133
+ description: "Number of threads returned per page as specified in the request.",
134
+ },
135
+ {
136
+ name: "hasMore",
137
+ type: "boolean",
138
+ description: "Indicates whether additional pages of results are available.",
139
+ },
140
+ ]}
141
+ />
142
+
143
+ ## Technical Notes
144
+
145
+ ### Performance Considerations
146
+
147
+ This method executes database-level pagination using LIMIT/OFFSET operations (or equivalent), which provides better performance and memory usage compared to retrieving all threads and paginating in application code.
148
+
149
+ ### Default Values
150
+
151
+ - `orderBy`: Defaults to `"createdAt"`
152
+ - `sortDirection`: Defaults to `"DESC"` (newest first)
153
+
154
+ ### Relationship to getThreadsByResourceId
155
+
156
+ The paginated version (`getThreadsByResourceIdPaginated`) complements the existing `getThreadsByResourceId` method:
157
+
158
+ - Use `getThreadsByResourceId` when you need all threads for a resource
159
+ - Use `getThreadsByResourceIdPaginated` when working with potentially large thread collections or implementing UI pagination
160
+
161
+ Both methods support the same sorting options for consistency.
162
+
163
+ ### Error Handling
164
+
165
+ ```typescript
166
+ try {
167
+ const result = await memory.getThreadsByResourceIdPaginated({
168
+ resourceId: "resource-123",
169
+ page: 0,
170
+ perPage: 100,
171
+ });
172
+
173
+ if (result.threads.length === 0) {
174
+ console.log("No threads found for this resource");
175
+ }
176
+ } catch (error) {
177
+ console.error("Failed to retrieve paginated threads:", error);
178
+ }
179
+ ```
180
+
181
+ ### Related
182
+
183
+ - [Memory Class Reference](/reference/memory/Memory.mdx)
184
+ - [getThreadsByResourceId](/reference/memory/getThreadsByResourceId.mdx) - Non-paginated version
185
+ - [Getting Started with Memory](/docs/memory/overview.mdx) (Covers threads/resources concept)
186
+ - [createThread](/reference/memory/createThread.mdx)
187
+ - [getThreadById](/reference/memory/getThreadById.mdx)
@@ -848,8 +848,14 @@ When tools are executed within an MCP server context, they receive an additional
848
848
  ```typescript
849
849
  execute: async ({ context }, options) => {
850
850
  // context contains the tool's input parameters
851
- // options contains server capabilities like elicitation
851
+ // options contains server capabilities like elicitation and authentication info
852
852
 
853
+ // Access authentication information (when available)
854
+ if (options.extra?.authInfo) {
855
+ console.log('Authenticated request from:', options.extra.authInfo.clientId);
856
+ }
857
+
858
+ // Use elicitation capabilities
853
859
  const result = await options.elicitation.sendRequest({
854
860
  message: "Please provide information",
855
861
  requestedSchema: { /* schema */ }
@@ -891,9 +897,12 @@ const server = new MCPServer({
891
897
  }),
892
898
  execute: async ({ context }, options) => {
893
899
  const { reason } = context;
900
+
901
+ // Log session info if available
902
+ console.log('Request from session:', options.extra?.sessionId);
894
903
 
895
904
  try {
896
- // Request user input via elicitation through the options parameter
905
+ // Request user input via elicitation
897
906
  const result = await options.elicitation.sendRequest({
898
907
  message: reason
899
908
  ? `Please provide your contact information. ${reason}`
@@ -1002,10 +1011,18 @@ The elicitation functionality is available through the `options` parameter in to
1002
1011
 
1003
1012
  ```typescript
1004
1013
  // Within a tool's execute function
1005
- options.elicitation.sendRequest({
1006
- message: string, // Message to display to user
1007
- requestedSchema: object // JSON schema defining expected response structure
1008
- }): Promise<ElicitResult>
1014
+ execute: async ({ context }, options) => {
1015
+ // Use elicitation for user input
1016
+ const result = await options.elicitation.sendRequest({
1017
+ message: string, // Message to display to user
1018
+ requestedSchema: object // JSON schema defining expected response structure
1019
+ }): Promise<ElicitResult>
1020
+
1021
+ // Access authentication info if needed
1022
+ if (options.extra?.authInfo) {
1023
+ // Use options.extra.authInfo.token, etc.
1024
+ }
1025
+ }
1009
1026
  ```
1010
1027
 
1011
1028
  Note that elicitation is **session-aware** when using HTTP-based transports (SSE or HTTP). This means that when multiple clients are connected to the same server, elicitation requests are routed to the correct client session that initiated the tool execution.
@@ -1019,7 +1036,44 @@ type ElicitResult = {
1019
1036
  }
1020
1037
  ```
1021
1038
 
1039
+ ## Authentication Context
1040
+
1041
+ Tools can access request metadata via `options.extra` when using HTTP-based transports:
1042
+
1043
+ ```typescript
1044
+ execute: async ({ context }, options) => {
1045
+ if (!options.extra?.authInfo?.token) {
1046
+ return "Authentication required";
1047
+ }
1048
+
1049
+ // Use the auth token
1050
+ const response = await fetch('/api/data', {
1051
+ headers: { Authorization: `Bearer ${options.extra.authInfo.token}` },
1052
+ signal: options.extra.signal,
1053
+ });
1054
+
1055
+ return response.json();
1056
+ }
1057
+ ```
1058
+
1059
+ The `extra` object contains:
1060
+ - `authInfo`: Authentication info (when provided by server middleware)
1061
+ - `sessionId`: Session identifier
1062
+ - `signal`: AbortSignal for cancellation
1063
+ - `sendNotification`/`sendRequest`: MCP protocol functions
1064
+
1065
+ > Note: To enable authentication, your HTTP server needs middleware that populates `req.auth` before calling `server.startHTTP()`. For example:
1066
+ > ```typescript
1067
+ > httpServer.createServer((req, res) => {
1068
+ > // Add auth middleware
1069
+ > req.auth = validateAuthToken(req.headers.authorization);
1070
+ >
1071
+ > // Then pass to MCP server
1072
+ > await server.startHTTP({ url, httpPath, req, res });
1073
+ > });
1074
+ > ```
1075
+
1022
1076
  ## Related Information
1023
1077
 
1024
1078
  - For connecting to MCP servers in Mastra, see the [MCPClient documentation](./mcp-client).
1025
- - For more about the Model Context Protocol, see the [@modelcontextprotocol/sdk documentation](https://github.com/modelcontextprotocol/typescript-sdk).
1079
+ - For more about the Model Context Protocol, see the [@modelcontextprotocol/sdk documentation](https://github.com/modelcontextprotocol/typescript-sdk).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp-docs-server",
3
- "version": "0.13.8",
3
+ "version": "0.13.9-alpha.0",
4
4
  "description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -32,8 +32,8 @@
32
32
  "uuid": "^11.1.0",
33
33
  "zod": "^3.25.67",
34
34
  "zod-to-json-schema": "^3.24.5",
35
- "@mastra/core": "0.12.1",
36
- "@mastra/mcp": "^0.10.9"
35
+ "@mastra/mcp": "^0.10.9",
36
+ "@mastra/core": "0.12.2-alpha.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@hono/node-server": "^1.17.1",
@@ -48,8 +48,8 @@
48
48
  "tsx": "^4.19.4",
49
49
  "typescript": "^5.8.3",
50
50
  "vitest": "^3.2.4",
51
- "@mastra/core": "0.12.1",
52
- "@internal/lint": "0.0.25"
51
+ "@internal/lint": "0.0.26",
52
+ "@mastra/core": "0.12.2-alpha.0"
53
53
  },
54
54
  "scripts": {
55
55
  "prepare-docs": "cross-env PREPARE=true node dist/prepare-docs/prepare.js",