@mastra/mcp-docs-server 0.13.24-alpha.0 → 0.13.24-alpha.3
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/%40mastra%2Fagent-builder.md +18 -0
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +28 -28
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +32 -32
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +21 -21
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +35 -35
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Flance.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +23 -23
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +44 -44
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Frag.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +37 -37
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +19 -19
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +10 -10
- package/.docs/organized/changelogs/create-mastra.md +18 -18
- package/.docs/organized/changelogs/mastra.md +42 -42
- package/.docs/raw/agents/dynamic-agents.mdx +19 -0
- package/.docs/raw/agents/overview.mdx +46 -0
- package/.docs/raw/auth/auth0.mdx +235 -0
- package/.docs/raw/auth/index.mdx +2 -7
- package/.docs/raw/auth/workos.mdx +198 -0
- package/.docs/raw/getting-started/installation.mdx +1 -1
- package/.docs/raw/memory/conversation-history.mdx +23 -0
- package/.docs/raw/memory/overview.mdx +35 -150
- package/.docs/raw/memory/semantic-recall.mdx +36 -0
- package/.docs/raw/memory/threads-and-resources.mdx +94 -0
- package/.docs/raw/reference/agents/agent.mdx +82 -5
- package/.docs/raw/reference/agents/getInstructions.mdx +2 -2
- package/.docs/raw/reference/auth/auth0.mdx +117 -0
- package/.docs/raw/reference/auth/workos.mdx +128 -0
- package/.docs/raw/reference/memory/Memory.mdx +41 -0
- package/.docs/raw/reference/rag/pg.mdx +28 -1
- package/.docs/raw/reference/workflows/step.mdx +1 -1
- package/CHANGELOG.md +22 -0
- package/package.json +5 -5
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "MastraAuthAuth0 Class"
|
|
3
|
+
description: "Documentation for the MastraAuthAuth0 class, which authenticates Mastra applications using Auth0 authentication."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { Tabs, Tab } from "@/components/tabs";
|
|
7
|
+
|
|
8
|
+
# MastraAuthAuth0 Class
|
|
9
|
+
|
|
10
|
+
The `MastraAuthAuth0` class provides authentication for Mastra using Auth0. It verifies incoming requests using Auth0-issued JWT tokens and integrates with the Mastra server using the `experimental_auth` option.
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
This example uses Auth0 authentication. Make sure to:
|
|
15
|
+
|
|
16
|
+
1. Create an Auth0 account at [auth0.com](https://auth0.com/)
|
|
17
|
+
2. Set up an Application in your Auth0 Dashboard
|
|
18
|
+
3. Configure an API in your Auth0 Dashboard with an identifier (audience)
|
|
19
|
+
4. Configure your application's allowed callback URLs, web origins, and logout URLs
|
|
20
|
+
|
|
21
|
+
```env filename=".env" copy
|
|
22
|
+
AUTH0_DOMAIN=your-tenant.auth0.com
|
|
23
|
+
AUTH0_AUDIENCE=your-api-identifier
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
> **Note:** You can find your domain in the Auth0 Dashboard under Applications > Settings. The audience is the identifier of your API configured in Auth0 Dashboard > APIs.
|
|
27
|
+
|
|
28
|
+
> For detailed setup instructions, refer to the [Auth0 quickstarts](https://auth0.com/docs/quickstarts) for your specific platform.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
Before you can use the `MastraAuthAuth0` class you have to install the `@mastra/auth-auth0` package.
|
|
33
|
+
|
|
34
|
+
```bash copy
|
|
35
|
+
npm install @mastra/auth-auth0@latest
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage examples
|
|
39
|
+
|
|
40
|
+
### Basic usage with environment variables
|
|
41
|
+
|
|
42
|
+
```typescript {2,7} filename="src/mastra/index.ts" showLineNumbers copy
|
|
43
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
44
|
+
import { MastraAuthAuth0 } from '@mastra/auth-auth0';
|
|
45
|
+
|
|
46
|
+
export const mastra = new Mastra({
|
|
47
|
+
// ..
|
|
48
|
+
server: {
|
|
49
|
+
experimental_auth: new MastraAuthAuth0(),
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Custom configuration
|
|
55
|
+
|
|
56
|
+
```typescript {2,7-10} filename="src/mastra/index.ts" showLineNumbers copy
|
|
57
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
58
|
+
import { MastraAuthAuth0 } from '@mastra/auth-auth0';
|
|
59
|
+
|
|
60
|
+
export const mastra = new Mastra({
|
|
61
|
+
// ..
|
|
62
|
+
server: {
|
|
63
|
+
experimental_auth: new MastraAuthAuth0({
|
|
64
|
+
domain: process.env.AUTH0_DOMAIN,
|
|
65
|
+
audience: process.env.AUTH0_AUDIENCE
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Configuration
|
|
72
|
+
|
|
73
|
+
### User Authorization
|
|
74
|
+
|
|
75
|
+
By default, `MastraAuthAuth0` allows all authenticated users who have valid Auth0 tokens for the specified audience. The token verification ensures that:
|
|
76
|
+
|
|
77
|
+
1. The token is properly signed by Auth0
|
|
78
|
+
2. The token is not expired
|
|
79
|
+
3. The token audience matches your configured audience
|
|
80
|
+
4. The token issuer matches your Auth0 domain
|
|
81
|
+
|
|
82
|
+
To customize user authorization, provide a custom `authorizeUser` function:
|
|
83
|
+
|
|
84
|
+
```typescript filename="src/mastra/auth.ts" showLineNumbers copy
|
|
85
|
+
import { MastraAuthAuth0 } from '@mastra/auth-auth0';
|
|
86
|
+
|
|
87
|
+
const auth0Provider = new MastraAuthAuth0({
|
|
88
|
+
authorizeUser: async (user) => {
|
|
89
|
+
// Custom authorization logic
|
|
90
|
+
return user.email?.endsWith('@yourcompany.com') || false;
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
> See the [MastraAuthAuth0](/reference/auth/auth0.mdx) API reference for all available configuration options.
|
|
96
|
+
|
|
97
|
+
## Client-side setup
|
|
98
|
+
|
|
99
|
+
When using Auth0 auth, you'll need to set up the Auth0 React SDK, authenticate users, and retrieve their access tokens to pass to your Mastra requests.
|
|
100
|
+
|
|
101
|
+
### Setting up Auth0 React SDK
|
|
102
|
+
|
|
103
|
+
First, install and configure the Auth0 React SDK in your application:
|
|
104
|
+
|
|
105
|
+
```bash copy
|
|
106
|
+
npm install @auth0/auth0-react
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
```typescript filename="src/auth0-provider.tsx" showLineNumbers copy
|
|
110
|
+
import React from 'react';
|
|
111
|
+
import { Auth0Provider } from '@auth0/auth0-react';
|
|
112
|
+
|
|
113
|
+
const Auth0ProviderWithHistory = ({ children }) => {
|
|
114
|
+
return (
|
|
115
|
+
<Auth0Provider
|
|
116
|
+
domain={process.env.REACT_APP_AUTH0_DOMAIN}
|
|
117
|
+
clientId={process.env.REACT_APP_AUTH0_CLIENT_ID}
|
|
118
|
+
authorizationParams={{
|
|
119
|
+
redirect_uri: window.location.origin,
|
|
120
|
+
audience: process.env.REACT_APP_AUTH0_AUDIENCE,
|
|
121
|
+
scope: "read:current_user update:current_user_metadata"
|
|
122
|
+
}}
|
|
123
|
+
>
|
|
124
|
+
{children}
|
|
125
|
+
</Auth0Provider>
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export default Auth0ProviderWithHistory;
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Retrieving access tokens
|
|
133
|
+
|
|
134
|
+
Use the Auth0 React SDK to authenticate users and retrieve their access tokens:
|
|
135
|
+
|
|
136
|
+
```typescript filename="lib/auth.ts" showLineNumbers copy
|
|
137
|
+
import { useAuth0 } from '@auth0/auth0-react';
|
|
138
|
+
|
|
139
|
+
export const useAuth0Token = () => {
|
|
140
|
+
const { getAccessTokenSilently } = useAuth0();
|
|
141
|
+
|
|
142
|
+
const getAccessToken = async () => {
|
|
143
|
+
const token = await getAccessTokenSilently();
|
|
144
|
+
return token;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
return { getAccessToken };
|
|
148
|
+
};
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
> Refer to the [Auth0 React SDK documentation](https://auth0.com/docs/libraries/auth0-react) for more authentication methods and configuration options.
|
|
152
|
+
|
|
153
|
+
## Configuring `MastraClient`
|
|
154
|
+
|
|
155
|
+
When `experimental_auth` is enabled, all requests made with `MastraClient` must include a valid Auth0 access token in the `Authorization` header:
|
|
156
|
+
|
|
157
|
+
```typescript filename="lib/mastra/mastra-client.ts" showLineNumbers copy
|
|
158
|
+
import { MastraClient } from "@mastra/client-js";
|
|
159
|
+
|
|
160
|
+
export const createMastraClient = (accessToken: string) => {
|
|
161
|
+
return new MastraClient({
|
|
162
|
+
baseUrl: "https://<mastra-api-url>",
|
|
163
|
+
headers: {
|
|
164
|
+
Authorization: `Bearer ${accessToken}`
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
> **Note:** The access token must be prefixed with `Bearer` in the Authorization header.
|
|
171
|
+
|
|
172
|
+
> See [Mastra Client SDK](/docs/server-db/mastra-client.mdx) for more configuration options.
|
|
173
|
+
|
|
174
|
+
### Making authenticated requests
|
|
175
|
+
|
|
176
|
+
Once `MastraClient` is configured with the Auth0 access token, you can send authenticated requests:
|
|
177
|
+
|
|
178
|
+
<Tabs items={["React Component", "curl"]}>
|
|
179
|
+
<Tab>
|
|
180
|
+
```tsx filename="src/components/mastra-api-test.tsx" showLineNumbers copy
|
|
181
|
+
import React, { useState } from 'react';
|
|
182
|
+
import { useAuth0 } from '@auth0/auth0-react';
|
|
183
|
+
import { MastraClient } from '@mastra/client-js';
|
|
184
|
+
|
|
185
|
+
export const MastraApiTest = () => {
|
|
186
|
+
const { getAccessTokenSilently } = useAuth0();
|
|
187
|
+
const [result, setResult] = useState(null);
|
|
188
|
+
|
|
189
|
+
const callMastraApi = async () => {
|
|
190
|
+
const token = await getAccessTokenSilently();
|
|
191
|
+
|
|
192
|
+
const mastra = new MastraClient({
|
|
193
|
+
baseUrl: "http://localhost:4111",
|
|
194
|
+
headers: {
|
|
195
|
+
Authorization: `Bearer ${token}`
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
const weatherAgent = mastra.getAgent("weatherAgent");
|
|
200
|
+
const response = await weatherAgent.generate({
|
|
201
|
+
messages: "What's the weather like in New York"
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
setResult(response.text);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<div>
|
|
209
|
+
<button onClick={callMastraApi}>
|
|
210
|
+
Test Mastra API
|
|
211
|
+
</button>
|
|
212
|
+
|
|
213
|
+
{result && (
|
|
214
|
+
<div className="result">
|
|
215
|
+
<h6>Result:</h6>
|
|
216
|
+
<pre>{result}</pre>
|
|
217
|
+
</div>
|
|
218
|
+
)}
|
|
219
|
+
</div>
|
|
220
|
+
);
|
|
221
|
+
};
|
|
222
|
+
```
|
|
223
|
+
</Tab>
|
|
224
|
+
<Tab>
|
|
225
|
+
```bash copy
|
|
226
|
+
curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
|
|
227
|
+
-H "Content-Type: application/json" \
|
|
228
|
+
-H "Authorization: Bearer <your-auth0-access-token>" \
|
|
229
|
+
-d '{
|
|
230
|
+
"messages": "Weather in London"
|
|
231
|
+
}'
|
|
232
|
+
```
|
|
233
|
+
</Tab>
|
|
234
|
+
</Tabs>
|
|
235
|
+
|
package/.docs/raw/auth/index.mdx
CHANGED
|
@@ -15,10 +15,5 @@ You can start with simple shared secret JWT authentication and switch to provide
|
|
|
15
15
|
- [Clerk](/docs/auth/clerk)
|
|
16
16
|
- [Supabase](/docs/auth/supabase)
|
|
17
17
|
- [Firebase](/docs/auth/firebase)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
The following providers will be available soon:
|
|
22
|
-
|
|
23
|
-
- Auth0
|
|
24
|
-
- WorkOS
|
|
18
|
+
- [WorkOS](/docs/auth/workos)
|
|
19
|
+
- [Auth0](/docs/auth/auth0)
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "MastraAuthWorkos Class"
|
|
3
|
+
description: "Documentation for the MastraAuthWorkos class, which authenticates Mastra applications using WorkOS authentication."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { Tabs, Tab } from "@/components/tabs";
|
|
7
|
+
|
|
8
|
+
# MastraAuthWorkos Class
|
|
9
|
+
|
|
10
|
+
The `MastraAuthWorkos` class provides authentication for Mastra using WorkOS. It verifies incoming requests using WorkOS access tokens and integrates with the Mastra server using the `experimental_auth` option.
|
|
11
|
+
|
|
12
|
+
## Prerequisites
|
|
13
|
+
|
|
14
|
+
This example uses WorkOS authentication. Make sure to:
|
|
15
|
+
|
|
16
|
+
1. Create a WorkOS account at [workos.com](https://workos.com/)
|
|
17
|
+
2. Set up an Application in your WorkOS Dashboard
|
|
18
|
+
3. Configure your redirect URIs and allowed origins
|
|
19
|
+
4. Set up Organizations and configure user roles as needed
|
|
20
|
+
|
|
21
|
+
```env filename=".env" copy
|
|
22
|
+
WORKOS_API_KEY=sk_live_...
|
|
23
|
+
WORKOS_CLIENT_ID=client_...
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
> **Note:** You can find your API key and Client ID in the WorkOS Dashboard under API Keys and Applications respectively.
|
|
27
|
+
|
|
28
|
+
> For detailed setup instructions, refer to the [WorkOS documentation](https://workos.com/docs) for your specific platform.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
Before you can use the `MastraAuthWorkos` class you have to install the `@mastra/auth-workos` package.
|
|
33
|
+
|
|
34
|
+
```bash copy
|
|
35
|
+
npm install @mastra/auth-workos@latest
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage examples
|
|
39
|
+
|
|
40
|
+
### Basic usage with environment variables
|
|
41
|
+
|
|
42
|
+
```typescript {2,7} filename="src/mastra/index.ts" showLineNumbers copy
|
|
43
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
44
|
+
import { MastraAuthWorkos } from '@mastra/auth-workos';
|
|
45
|
+
|
|
46
|
+
export const mastra = new Mastra({
|
|
47
|
+
// ..
|
|
48
|
+
server: {
|
|
49
|
+
experimental_auth: new MastraAuthWorkos(),
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Custom configuration
|
|
55
|
+
|
|
56
|
+
```typescript {2,7-10} filename="src/mastra/index.ts" showLineNumbers copy
|
|
57
|
+
import { Mastra } from "@mastra/core/mastra";
|
|
58
|
+
import { MastraAuthWorkos } from '@mastra/auth-workos';
|
|
59
|
+
|
|
60
|
+
export const mastra = new Mastra({
|
|
61
|
+
// ..
|
|
62
|
+
server: {
|
|
63
|
+
experimental_auth: new MastraAuthWorkos({
|
|
64
|
+
apiKey: process.env.WORKOS_API_KEY,
|
|
65
|
+
clientId: process.env.WORKOS_CLIENT_ID
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Configuration
|
|
72
|
+
|
|
73
|
+
### User Authorization
|
|
74
|
+
|
|
75
|
+
By default, `MastraAuthWorkos` checks whether the authenticated user has an 'admin' role in any of their organization memberships. The authorization process:
|
|
76
|
+
|
|
77
|
+
1. Retrieves the user's organization memberships using their user ID
|
|
78
|
+
2. Extracts all roles from their memberships
|
|
79
|
+
3. Checks if any role has the slug 'admin'
|
|
80
|
+
4. Grants access only if the user has admin role in at least one organization
|
|
81
|
+
|
|
82
|
+
To customize user authorization, provide a custom `authorizeUser` function:
|
|
83
|
+
|
|
84
|
+
```typescript filename="src/mastra/auth.ts" showLineNumbers copy
|
|
85
|
+
import { MastraAuthWorkos } from '@mastra/auth-workos';
|
|
86
|
+
|
|
87
|
+
const workosAuth = new MastraAuthWorkos({
|
|
88
|
+
apiKey: process.env.WORKOS_API_KEY,
|
|
89
|
+
clientId: process.env.WORKOS_CLIENT_ID,
|
|
90
|
+
authorizeUser: async (user) => {
|
|
91
|
+
return !!user;
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
> See the [MastraAuthWorkos](/reference/auth/workos) API reference for all available configuration options.
|
|
97
|
+
|
|
98
|
+
## Client-side setup
|
|
99
|
+
|
|
100
|
+
When using WorkOS auth, you'll need to implement the WorkOS authentication flow to exchange an authorization code for an access token, then use that token with your Mastra requests.
|
|
101
|
+
|
|
102
|
+
### Installing WorkOS SDK
|
|
103
|
+
|
|
104
|
+
First, install the WorkOS SDK in your application:
|
|
105
|
+
|
|
106
|
+
```bash copy
|
|
107
|
+
npm install @workos-inc/node
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Exchanging code for access token
|
|
111
|
+
|
|
112
|
+
After users complete the WorkOS authentication flow and return with an authorization code, exchange it for an access token:
|
|
113
|
+
|
|
114
|
+
```typescript filename="lib/auth.ts" showLineNumbers copy
|
|
115
|
+
import { WorkOS } from '@workos-inc/node';
|
|
116
|
+
|
|
117
|
+
const workos = new WorkOS(process.env.WORKOS_API_KEY);
|
|
118
|
+
|
|
119
|
+
export const authenticateWithWorkos = async (code: string, clientId: string) => {
|
|
120
|
+
const authenticationResponse = await workos.userManagement.authenticateWithCode({
|
|
121
|
+
code,
|
|
122
|
+
clientId,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return authenticationResponse.accessToken;
|
|
126
|
+
};
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
> Refer to the [WorkOS User Management documentation](https://workos.com/docs/authkit/vanilla/nodejs) for more authentication methods and configuration options.
|
|
130
|
+
|
|
131
|
+
## Configuring `MastraClient`
|
|
132
|
+
|
|
133
|
+
When `experimental_auth` is enabled, all requests made with `MastraClient` must include a valid WorkOS access token in the `Authorization` header:
|
|
134
|
+
|
|
135
|
+
```typescript filename="lib/mastra/mastra-client.ts" showLineNumbers copy
|
|
136
|
+
import { MastraClient } from "@mastra/client-js";
|
|
137
|
+
|
|
138
|
+
export const createMastraClient = (accessToken: string) => {
|
|
139
|
+
return new MastraClient({
|
|
140
|
+
baseUrl: "https://<mastra-api-url>",
|
|
141
|
+
headers: {
|
|
142
|
+
Authorization: `Bearer ${accessToken}`
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
> **Note:** The access token must be prefixed with `Bearer` in the Authorization header.
|
|
149
|
+
|
|
150
|
+
> See [Mastra Client SDK](/docs/server-db/mastra-client) for more configuration options.
|
|
151
|
+
|
|
152
|
+
### Making authenticated requests
|
|
153
|
+
|
|
154
|
+
Once `MastraClient` is configured with the WorkOS access token, you can send authenticated requests:
|
|
155
|
+
|
|
156
|
+
<Tabs items={["JavaScript/Node.js", "curl"]}>
|
|
157
|
+
<Tab>
|
|
158
|
+
```typescript filename="src/api/agents.ts" showLineNumbers copy
|
|
159
|
+
import { WorkOS } from '@workos-inc/node';
|
|
160
|
+
import { MastraClient } from '@mastra/client-js';
|
|
161
|
+
|
|
162
|
+
const workos = new WorkOS(process.env.WORKOS_API_KEY);
|
|
163
|
+
|
|
164
|
+
export const callMastraWithWorkos = async (code: string, clientId: string) => {
|
|
165
|
+
const authenticationResponse = await workos.userManagement.authenticateWithCode({
|
|
166
|
+
code,
|
|
167
|
+
clientId,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const token = authenticationResponse.accessToken;
|
|
171
|
+
|
|
172
|
+
const mastra = new MastraClient({
|
|
173
|
+
baseUrl: "http://localhost:4111",
|
|
174
|
+
headers: {
|
|
175
|
+
Authorization: `Bearer ${token}`,
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
const weatherAgent = mastra.getAgent("weatherAgent");
|
|
180
|
+
const response = await weatherAgent.generate({
|
|
181
|
+
messages: "What's the weather like in Nairobi",
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return response.text;
|
|
185
|
+
};
|
|
186
|
+
```
|
|
187
|
+
</Tab>
|
|
188
|
+
<Tab>
|
|
189
|
+
```bash copy
|
|
190
|
+
curl -X POST http://localhost:4111/api/agents/weatherAgent/generate \
|
|
191
|
+
-H "Content-Type: application/json" \
|
|
192
|
+
-H "Authorization: Bearer <your-workos-access-token>" \
|
|
193
|
+
-d '{
|
|
194
|
+
"messages": "Weather in London"
|
|
195
|
+
}'
|
|
196
|
+
```
|
|
197
|
+
</Tab>
|
|
198
|
+
</Tabs>
|
|
@@ -8,7 +8,7 @@ import { Tabs, Tab } from "@/components/tabs";
|
|
|
8
8
|
|
|
9
9
|
# Install Mastra
|
|
10
10
|
|
|
11
|
-
To get started with Mastra, you
|
|
11
|
+
To get started with Mastra, you'll need access to a large language model (LLM). By default, Mastra is set up to work with [OpenAI](https://platform.openai.com/), so you'll need an API key to begin.
|
|
12
12
|
|
|
13
13
|
Mastra also supports other LLM providers. For a full list of supported models and setup instructions, see [Model Providers](/docs/getting-started/model-providers).
|
|
14
14
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Conversation History | Memory | Mastra Docs"
|
|
3
|
+
description: "Learn how to configure conversation history in Mastra to store recent messages from the current conversation."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Conversation History
|
|
7
|
+
|
|
8
|
+
Conversation history is the simplest kind of memory. It is a list of messages from the current conversation.
|
|
9
|
+
|
|
10
|
+
By default, each request includes the last 10 messages from the current memory thread, giving the agent short-term conversational context. This limit can be increased using the `lastMessages` parameter.
|
|
11
|
+
|
|
12
|
+
You can increase this limit by passing the `lastMessages` parameter to the `Memory` instance.
|
|
13
|
+
|
|
14
|
+
```typescript {3-7} showLineNumbers
|
|
15
|
+
export const testAgent = new Agent({
|
|
16
|
+
// ...
|
|
17
|
+
memory: new Memory({
|
|
18
|
+
options: {
|
|
19
|
+
lastMessages: 100
|
|
20
|
+
},
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
```
|