@mastra/mcp-docs-server 0.13.8 → 0.13.9-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/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +38 -38
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +38 -38
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +36 -36
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +36 -36
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +33 -33
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +23 -23
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +28 -1
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +23 -23
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +40 -40
- package/.docs/organized/changelogs/%40mastra%2Frag.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +32 -32
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +14 -14
- package/.docs/organized/changelogs/create-mastra.md +17 -17
- package/.docs/organized/changelogs/mastra.md +60 -60
- package/.docs/organized/code-examples/memory-per-resource-example.md +10 -10
- package/.docs/organized/code-examples/memory-with-libsql.md +6 -7
- package/.docs/organized/code-examples/memory-with-pg.md +7 -8
- package/.docs/raw/agents/agent-memory.mdx +11 -7
- package/.docs/raw/memory/semantic-recall.mdx +2 -0
- package/.docs/raw/memory/working-memory.mdx +1 -1
- package/.docs/raw/rag/chunking-and-embedding.mdx +19 -3
- package/.docs/raw/reference/memory/getThreadsByResourceId.mdx +1 -0
- package/.docs/raw/reference/memory/getThreadsByResourceIdPaginated.mdx +187 -0
- package/.docs/raw/reference/rag/chunk.mdx +169 -18
- package/.docs/raw/reference/tools/mcp-server.mdx +61 -7
- package/package.json +4 -4
|
@@ -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)
|
|
@@ -42,21 +42,30 @@ const chunksWithMetadata = await doc.chunk({
|
|
|
42
42
|
|
|
43
43
|
## Parameters
|
|
44
44
|
|
|
45
|
+
The following parameters are available for all chunking strategies.
|
|
46
|
+
**Important:** Each strategy will only utilize a subset of these parameters relevant to its specific use case.
|
|
47
|
+
|
|
45
48
|
<PropertiesTable
|
|
46
49
|
content={[
|
|
47
50
|
{
|
|
48
51
|
name: "strategy",
|
|
49
|
-
type: "'recursive' | 'character' | 'token' | 'markdown' | 'html' | 'json' | 'latex'",
|
|
52
|
+
type: "'recursive' | 'character' | 'token' | 'markdown' | 'html' | 'json' | 'latex' | 'sentence'",
|
|
50
53
|
isOptional: true,
|
|
51
54
|
description:
|
|
52
55
|
"The chunking strategy to use. If not specified, defaults based on document type. Depending on the chunking strategy, there are additional optionals. Defaults: .md files → 'markdown', .html/.htm → 'html', .json → 'json', .tex → 'latex', others → 'recursive'",
|
|
53
56
|
},
|
|
57
|
+
{
|
|
58
|
+
name: "maxSize",
|
|
59
|
+
type: "number",
|
|
60
|
+
isOptional: true,
|
|
61
|
+
defaultValue: "4000",
|
|
62
|
+
description: "Maximum size of each chunk. **Note:** Some strategy configurations (markdown with headers, HTML with headers) ignore this parameter.",
|
|
63
|
+
},
|
|
54
64
|
{
|
|
55
65
|
name: "size",
|
|
56
66
|
type: "number",
|
|
57
67
|
isOptional: true,
|
|
58
|
-
|
|
59
|
-
description: "Maximum size of each chunk",
|
|
68
|
+
description: "**Deprecated:** Use `maxSize` instead. This parameter will be removed in the next major version.",
|
|
60
69
|
},
|
|
61
70
|
{
|
|
62
71
|
name: "overlap",
|
|
@@ -66,33 +75,38 @@ const chunksWithMetadata = await doc.chunk({
|
|
|
66
75
|
description: "Number of characters/tokens that overlap between chunks.",
|
|
67
76
|
},
|
|
68
77
|
{
|
|
69
|
-
name: "
|
|
70
|
-
type: "string",
|
|
78
|
+
name: "lengthFunction",
|
|
79
|
+
type: "(text: string) => number",
|
|
80
|
+
isOptional: true,
|
|
81
|
+
description: "Function to calculate text length. Defaults to character count.",
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "keepSeparator",
|
|
85
|
+
type: "boolean | 'start' | 'end'",
|
|
71
86
|
isOptional: true,
|
|
72
|
-
defaultValue: "\\n\\n",
|
|
73
87
|
description:
|
|
74
|
-
"
|
|
88
|
+
"Whether to keep the separator at the start or end of chunks",
|
|
75
89
|
},
|
|
76
90
|
{
|
|
77
|
-
name: "
|
|
91
|
+
name: "addStartIndex",
|
|
78
92
|
type: "boolean",
|
|
79
93
|
isOptional: true,
|
|
80
94
|
defaultValue: "false",
|
|
81
|
-
description: "Whether
|
|
95
|
+
description: "Whether to add start index metadata to chunks.",
|
|
82
96
|
},
|
|
83
97
|
{
|
|
84
|
-
name: "
|
|
85
|
-
type: "
|
|
98
|
+
name: "stripWhitespace",
|
|
99
|
+
type: "boolean",
|
|
86
100
|
isOptional: true,
|
|
87
|
-
|
|
88
|
-
|
|
101
|
+
defaultValue: "true",
|
|
102
|
+
description: "Whether to strip whitespace from chunks.",
|
|
89
103
|
},
|
|
90
104
|
{
|
|
91
105
|
name: "extract",
|
|
92
106
|
type: "ExtractParams",
|
|
93
107
|
isOptional: true,
|
|
94
108
|
description:
|
|
95
|
-
"Metadata extraction configuration. See [ExtractParams reference](
|
|
109
|
+
"Metadata extraction configuration. See [ExtractParams reference](/reference/rag/extract-params) for details.",
|
|
96
110
|
},
|
|
97
111
|
]}
|
|
98
112
|
/>
|
|
@@ -102,6 +116,32 @@ const chunksWithMetadata = await doc.chunk({
|
|
|
102
116
|
Strategy-specific options are passed as top-level parameters alongside the strategy parameter. For example:
|
|
103
117
|
|
|
104
118
|
```typescript showLineNumbers copy
|
|
119
|
+
// Character strategy example
|
|
120
|
+
const chunks = await doc.chunk({
|
|
121
|
+
strategy: "character",
|
|
122
|
+
separator: ".", // Character-specific option
|
|
123
|
+
isSeparatorRegex: false, // Character-specific option
|
|
124
|
+
maxSize: 300, // general option
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
// Recursive strategy example
|
|
128
|
+
const chunks = await doc.chunk({
|
|
129
|
+
strategy: "recursive",
|
|
130
|
+
separators: ["\n\n", "\n", " "], // Recursive-specific option
|
|
131
|
+
language: "markdown", // Recursive-specific option
|
|
132
|
+
maxSize: 500, // general option
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Sentence strategy example
|
|
136
|
+
const chunks = await doc.chunk({
|
|
137
|
+
strategy: "sentence",
|
|
138
|
+
maxSize: 450, // Required for sentence strategy
|
|
139
|
+
minSize: 50, // Sentence-specific option
|
|
140
|
+
sentenceEnders: ["."], // Sentence-specific option
|
|
141
|
+
fallbackToCharacters: false, // Sentence-specific option
|
|
142
|
+
keepSeparator: true, // general option
|
|
143
|
+
});
|
|
144
|
+
|
|
105
145
|
// HTML strategy example
|
|
106
146
|
const chunks = await doc.chunk({
|
|
107
147
|
strategy: "html",
|
|
@@ -109,8 +149,6 @@ const chunks = await doc.chunk({
|
|
|
109
149
|
["h1", "title"],
|
|
110
150
|
["h2", "subtitle"],
|
|
111
151
|
], // HTML-specific option
|
|
112
|
-
sections: [["div.content", "main"]], // HTML-specific option
|
|
113
|
-
size: 500, // general option
|
|
114
152
|
});
|
|
115
153
|
|
|
116
154
|
// Markdown strategy example
|
|
@@ -121,7 +159,6 @@ const chunks = await doc.chunk({
|
|
|
121
159
|
["##", "section"],
|
|
122
160
|
], // Markdown-specific option
|
|
123
161
|
stripHeaders: true, // Markdown-specific option
|
|
124
|
-
overlap: 50, // general option
|
|
125
162
|
});
|
|
126
163
|
|
|
127
164
|
// Token strategy example
|
|
@@ -129,12 +166,105 @@ const chunks = await doc.chunk({
|
|
|
129
166
|
strategy: "token",
|
|
130
167
|
encodingName: "gpt2", // Token-specific option
|
|
131
168
|
modelName: "gpt-3.5-turbo", // Token-specific option
|
|
132
|
-
|
|
169
|
+
maxSize: 1000, // general option
|
|
133
170
|
});
|
|
134
171
|
```
|
|
135
172
|
|
|
136
173
|
The options documented below are passed directly at the top level of the configuration object, not nested within a separate options object.
|
|
137
174
|
|
|
175
|
+
### Character
|
|
176
|
+
|
|
177
|
+
<PropertiesTable
|
|
178
|
+
content={[
|
|
179
|
+
{
|
|
180
|
+
name: "separator",
|
|
181
|
+
type: "string",
|
|
182
|
+
isOptional: true,
|
|
183
|
+
defaultValue: "\\n\\n",
|
|
184
|
+
description: "Character(s) to split on. Defaults to double newline for text content.",
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: "isSeparatorRegex",
|
|
188
|
+
type: "boolean",
|
|
189
|
+
isOptional: true,
|
|
190
|
+
defaultValue: "false",
|
|
191
|
+
description: "Whether the separator is a regex pattern",
|
|
192
|
+
},
|
|
193
|
+
]}
|
|
194
|
+
/>
|
|
195
|
+
|
|
196
|
+
### Recursive
|
|
197
|
+
|
|
198
|
+
<PropertiesTable
|
|
199
|
+
content={[
|
|
200
|
+
{
|
|
201
|
+
name: "separators",
|
|
202
|
+
type: "string[]",
|
|
203
|
+
isOptional: true,
|
|
204
|
+
description: "Array of separators to try in order of preference. The strategy will attempt to split on the first separator, then fall back to subsequent ones.",
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: "isSeparatorRegex",
|
|
208
|
+
type: "boolean",
|
|
209
|
+
isOptional: true,
|
|
210
|
+
defaultValue: "false",
|
|
211
|
+
description: "Whether the separators are regex patterns",
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
name: "language",
|
|
215
|
+
type: "Language",
|
|
216
|
+
isOptional: true,
|
|
217
|
+
description: "Programming or markup language for language-specific splitting behavior. See Language enum for supported values.",
|
|
218
|
+
},
|
|
219
|
+
]}
|
|
220
|
+
/>
|
|
221
|
+
|
|
222
|
+
### Sentence
|
|
223
|
+
|
|
224
|
+
<PropertiesTable
|
|
225
|
+
content={[
|
|
226
|
+
{
|
|
227
|
+
name: "maxSize",
|
|
228
|
+
type: "number",
|
|
229
|
+
description: "Maximum size of each chunk (required for sentence strategy)",
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
name: "minSize",
|
|
233
|
+
type: "number",
|
|
234
|
+
isOptional: true,
|
|
235
|
+
defaultValue: "50",
|
|
236
|
+
description: "Minimum size of each chunk. Chunks smaller than this will be merged with adjacent chunks when possible.",
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: "targetSize",
|
|
240
|
+
type: "number",
|
|
241
|
+
isOptional: true,
|
|
242
|
+
description: "Preferred target size for chunks. Defaults to 80% of maxSize. The strategy will try to create chunks close to this size.",
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: "sentenceEnders",
|
|
246
|
+
type: "string[]",
|
|
247
|
+
isOptional: true,
|
|
248
|
+
defaultValue: "['.', '!', '?']",
|
|
249
|
+
description: "Array of characters that mark sentence endings for splitting boundaries.",
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: "fallbackToWords",
|
|
253
|
+
type: "boolean",
|
|
254
|
+
isOptional: true,
|
|
255
|
+
defaultValue: "true",
|
|
256
|
+
description: "Whether to fall back to word-level splitting for sentences that exceed maxSize.",
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: "fallbackToCharacters",
|
|
260
|
+
type: "boolean",
|
|
261
|
+
isOptional: true,
|
|
262
|
+
defaultValue: "true",
|
|
263
|
+
description: "Whether to fall back to character-level splitting for words that exceed maxSize. Only applies if fallbackToWords is enabled.",
|
|
264
|
+
},
|
|
265
|
+
]}
|
|
266
|
+
/>
|
|
267
|
+
|
|
138
268
|
### HTML
|
|
139
269
|
|
|
140
270
|
<PropertiesTable
|
|
@@ -160,6 +290,8 @@ The options documented below are passed directly at the top level of the configu
|
|
|
160
290
|
]}
|
|
161
291
|
/>
|
|
162
292
|
|
|
293
|
+
**Important:** When using the HTML strategy, all general options are ignored. Use `headers` for header-based splitting or `sections` for section-based splitting. If used together, `sections` will be ignored.
|
|
294
|
+
|
|
163
295
|
### Markdown
|
|
164
296
|
|
|
165
297
|
<PropertiesTable
|
|
@@ -167,6 +299,7 @@ The options documented below are passed directly at the top level of the configu
|
|
|
167
299
|
{
|
|
168
300
|
name: "headers",
|
|
169
301
|
type: "Array<[string, string]>",
|
|
302
|
+
isOptional: true,
|
|
170
303
|
description: "Array of [header level, metadata key] pairs",
|
|
171
304
|
},
|
|
172
305
|
{
|
|
@@ -184,6 +317,8 @@ The options documented below are passed directly at the top level of the configu
|
|
|
184
317
|
]}
|
|
185
318
|
/>
|
|
186
319
|
|
|
320
|
+
**Important:** When using the `headers` option, the markdown strategy ignores all general options and content is split based on the markdown header structure. To use size-based chunking with markdown, omit the `headers` parameter.
|
|
321
|
+
|
|
187
322
|
### Token
|
|
188
323
|
|
|
189
324
|
<PropertiesTable
|
|
@@ -200,6 +335,18 @@ The options documented below are passed directly at the top level of the configu
|
|
|
200
335
|
isOptional: true,
|
|
201
336
|
description: "Name of the model for tokenization",
|
|
202
337
|
},
|
|
338
|
+
{
|
|
339
|
+
name: "allowedSpecial",
|
|
340
|
+
type: "Set<string> | 'all'",
|
|
341
|
+
isOptional: true,
|
|
342
|
+
description: "Set of special tokens allowed during tokenization, or 'all' to allow all special tokens",
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
name: "disallowedSpecial",
|
|
346
|
+
type: "Set<string> | 'all'",
|
|
347
|
+
isOptional: true,
|
|
348
|
+
description: "Set of special tokens to disallow during tokenization, or 'all' to disallow all special tokens",
|
|
349
|
+
},
|
|
203
350
|
]}
|
|
204
351
|
/>
|
|
205
352
|
|
|
@@ -233,6 +380,10 @@ The options documented below are passed directly at the top level of the configu
|
|
|
233
380
|
]}
|
|
234
381
|
/>
|
|
235
382
|
|
|
383
|
+
### Latex
|
|
384
|
+
|
|
385
|
+
The Latex strategy uses only the general chunking options listed above. It provides LaTeX-aware splitting optimized for mathematical and academic documents.
|
|
386
|
+
|
|
236
387
|
## Return Value
|
|
237
388
|
|
|
238
389
|
Returns a `MDocument` instance containing the chunked documents. Each chunk includes:
|
|
@@ -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
|
|
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
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
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.
|
|
3
|
+
"version": "0.13.9-alpha.1",
|
|
4
4
|
"description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -32,7 +32,7 @@
|
|
|
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.
|
|
35
|
+
"@mastra/core": "0.13.0-alpha.1",
|
|
36
36
|
"@mastra/mcp": "^0.10.9"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"tsx": "^4.19.4",
|
|
49
49
|
"typescript": "^5.8.3",
|
|
50
50
|
"vitest": "^3.2.4",
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
51
|
+
"@internal/lint": "0.0.26",
|
|
52
|
+
"@mastra/core": "0.13.0-alpha.1"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"prepare-docs": "cross-env PREPARE=true node dist/prepare-docs/prepare.js",
|