@mastra/mcp-docs-server 0.13.9-alpha.0 → 0.13.9-alpha.2
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%2Ftypes-builder.md +1 -0
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fauth.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +36 -36
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +30 -30
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +30 -30
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Flance.md +13 -0
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fmem0.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +30 -30
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +35 -35
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +42 -1
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Frag.md +26 -26
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +13 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +14 -14
- package/.docs/organized/changelogs/create-mastra.md +5 -5
- package/.docs/organized/changelogs/mastra.md +32 -32
- package/.docs/organized/code-examples/workflow-with-separate-steps.md +83 -40
- package/.docs/raw/agents/overview.mdx +1 -0
- package/.docs/raw/course/02-agent-tools-mcp/14-getting-github-mcp-url.md +27 -8
- package/.docs/raw/course/02-agent-tools-mcp/15-updating-mcp-config-github.md +1 -1
- package/.docs/raw/memory/memory-processors.mdx +4 -3
- 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/rag/chunk.mdx +169 -18
- package/.docs/raw/workflows/using-with-agents-and-tools.mdx +25 -0
- package/package.json +6 -6
|
@@ -20,15 +20,21 @@
|
|
|
20
20
|
import { mastra } from './mastra';
|
|
21
21
|
|
|
22
22
|
async function main() {
|
|
23
|
-
const
|
|
24
|
-
const { start } = myWorkflow.createRun();
|
|
23
|
+
const run = await mastra.getWorkflow('myWorkflow').createRunAsync();
|
|
25
24
|
try {
|
|
26
|
-
const res = await start({
|
|
27
|
-
|
|
28
|
-
inputValue:
|
|
25
|
+
const res = await run.start({
|
|
26
|
+
inputData: {
|
|
27
|
+
inputValue: 12,
|
|
29
28
|
},
|
|
30
29
|
});
|
|
31
|
-
|
|
30
|
+
|
|
31
|
+
if (res.status === 'success') {
|
|
32
|
+
console.log(res.result);
|
|
33
|
+
} else if (res.status === 'failed') {
|
|
34
|
+
console.log('Workflow failed:', res.error);
|
|
35
|
+
} else {
|
|
36
|
+
console.log('Workflow suspended:', res.suspended);
|
|
37
|
+
}
|
|
32
38
|
} catch (e) {
|
|
33
39
|
console.log(e);
|
|
34
40
|
}
|
|
@@ -54,64 +60,101 @@ export const mastra = new Mastra({
|
|
|
54
60
|
|
|
55
61
|
### mastra/workflows/index.ts
|
|
56
62
|
```typescript
|
|
57
|
-
import {
|
|
63
|
+
import { createStep, createWorkflow } from '@mastra/core/workflows';
|
|
58
64
|
import { z } from 'zod';
|
|
59
65
|
|
|
60
|
-
const stepOne =
|
|
66
|
+
const stepOne = createStep({
|
|
61
67
|
id: 'stepOne',
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
inputSchema: z.object({
|
|
69
|
+
inputValue: z.number(),
|
|
70
|
+
}),
|
|
71
|
+
outputSchema: z.object({
|
|
72
|
+
doubledValue: z.number(),
|
|
73
|
+
isOriginalOdd: z.boolean(), // Track original parity
|
|
74
|
+
}),
|
|
75
|
+
execute: async ({ inputData }) => {
|
|
76
|
+
const doubledValue = inputData.inputValue * 2;
|
|
77
|
+
const isOriginalOdd = inputData.inputValue % 2 === 1;
|
|
78
|
+
return { doubledValue, isOriginalOdd };
|
|
66
79
|
},
|
|
67
80
|
});
|
|
68
81
|
|
|
69
|
-
const stepTwo =
|
|
82
|
+
const stepTwo = createStep({
|
|
70
83
|
id: 'stepTwo',
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
84
|
+
inputSchema: z.object({
|
|
85
|
+
doubledValue: z.number(),
|
|
86
|
+
isOriginalOdd: z.boolean(),
|
|
87
|
+
}),
|
|
88
|
+
outputSchema: z.object({
|
|
89
|
+
incrementedValue: z.number(),
|
|
90
|
+
}),
|
|
91
|
+
execute: async ({ inputData }) => {
|
|
92
|
+
// Increment only if original input was odd
|
|
93
|
+
const incrementedValue = inputData.doubledValue + (inputData.isOriginalOdd ? 1 : 0);
|
|
77
94
|
return { incrementedValue };
|
|
78
95
|
},
|
|
79
96
|
});
|
|
80
97
|
|
|
81
|
-
const stepThree =
|
|
98
|
+
const stepThree = createStep({
|
|
82
99
|
id: 'stepThree',
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
100
|
+
inputSchema: z.object({
|
|
101
|
+
incrementedValue: z.number(),
|
|
102
|
+
}),
|
|
103
|
+
outputSchema: z.object({
|
|
104
|
+
tripledValue: z.number(),
|
|
105
|
+
}),
|
|
106
|
+
execute: async ({ inputData, getStepResult }) => {
|
|
107
|
+
try {
|
|
108
|
+
const stepTwoResult = getStepResult(stepTwo);
|
|
109
|
+
if (!stepTwoResult || typeof stepTwoResult.incrementedValue !== 'number') {
|
|
110
|
+
throw new Error('stepTwo failed or returned invalid data');
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
throw new Error(`stepTwo failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const tripledValue = inputData.incrementedValue * 3;
|
|
86
117
|
return { tripledValue };
|
|
87
118
|
},
|
|
88
119
|
});
|
|
89
120
|
|
|
90
|
-
const stepFour =
|
|
121
|
+
const stepFour = createStep({
|
|
91
122
|
id: 'stepFour',
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
123
|
+
inputSchema: z.object({
|
|
124
|
+
tripledValue: z.number(),
|
|
125
|
+
}),
|
|
126
|
+
outputSchema: z.object({
|
|
127
|
+
isEven: z.boolean(),
|
|
128
|
+
}),
|
|
129
|
+
execute: async ({ inputData, getStepResult }) => {
|
|
130
|
+
try {
|
|
131
|
+
const stepThreeResult = getStepResult(stepThree);
|
|
132
|
+
if (!stepThreeResult || typeof stepThreeResult.tripledValue !== 'number') {
|
|
133
|
+
throw new Error('stepThree failed or returned invalid data');
|
|
134
|
+
}
|
|
135
|
+
} catch (error) {
|
|
136
|
+
throw new Error(`stepThree failed: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
95
137
|
}
|
|
96
|
-
|
|
97
|
-
const isEven =
|
|
138
|
+
|
|
139
|
+
const isEven = inputData.tripledValue % 2 === 0;
|
|
98
140
|
return { isEven };
|
|
99
141
|
},
|
|
100
142
|
});
|
|
101
143
|
|
|
102
|
-
export const myWorkflow =
|
|
103
|
-
|
|
104
|
-
|
|
144
|
+
export const myWorkflow = createWorkflow({
|
|
145
|
+
id: 'my-workflow',
|
|
146
|
+
inputSchema: z.object({
|
|
105
147
|
inputValue: z.number(),
|
|
106
148
|
}),
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
149
|
+
outputSchema: z.object({
|
|
150
|
+
isEven: z.boolean(),
|
|
151
|
+
}),
|
|
152
|
+
})
|
|
153
|
+
.then(stepOne)
|
|
154
|
+
.then(stepTwo)
|
|
155
|
+
.then(stepThree)
|
|
156
|
+
.then(stepFour);
|
|
114
157
|
|
|
115
|
-
|
|
158
|
+
myWorkflow.commit();
|
|
116
159
|
|
|
117
160
|
```
|
|
@@ -1,16 +1,35 @@
|
|
|
1
|
-
# Getting a
|
|
1
|
+
# Getting a Smithery GitHub MCP URL
|
|
2
2
|
|
|
3
|
-
First, you'll need to get a
|
|
3
|
+
First, you'll need to get a Smithery GitHub MCP URL. This typically requires:
|
|
4
4
|
|
|
5
|
-
1. Setting up
|
|
6
|
-
2.
|
|
7
|
-
3. Getting your unique MCP URL
|
|
5
|
+
1. Setting up a Smithery account
|
|
6
|
+
2. Creating a personal access token with your GitHub account
|
|
7
|
+
3. Getting your unique MCP URL via the Smithery packages
|
|
8
8
|
|
|
9
|
-
For this example, we'll use an environment variable to store the
|
|
9
|
+
For this example, we'll use an environment variable to store the Smithery API key and profile name which can be found in the Smithery interface.
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
12
|
# Add this to your .env file
|
|
13
|
-
|
|
13
|
+
SMITHERY_API_KEY=your_smithery_api_key
|
|
14
|
+
SMITHERY_PROFILE=your_smithery_profile_name
|
|
14
15
|
```
|
|
15
16
|
|
|
16
|
-
Using an environment variable keeps your configuration secure and flexible.
|
|
17
|
+
Using an environment variable keeps your configuration secure and flexible. It also prevents sensitive information from being committed to your repository.
|
|
18
|
+
|
|
19
|
+
We will use the Smithery packages to authenticate and create a streamable HTTP URL for the MCP server configuration
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pnpm install @smithery/sdk
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { createSmitheryUrl } from "@smithery/sdk";
|
|
27
|
+
|
|
28
|
+
const smitheryGithubMCPServerUrl = createSmitheryUrl(
|
|
29
|
+
"https://server.smithery.ai/@smithery-ai/github",
|
|
30
|
+
{
|
|
31
|
+
apiKey: process.env.SMITHERY_API_KEY,
|
|
32
|
+
profile: process.env.SMITHERY_PROFILE,
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
```
|
|
@@ -97,9 +97,10 @@ const memoryWithMultipleProcessors = new Memory({
|
|
|
97
97
|
|
|
98
98
|
You can create custom logic by extending the base `MemoryProcessor` class.
|
|
99
99
|
|
|
100
|
-
```typescript copy showLineNumbers {
|
|
101
|
-
import { Memory
|
|
102
|
-
import {
|
|
100
|
+
```typescript copy showLineNumbers {5-20,24-27}
|
|
101
|
+
import { Memory } from "@mastra/memory";
|
|
102
|
+
import { CoreMessage, MemoryProcessorOpts } from "@mastra/core";
|
|
103
|
+
import { MemoryProcessor } from "@mastra/core/memory";
|
|
103
104
|
|
|
104
105
|
class ConversationOnlyFilter extends MemoryProcessor {
|
|
105
106
|
constructor() {
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
If you ask your friend what they did last weekend, they will search in their memory for events associated with "last weekend" and then tell you what they did. That's sort of like how semantic recall works in Mastra.
|
|
4
4
|
|
|
5
|
+
> **📹 Watch**: What semantic recall is, how it works, and how to configure it in Mastra → [YouTube (5 minutes)](https://youtu.be/UVZtK8cK8xQ)
|
|
6
|
+
|
|
5
7
|
## How Semantic Recall Works
|
|
6
8
|
|
|
7
9
|
Semantic recall is RAG-based search that helps agents maintain context across longer interactions when messages are no longer within [recent conversation history](./overview.mdx#conversation-history).
|
|
@@ -43,7 +43,7 @@ const agent = new Agent({
|
|
|
43
43
|
|
|
44
44
|
Working memory is a block of Markdown text that the agent is able to update over time to store continuously relevant information:
|
|
45
45
|
|
|
46
|
-
<YouTube id="
|
|
46
|
+
<YouTube id="UMy_JHLf1n8" />
|
|
47
47
|
|
|
48
48
|
## Memory Persistence Scopes
|
|
49
49
|
|
|
@@ -25,21 +25,37 @@ Use `chunk` to split documents into manageable pieces. Mastra supports multiple
|
|
|
25
25
|
- `html`: HTML structure-aware splitting
|
|
26
26
|
- `json`: JSON structure-aware splitting
|
|
27
27
|
- `latex`: LaTeX structure-aware splitting
|
|
28
|
+
- `sentence`: Sentence-aware splitting
|
|
29
|
+
|
|
30
|
+
**Note:** Each strategy accepts different parameters optimized for its chunking approach.
|
|
28
31
|
|
|
29
32
|
Here's an example of how to use the `recursive` strategy:
|
|
30
33
|
|
|
31
34
|
```ts showLineNumbers copy
|
|
32
35
|
const chunks = await doc.chunk({
|
|
33
36
|
strategy: "recursive",
|
|
34
|
-
|
|
37
|
+
maxSize: 512,
|
|
35
38
|
overlap: 50,
|
|
36
|
-
|
|
39
|
+
separators: ["\n"],
|
|
37
40
|
extract: {
|
|
38
41
|
metadata: true, // Optionally extract metadata
|
|
39
42
|
},
|
|
40
43
|
});
|
|
41
44
|
```
|
|
42
45
|
|
|
46
|
+
For text where preserving sentence structure is important, here's an example of how to use the `sentence` strategy:
|
|
47
|
+
|
|
48
|
+
```ts showLineNumbers copy
|
|
49
|
+
const chunks = await doc.chunk({
|
|
50
|
+
strategy: "sentence",
|
|
51
|
+
maxSize: 450,
|
|
52
|
+
minSize: 50,
|
|
53
|
+
overlap: 0,
|
|
54
|
+
sentenceEnders: ["."],
|
|
55
|
+
keepSeparator: true,
|
|
56
|
+
});
|
|
57
|
+
```
|
|
58
|
+
|
|
43
59
|
**Note:** Metadata extraction may use LLM calls, so ensure your API key is set.
|
|
44
60
|
|
|
45
61
|
We go deeper into chunking strategies in our [chunk documentation](/reference/rag/chunk.mdx).
|
|
@@ -130,7 +146,7 @@ const doc = MDocument.fromText(`
|
|
|
130
146
|
// Create chunks
|
|
131
147
|
const chunks = await doc.chunk({
|
|
132
148
|
strategy: "recursive",
|
|
133
|
-
|
|
149
|
+
maxSize: 256,
|
|
134
150
|
overlap: 50,
|
|
135
151
|
});
|
|
136
152
|
|
|
@@ -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:
|
|
@@ -258,6 +258,31 @@ export const cityCoordinatesTool = createTool({
|
|
|
258
258
|
});
|
|
259
259
|
```
|
|
260
260
|
|
|
261
|
+
## Using workflows in agents
|
|
262
|
+
|
|
263
|
+
You can also use Workflows in Agents. This agent is able to choose between using the test tool or the test workflow.
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
import { openai } from "@ai-sdk/openai";
|
|
267
|
+
import { Agent } from "@mastra/core/agent";
|
|
268
|
+
import { testTool } from "../tools/test-tool";
|
|
269
|
+
import { testWorkflow } from "../workflows/test-workflow";
|
|
270
|
+
|
|
271
|
+
export const testAgent = new Agent({
|
|
272
|
+
name: "test-agent",
|
|
273
|
+
description: "Create facts for a country based on the city",
|
|
274
|
+
instructions: `Return an interesting fact about the country based on the city provided`,
|
|
275
|
+
model: openai("gpt-4o"),
|
|
276
|
+
workflows: {
|
|
277
|
+
test_workflow: testWorkflow
|
|
278
|
+
},
|
|
279
|
+
tools: {
|
|
280
|
+
test_tool: testTool
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
|
|
261
286
|
## Exposing workflows with `MCPServer`
|
|
262
287
|
|
|
263
288
|
You can convert your workflows into tools by passing them into an instance of a Mastra `MCPServer`. This allows any MCP-compatible client to access your workflow.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp-docs-server",
|
|
3
|
-
"version": "0.13.9-alpha.
|
|
3
|
+
"version": "0.13.9-alpha.2",
|
|
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/
|
|
36
|
-
"@mastra/
|
|
35
|
+
"@mastra/core": "0.13.0-alpha.2",
|
|
36
|
+
"@mastra/mcp": "^0.10.10-alpha.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@hono/node-server": "^1.17.1",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"@wong2/mcp-cli": "^1.10.0",
|
|
44
44
|
"cross-env": "^7.0.3",
|
|
45
45
|
"eslint": "^9.30.1",
|
|
46
|
-
"hono": "^4.8.
|
|
46
|
+
"hono": "^4.8.11",
|
|
47
47
|
"tsup": "^8.5.0",
|
|
48
48
|
"tsx": "^4.19.4",
|
|
49
49
|
"typescript": "^5.8.3",
|
|
50
50
|
"vitest": "^3.2.4",
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
51
|
+
"@mastra/core": "0.13.0-alpha.2",
|
|
52
|
+
"@internal/lint": "0.0.26"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"prepare-docs": "cross-env PREPARE=true node dist/prepare-docs/prepare.js",
|