@mastra/express 0.0.2-beta.0 → 0.0.2-beta.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/CHANGELOG.md +47 -0
- package/dist/auth-middleware.d.ts +4 -0
- package/dist/auth-middleware.d.ts.map +1 -0
- package/dist/index.cjs +180 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +7 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +181 -32
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,52 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.0.2-beta.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Unified MastraServer API with MCP transport routes ([#10644](https://github.com/mastra-ai/mastra/pull/10644))
|
|
8
|
+
|
|
9
|
+
**Breaking Changes:**
|
|
10
|
+
- Renamed `HonoServerAdapter` to `MastraServer` in `@mastra/hono`
|
|
11
|
+
- Renamed `ExpressServerAdapter` to `MastraServer` in `@mastra/express`
|
|
12
|
+
- Configuration now passed to constructor instead of separate method calls
|
|
13
|
+
- Renamed base class from `ServerAdapter` to `MastraServerBase` in `@mastra/server`
|
|
14
|
+
|
|
15
|
+
**New Features:**
|
|
16
|
+
- Added MCP transport routes (HTTP and SSE) to server adapters
|
|
17
|
+
- MCP endpoints available at `/api/mcp/:serverId/mcp` (HTTP) and `/api/mcp/:serverId/sse` (SSE)
|
|
18
|
+
- Added `express.json()` middleware compatibility for MCP routes
|
|
19
|
+
- Moved authentication helpers from deployer to `@mastra/server/auth`
|
|
20
|
+
|
|
21
|
+
**Testing:**
|
|
22
|
+
- Added shared MCP route and transport test suites in `@internal/server-adapter-test-utils`
|
|
23
|
+
- Added comprehensive MCP endpoint tests for both Hono and Express adapters
|
|
24
|
+
- Added GitHub Actions workflow for server adapter CI testing
|
|
25
|
+
|
|
26
|
+
- Allow direct access to server app handle directly from Mastra instance. ([#10598](https://github.com/mastra-ai/mastra/pull/10598))
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
// Before: HTTP request to localhost
|
|
30
|
+
const response = await fetch(`http://localhost:5000/api/tools`);
|
|
31
|
+
|
|
32
|
+
// After: Direct call via app.fetch()
|
|
33
|
+
const app = mastra.getServerApp<Hono>();
|
|
34
|
+
const response = await app.fetch(new Request('http://internal/api/tools'));
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- Added `mastra.getServerApp<T>()` to access the underlying Hono/Express app
|
|
38
|
+
- Added `mastra.getMastraServer()` and `mastra.setMastraServer()` for adapter access
|
|
39
|
+
- Added `MastraServerBase` class in `@mastra/core/server` for adapter implementations
|
|
40
|
+
- Server adapters now auto-register with Mastra in their constructor
|
|
41
|
+
|
|
42
|
+
- Add stream data redaction to prevent sensitive information leaks in agent stream API responses. ([#10705](https://github.com/mastra-ai/mastra/pull/10705))
|
|
43
|
+
|
|
44
|
+
The `stream` API endpoint now automatically redacts `request` data from stream chunks (`step-start`, `step-finish`, `finish`) which could contain system prompts, tool definitions, and API keys. Redaction is enabled by default and can be disabled for debugging/internal services via `streamOptions.redact`.
|
|
45
|
+
|
|
46
|
+
- Updated dependencies [[`ac0d2f4`](https://github.com/mastra-ai/mastra/commit/ac0d2f4ff8831f72c1c66c2be809706d17f65789), [`1a0d3fc`](https://github.com/mastra-ai/mastra/commit/1a0d3fc811482c9c376cdf79ee615c23bae9b2d6), [`85a628b`](https://github.com/mastra-ai/mastra/commit/85a628b1224a8f64cd82ea7f033774bf22df7a7e), [`c237233`](https://github.com/mastra-ai/mastra/commit/c23723399ccedf7f5744b3f40997b79246bfbe64), [`15f9e21`](https://github.com/mastra-ai/mastra/commit/15f9e216177201ea6e3f6d0bfb063fcc0953444f), [`ff94dea`](https://github.com/mastra-ai/mastra/commit/ff94dea935f4e34545c63bcb6c29804732698809), [`5b2ff46`](https://github.com/mastra-ai/mastra/commit/5b2ff4651df70c146523a7fca773f8eb0a2272f8), [`db41688`](https://github.com/mastra-ai/mastra/commit/db4168806d007417e2e60b4f68656dca4e5f40c9), [`5ca599d`](https://github.com/mastra-ai/mastra/commit/5ca599d0bb59a1595f19f58473fcd67cc71cef58), [`bff1145`](https://github.com/mastra-ai/mastra/commit/bff114556b3cbadad9b2768488708f8ad0e91475), [`5c8ca24`](https://github.com/mastra-ai/mastra/commit/5c8ca247094e0cc2cdbd7137822fb47241f86e77), [`e191844`](https://github.com/mastra-ai/mastra/commit/e1918444ca3f80e82feef1dad506cd4ec6e2875f), [`22553f1`](https://github.com/mastra-ai/mastra/commit/22553f11c63ee5e966a9c034a349822249584691), [`7237163`](https://github.com/mastra-ai/mastra/commit/72371635dbf96a87df4b073cc48fc655afbdce3d), [`2500740`](https://github.com/mastra-ai/mastra/commit/2500740ea23da067d6e50ec71c625ab3ce275e64), [`873ecbb`](https://github.com/mastra-ai/mastra/commit/873ecbb517586aa17d2f1e99283755b3ebb2863f), [`4f9bbe5`](https://github.com/mastra-ai/mastra/commit/4f9bbe5968f42c86f4930b8193de3c3c17e5bd36), [`02e51fe`](https://github.com/mastra-ai/mastra/commit/02e51feddb3d4155cfbcc42624fd0d0970d032c0), [`8f3fa3a`](https://github.com/mastra-ai/mastra/commit/8f3fa3a652bb77da092f913ec51ae46e3a7e27dc), [`cd29ad2`](https://github.com/mastra-ai/mastra/commit/cd29ad23a255534e8191f249593849ed29160886), [`bdf4d8c`](https://github.com/mastra-ai/mastra/commit/bdf4d8cdc656d8a2c21d81834bfa3bfa70f56c16), [`854e3da`](https://github.com/mastra-ai/mastra/commit/854e3dad5daac17a91a20986399d3a51f54bf68b), [`ce18d38`](https://github.com/mastra-ai/mastra/commit/ce18d38678c65870350d123955014a8432075fd9), [`cccf9c8`](https://github.com/mastra-ai/mastra/commit/cccf9c8b2d2dfc1a5e63919395b83d78c89682a0), [`5a9bafc`](https://github.com/mastra-ai/mastra/commit/5a9bafcaaa859898e954456e781a1552dc0ad4f1), [`61a5705`](https://github.com/mastra-ai/mastra/commit/61a570551278b6743e64243b3ce7d73de915ca8a), [`db70a48`](https://github.com/mastra-ai/mastra/commit/db70a48aeeeeb8e5f92007e8ede52c364ce15287), [`f0fdc14`](https://github.com/mastra-ai/mastra/commit/f0fdc14ee233d619266b3d2bbdeea7d25cfc6d13), [`db18bc9`](https://github.com/mastra-ai/mastra/commit/db18bc9c3825e2c1a0ad9a183cc9935f6691bfa1), [`9b37b56`](https://github.com/mastra-ai/mastra/commit/9b37b565e1f2a76c24f728945cc740c2b09be9da), [`41a23c3`](https://github.com/mastra-ai/mastra/commit/41a23c32f9877d71810f37e24930515df2ff7a0f), [`5d171ad`](https://github.com/mastra-ai/mastra/commit/5d171ad9ef340387276b77c2bb3e83e83332d729), [`f03ae60`](https://github.com/mastra-ai/mastra/commit/f03ae60500fe350c9d828621006cdafe1975fdd8), [`d1e74a0`](https://github.com/mastra-ai/mastra/commit/d1e74a0a293866dece31022047f5dbab65a304d0), [`39e7869`](https://github.com/mastra-ai/mastra/commit/39e7869bc7d0ee391077ce291474d8a84eedccff), [`e849603`](https://github.com/mastra-ai/mastra/commit/e849603a596269069f58a438b98449ea2770493d), [`5761926`](https://github.com/mastra-ai/mastra/commit/57619260c4a2cdd598763abbacd90de594c6bc76), [`c900fdd`](https://github.com/mastra-ai/mastra/commit/c900fdd504c41348efdffb205cfe80d48c38fa33), [`604a79f`](https://github.com/mastra-ai/mastra/commit/604a79fecf276e26a54a3fe01bb94e65315d2e0e), [`60e6e0f`](https://github.com/mastra-ai/mastra/commit/60e6e0f2913bbb467c64a0013b50509cf5efeb38), [`887f0b4`](https://github.com/mastra-ai/mastra/commit/887f0b4746cdbd7cb7d6b17ac9f82aeb58037ea5), [`2562143`](https://github.com/mastra-ai/mastra/commit/256214336b4faa78646c9c1776612393790d8784), [`ef11a61`](https://github.com/mastra-ai/mastra/commit/ef11a61920fa0ed08a5b7ceedd192875af119749)]:
|
|
47
|
+
- @mastra/core@1.0.0-beta.6
|
|
48
|
+
- @mastra/server@1.0.0-beta.6
|
|
49
|
+
|
|
3
50
|
## 0.0.2-beta.0
|
|
4
51
|
|
|
5
52
|
### Patch Changes
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
+
export declare const authenticationMiddleware: (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
3
|
+
export declare const authorizationMiddleware: (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
4
|
+
//# sourceMappingURL=auth-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-middleware.d.ts","sourceRoot":"","sources":["../src/auth-middleware.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,eAAO,MAAM,wBAAwB,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,uDAmE7F,CAAC;AAEF,eAAO,MAAM,uBAAuB,GAAU,KAAK,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,uDAkG5F,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,29 +1,128 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var store = require('@mastra/server/a2a/store');
|
|
4
3
|
var serverAdapter = require('@mastra/server/server-adapter');
|
|
4
|
+
var auth = require('@mastra/server/auth');
|
|
5
5
|
|
|
6
6
|
// src/index.ts
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
mastra,
|
|
14
|
-
tools,
|
|
15
|
-
taskStore,
|
|
16
|
-
customRouteAuthConfig,
|
|
17
|
-
playground,
|
|
18
|
-
isDev,
|
|
19
|
-
bodyLimitOptions
|
|
20
|
-
}) {
|
|
21
|
-
super({ mastra, bodyLimitOptions, tools });
|
|
22
|
-
this.taskStore = taskStore || new store.InMemoryTaskStore();
|
|
23
|
-
this.customRouteAuthConfig = customRouteAuthConfig;
|
|
24
|
-
this.playground = playground;
|
|
25
|
-
this.isDev = isDev;
|
|
7
|
+
var authenticationMiddleware = async (req, res, next) => {
|
|
8
|
+
const mastra = res.locals.mastra;
|
|
9
|
+
const authConfig = mastra.getServer()?.auth;
|
|
10
|
+
const customRouteAuthConfig = res.locals.customRouteAuthConfig;
|
|
11
|
+
if (!authConfig) {
|
|
12
|
+
return next();
|
|
26
13
|
}
|
|
14
|
+
const path = req.path;
|
|
15
|
+
const method = req.method;
|
|
16
|
+
const getHeader = (name) => req.headers[name.toLowerCase()];
|
|
17
|
+
if (auth.isDevPlaygroundRequest(path, method, getHeader, authConfig)) {
|
|
18
|
+
return next();
|
|
19
|
+
}
|
|
20
|
+
if (!auth.isProtectedPath(req.path, req.method, authConfig, customRouteAuthConfig)) {
|
|
21
|
+
return next();
|
|
22
|
+
}
|
|
23
|
+
if (auth.canAccessPublicly(req.path, req.method, authConfig)) {
|
|
24
|
+
return next();
|
|
25
|
+
}
|
|
26
|
+
const authHeader = req.headers.authorization;
|
|
27
|
+
let token = authHeader ? authHeader.replace("Bearer ", "") : null;
|
|
28
|
+
if (!token && req.query.apiKey) {
|
|
29
|
+
token = req.query.apiKey || null;
|
|
30
|
+
}
|
|
31
|
+
if (!token) {
|
|
32
|
+
return res.status(401).json({ error: "Authentication required" });
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
let user;
|
|
36
|
+
if (typeof authConfig.authenticateToken === "function") {
|
|
37
|
+
user = await authConfig.authenticateToken(token, req);
|
|
38
|
+
} else {
|
|
39
|
+
throw new Error("No token verification method configured");
|
|
40
|
+
}
|
|
41
|
+
if (!user) {
|
|
42
|
+
return res.status(401).json({ error: "Invalid or expired token" });
|
|
43
|
+
}
|
|
44
|
+
res.locals.requestContext.set("user", user);
|
|
45
|
+
return next();
|
|
46
|
+
} catch (err) {
|
|
47
|
+
console.error(err);
|
|
48
|
+
return res.status(401).json({ error: "Invalid or expired token" });
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
var authorizationMiddleware = async (req, res, next) => {
|
|
52
|
+
const mastra = res.locals.mastra;
|
|
53
|
+
const authConfig = mastra.getServer()?.auth;
|
|
54
|
+
const customRouteAuthConfig = res.locals.customRouteAuthConfig;
|
|
55
|
+
if (!authConfig) {
|
|
56
|
+
return next();
|
|
57
|
+
}
|
|
58
|
+
const path = req.path;
|
|
59
|
+
const method = req.method;
|
|
60
|
+
const getHeader = (name) => req.headers[name.toLowerCase()];
|
|
61
|
+
if (auth.isDevPlaygroundRequest(path, method, getHeader, authConfig)) {
|
|
62
|
+
return next();
|
|
63
|
+
}
|
|
64
|
+
if (!auth.isProtectedPath(req.path, req.method, authConfig, customRouteAuthConfig)) {
|
|
65
|
+
return next();
|
|
66
|
+
}
|
|
67
|
+
if (auth.canAccessPublicly(path, method, authConfig)) {
|
|
68
|
+
return next();
|
|
69
|
+
}
|
|
70
|
+
const user = res.locals.requestContext.get("user");
|
|
71
|
+
if ("authorizeUser" in authConfig && typeof authConfig.authorizeUser === "function") {
|
|
72
|
+
try {
|
|
73
|
+
const isAuthorized = await authConfig.authorizeUser(user, req);
|
|
74
|
+
if (isAuthorized) {
|
|
75
|
+
return next();
|
|
76
|
+
}
|
|
77
|
+
return res.status(403).json({ error: "Access denied" });
|
|
78
|
+
} catch (err) {
|
|
79
|
+
console.error(err);
|
|
80
|
+
return res.status(500).json({ error: "Authorization error" });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if ("authorize" in authConfig && typeof authConfig.authorize === "function") {
|
|
84
|
+
try {
|
|
85
|
+
const context = {
|
|
86
|
+
get: (key) => {
|
|
87
|
+
if (key === "mastra") return res.locals.mastra;
|
|
88
|
+
if (key === "requestContext") return res.locals.requestContext;
|
|
89
|
+
if (key === "tools") return res.locals.tools;
|
|
90
|
+
if (key === "taskStore") return res.locals.taskStore;
|
|
91
|
+
if (key === "customRouteAuthConfig") return res.locals.customRouteAuthConfig;
|
|
92
|
+
if (key === "playground") return res.locals.playground;
|
|
93
|
+
if (key === "isDev") return res.locals.isDev;
|
|
94
|
+
return void 0;
|
|
95
|
+
},
|
|
96
|
+
req
|
|
97
|
+
};
|
|
98
|
+
const isAuthorized = await authConfig.authorize(path, method, user, context);
|
|
99
|
+
if (isAuthorized) {
|
|
100
|
+
return next();
|
|
101
|
+
}
|
|
102
|
+
return res.status(403).json({ error: "Access denied" });
|
|
103
|
+
} catch (err) {
|
|
104
|
+
console.error(err);
|
|
105
|
+
return res.status(500).json({ error: "Authorization error" });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if ("rules" in authConfig && authConfig.rules && authConfig.rules.length > 0) {
|
|
109
|
+
const isAuthorized = await auth.checkRules(authConfig.rules, path, method, user);
|
|
110
|
+
if (isAuthorized) {
|
|
111
|
+
return next();
|
|
112
|
+
}
|
|
113
|
+
return res.status(403).json({ error: "Access denied" });
|
|
114
|
+
}
|
|
115
|
+
if (auth.defaultAuthConfig.rules && auth.defaultAuthConfig.rules.length > 0) {
|
|
116
|
+
const isAuthorized = await auth.checkRules(auth.defaultAuthConfig.rules, path, method, user);
|
|
117
|
+
if (isAuthorized) {
|
|
118
|
+
return next();
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return res.status(403).json({ error: "Access denied" });
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// src/index.ts
|
|
125
|
+
var MastraServer = class extends serverAdapter.MastraServer {
|
|
27
126
|
createContextMiddleware() {
|
|
28
127
|
return async (req, res, next) => {
|
|
29
128
|
let bodyRequestContext;
|
|
@@ -57,7 +156,9 @@ var ExpressServerAdapter = class extends serverAdapter.MastraServerAdapter {
|
|
|
57
156
|
res.locals.requestContext = requestContext;
|
|
58
157
|
res.locals.mastra = this.mastra;
|
|
59
158
|
res.locals.tools = this.tools || {};
|
|
60
|
-
|
|
159
|
+
if (this.taskStore) {
|
|
160
|
+
res.locals.taskStore = this.taskStore;
|
|
161
|
+
}
|
|
61
162
|
res.locals.playground = this.playground === true;
|
|
62
163
|
res.locals.isDev = this.isDev === true;
|
|
63
164
|
res.locals.customRouteAuthConfig = this.customRouteAuthConfig;
|
|
@@ -80,12 +181,14 @@ var ExpressServerAdapter = class extends serverAdapter.MastraServerAdapter {
|
|
|
80
181
|
const { done, value } = await reader.read();
|
|
81
182
|
if (done) break;
|
|
82
183
|
if (value) {
|
|
184
|
+
const shouldRedact = this.streamOptions?.redact ?? true;
|
|
185
|
+
const outputValue = shouldRedact ? serverAdapter.redactStreamChunk(value) : value;
|
|
83
186
|
if (streamFormat === "sse") {
|
|
84
|
-
res.write(`data: ${JSON.stringify(
|
|
187
|
+
res.write(`data: ${JSON.stringify(outputValue)}
|
|
85
188
|
|
|
86
189
|
`);
|
|
87
190
|
} else {
|
|
88
|
-
res.write(JSON.stringify(
|
|
191
|
+
res.write(JSON.stringify(outputValue) + "");
|
|
89
192
|
}
|
|
90
193
|
}
|
|
91
194
|
}
|
|
@@ -101,7 +204,7 @@ var ExpressServerAdapter = class extends serverAdapter.MastraServerAdapter {
|
|
|
101
204
|
const body = await request.body;
|
|
102
205
|
return { urlParams, queryParams, body };
|
|
103
206
|
}
|
|
104
|
-
async sendResponse(route, response, result) {
|
|
207
|
+
async sendResponse(route, response, result, request) {
|
|
105
208
|
if (route.responseType === "json") {
|
|
106
209
|
response.json(result);
|
|
107
210
|
} else if (route.responseType === "stream") {
|
|
@@ -124,6 +227,47 @@ var ExpressServerAdapter = class extends serverAdapter.MastraServerAdapter {
|
|
|
124
227
|
} else {
|
|
125
228
|
response.end();
|
|
126
229
|
}
|
|
230
|
+
} else if (route.responseType === "mcp-http") {
|
|
231
|
+
if (!request) {
|
|
232
|
+
response.status(500).json({ error: "Request object required for MCP transport" });
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const { server, httpPath } = result;
|
|
236
|
+
try {
|
|
237
|
+
await server.startHTTP({
|
|
238
|
+
url: new URL(request.url, `http://${request.headers.host}`),
|
|
239
|
+
httpPath,
|
|
240
|
+
req: request,
|
|
241
|
+
res: response
|
|
242
|
+
});
|
|
243
|
+
} catch {
|
|
244
|
+
if (!response.headersSent) {
|
|
245
|
+
response.status(500).json({
|
|
246
|
+
jsonrpc: "2.0",
|
|
247
|
+
error: { code: -32603, message: "Internal server error" },
|
|
248
|
+
id: null
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
} else if (route.responseType === "mcp-sse") {
|
|
253
|
+
if (!request) {
|
|
254
|
+
response.status(500).json({ error: "Request object required for MCP transport" });
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const { server, ssePath, messagePath } = result;
|
|
258
|
+
try {
|
|
259
|
+
await server.startSSE({
|
|
260
|
+
url: new URL(request.url, `http://${request.headers.host}`),
|
|
261
|
+
ssePath,
|
|
262
|
+
messagePath,
|
|
263
|
+
req: request,
|
|
264
|
+
res: response
|
|
265
|
+
});
|
|
266
|
+
} catch {
|
|
267
|
+
if (!response.headersSent) {
|
|
268
|
+
response.status(500).json({ error: "Error handling MCP SSE request" });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
127
271
|
} else {
|
|
128
272
|
response.sendStatus(500);
|
|
129
273
|
}
|
|
@@ -167,7 +311,7 @@ var ExpressServerAdapter = class extends serverAdapter.MastraServerAdapter {
|
|
|
167
311
|
try {
|
|
168
312
|
params.body = await this.parseBody(route, params.body);
|
|
169
313
|
} catch (error) {
|
|
170
|
-
console.error("Error parsing body", error);
|
|
314
|
+
console.error("Error parsing body:", error instanceof Error ? error.message : String(error));
|
|
171
315
|
return res.status(400).json({
|
|
172
316
|
error: "Invalid request body",
|
|
173
317
|
details: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -186,7 +330,7 @@ var ExpressServerAdapter = class extends serverAdapter.MastraServerAdapter {
|
|
|
186
330
|
};
|
|
187
331
|
try {
|
|
188
332
|
const result = await route.handler(handlerParams);
|
|
189
|
-
await this.sendResponse(route, res, result);
|
|
333
|
+
await this.sendResponse(route, res, result, req);
|
|
190
334
|
} catch (error) {
|
|
191
335
|
console.error("Error calling handler", error);
|
|
192
336
|
let status = 500;
|
|
@@ -202,14 +346,19 @@ var ExpressServerAdapter = class extends serverAdapter.MastraServerAdapter {
|
|
|
202
346
|
}
|
|
203
347
|
);
|
|
204
348
|
}
|
|
205
|
-
registerContextMiddleware(
|
|
206
|
-
app.use(this.createContextMiddleware());
|
|
349
|
+
registerContextMiddleware() {
|
|
350
|
+
this.app.use(this.createContextMiddleware());
|
|
207
351
|
}
|
|
208
|
-
|
|
209
|
-
|
|
352
|
+
registerAuthMiddleware() {
|
|
353
|
+
const authConfig = this.mastra.getServer()?.auth;
|
|
354
|
+
if (!authConfig) {
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
this.app.use(authenticationMiddleware);
|
|
358
|
+
this.app.use(authorizationMiddleware);
|
|
210
359
|
}
|
|
211
360
|
};
|
|
212
361
|
|
|
213
|
-
exports.
|
|
362
|
+
exports.MastraServer = MastraServer;
|
|
214
363
|
//# sourceMappingURL=index.cjs.map
|
|
215
364
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["MastraServerAdapter","InMemoryTaskStore"],"mappings":";;;;;;AAwBO,IAAM,oBAAA,GAAN,cAAmCA,iCAAA,CAAoD;AAAA,EACpF,SAAA;AAAA,EACA,qBAAA;AAAA,EACA,UAAA;AAAA,EACA,KAAA;AAAA,EAER,WAAA,CAAY;AAAA,IACV,MAAA;AAAA,IACA,KAAA;AAAA,IACA,SAAA;AAAA,IACA,qBAAA;AAAA,IACA,UAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF,EAQG;AACD,IAAA,KAAA,CAAM,EAAE,MAAA,EAAQ,gBAAA,EAA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MAAM,CAAA;AAAA,QAC5C,SAAS,KAAA,EAAO;AACd,UAAA,OAAA,CAAQ,KAAA,CAAM,yBAAyB,KAAK,CAAA;AAE5C,UAAA,IAAI,MAAA,GAAS,GAAA;AACb,UAAA,IAAI,KAAA,IAAS,OAAO,KAAA,KAAU,QAAA,EAAU;AAEtC,YAAA,IAAI,YAAY,KAAA,EAAO;AACrB,cAAA,MAAA,GAAU,KAAA,CAAc,MAAA;AAAA,YAC1B,CAAA,MAAA,IAGE,SAAA,IAAa,KAAA,IACb,KAAA,CAAM,OAAA,IACN,OAAO,KAAA,CAAM,OAAA,KAAY,QAAA,IACzB,QAAA,IAAY,KAAA,CAAM,OAAA,EAClB;AACA,cAAA,MAAA,GAAU,MAAM,OAAA,CAAgB,MAAA;AAAA,YAClC;AAAA,UACF;AACA,UAAA,GAAA,CAAI,MAAA,CAAO,MAAM,CAAA,CAAE,IAAA,CAAK,EAAE,KAAA,EAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,eAAA,EAAiB,CAAA;AAAA,QAC7F;AAAA,MACF;AAAA,KACF;AAAA,EACF;AAAA,EAEA,0BAA0B,GAAA,EAAwB;AAChD,IAAA,GAAA,CAAI,GAAA,CAAI,IAAA,CAAK,uBAAA,EAAyB,CAAA;AAAA,EACxC;AAAA,EAEA,MAAM,cAAA,CACJ,GAAA,EACA,EAAE,MAAA,EAAQ,aAAY,EACP;AACf,IAAA,MAAM,MAAM,cAAA,CAAe,GAAA,EAAK,EAAE,MAAA,EAAQ,aAAa,CAAA;AAAA,EACzD;AACF","file":"index.cjs","sourcesContent":["import type { Mastra } from '@mastra/core/mastra';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { Tool } from '@mastra/core/tools';\nimport { InMemoryTaskStore } from '@mastra/server/a2a/store';\nimport type { ServerRoute, BodyLimitOptions } from '@mastra/server/server-adapter';\nimport { MastraServerAdapter } from '@mastra/server/server-adapter';\nimport type { Application, NextFunction, Request, Response } from 'express';\n\n// Extend Express types to include Mastra context\ndeclare global {\n namespace Express {\n interface Locals {\n mastra: Mastra;\n requestContext: RequestContext;\n abortSignal: AbortSignal;\n tools: Record<string, Tool>;\n taskStore: InMemoryTaskStore;\n customRouteAuthConfig?: Map<string, boolean>;\n playground?: boolean;\n isDev?: boolean;\n }\n }\n}\n\nexport class ExpressServerAdapter extends MastraServerAdapter<Application, Request, Response> {\n private taskStore: InMemoryTaskStore;\n private customRouteAuthConfig?: Map<string, boolean>;\n private playground?: boolean;\n private isDev?: boolean;\n\n constructor({\n mastra,\n tools,\n taskStore,\n customRouteAuthConfig,\n playground,\n isDev,\n bodyLimitOptions,\n }: {\n mastra: Mastra;\n tools?: Record<string, Tool>;\n taskStore?: InMemoryTaskStore;\n customRouteAuthConfig?: Map<string, boolean>;\n playground?: boolean;\n isDev?: boolean;\n bodyLimitOptions?: BodyLimitOptions;\n }) {\n super({ mastra, bodyLimitOptions, tools });\n this.taskStore = taskStore || new InMemoryTaskStore();\n this.customRouteAuthConfig = customRouteAuthConfig;\n this.playground = playground;\n this.isDev = isDev;\n }\n\n createContextMiddleware(): (req: Request, res: Response, next: NextFunction) => Promise<void> {\n return async (req: Request, res: Response, next: NextFunction) => {\n // Parse request context from request body and add to context\n let bodyRequestContext: Record<string, any> | undefined;\n let paramsRequestContext: Record<string, any> | undefined;\n\n // Parse request context from request body (POST/PUT)\n if (req.method === 'POST' || req.method === 'PUT') {\n const contentType = req.headers['content-type'];\n if (contentType?.includes('application/json') && req.body) {\n if (req.body.requestContext) {\n bodyRequestContext = req.body.requestContext;\n }\n }\n }\n\n // Parse request context from query params (GET)\n if (req.method === 'GET') {\n try {\n const encodedRequestContext = req.query.requestContext;\n if (typeof encodedRequestContext === 'string') {\n // Try JSON first\n try {\n paramsRequestContext = JSON.parse(encodedRequestContext);\n } catch {\n // Fallback to base64(JSON)\n try {\n const json = Buffer.from(encodedRequestContext, 'base64').toString('utf-8');\n paramsRequestContext = JSON.parse(json);\n } catch {\n // ignore if still invalid\n }\n }\n }\n } catch {\n // ignore query parsing errors\n }\n }\n\n const requestContext = this.mergeRequestContext({ paramsRequestContext, bodyRequestContext });\n\n // Set context in res.locals\n res.locals.requestContext = requestContext;\n res.locals.mastra = this.mastra;\n res.locals.tools = this.tools || {};\n res.locals.taskStore = this.taskStore;\n res.locals.playground = this.playground === true;\n res.locals.isDev = this.isDev === true;\n res.locals.customRouteAuthConfig = this.customRouteAuthConfig;\n const controller = new AbortController();\n req.on('close', () => {\n controller.abort();\n });\n res.locals.abortSignal = controller.signal;\n next();\n };\n }\n async stream(route: ServerRoute, res: Response, result: { fullStream: ReadableStream }): Promise<void> {\n res.setHeader('Content-Type', 'text/plain');\n res.setHeader('Transfer-Encoding', 'chunked');\n\n const streamFormat = route.streamFormat || 'stream';\n\n const readableStream = result instanceof ReadableStream ? result : result.fullStream;\n const reader = readableStream.getReader();\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n if (value) {\n if (streamFormat === 'sse') {\n res.write(`data: ${JSON.stringify(value)}\\n\\n`);\n } else {\n res.write(JSON.stringify(value) + '\\x1E');\n }\n }\n }\n } catch (error) {\n console.error(error);\n } finally {\n res.end();\n }\n }\n\n async getParams(\n route: ServerRoute,\n request: Request,\n ): Promise<{ urlParams: Record<string, string>; queryParams: Record<string, string>; body: unknown }> {\n const urlParams = request.params;\n const queryParams = request.query;\n const body = await request.body;\n return { urlParams, queryParams: queryParams as Record<string, string>, body };\n }\n\n async sendResponse(route: ServerRoute, response: Response, result: unknown): Promise<void> {\n if (route.responseType === 'json') {\n response.json(result);\n } else if (route.responseType === 'stream') {\n await this.stream(route, response, result as { fullStream: ReadableStream });\n } else if (route.responseType === 'datastream-response') {\n // Handle AI SDK Response objects - pipe Response.body to Express response\n const fetchResponse = result as globalThis.Response;\n fetchResponse.headers.forEach((value, key) => response.setHeader(key, value));\n response.status(fetchResponse.status);\n if (fetchResponse.body) {\n const reader = fetchResponse.body.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n response.write(value);\n }\n } finally {\n response.end();\n }\n } else {\n response.end();\n }\n } else {\n response.sendStatus(500);\n }\n }\n\n async registerRoute(app: Application, route: ServerRoute, { prefix }: { prefix?: string }): Promise<void> {\n // Determine if body limits should be applied\n const shouldApplyBodyLimit = this.bodyLimitOptions && ['POST', 'PUT', 'PATCH'].includes(route.method.toUpperCase());\n\n // Get the body size limit for this route (route-specific or default)\n const maxSize = route.maxBodySize ?? this.bodyLimitOptions?.maxSize;\n\n // Create middleware array\n const middlewares: Array<(req: Request, res: Response, next: NextFunction) => void> = [];\n\n // Add body limit middleware if needed\n if (shouldApplyBodyLimit && maxSize && this.bodyLimitOptions) {\n const bodyLimitMiddleware = (req: Request, res: Response, next: NextFunction) => {\n const contentLength = req.headers['content-length'];\n if (contentLength && parseInt(contentLength, 10) > maxSize) {\n try {\n const errorResponse = this.bodyLimitOptions!.onError({ error: 'Request body too large' });\n return res.status(413).json(errorResponse);\n } catch {\n return res.status(413).json({ error: 'Request body too large' });\n }\n }\n next();\n };\n middlewares.push(bodyLimitMiddleware);\n }\n\n app[route.method.toLowerCase() as keyof Application](\n `${prefix}${route.path}`,\n ...middlewares,\n async (req: Request, res: Response) => {\n const params = await this.getParams(route, req);\n\n if (params.queryParams) {\n try {\n params.queryParams = await this.parseQueryParams(route, params.queryParams as Record<string, string>);\n } catch (error) {\n console.error('Error parsing query params', error);\n // Zod validation errors should return 400 Bad Request, not 500\n return res.status(400).json({\n error: 'Invalid query parameters',\n details: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n\n if (params.body) {\n try {\n params.body = await this.parseBody(route, params.body);\n } catch (error) {\n console.error('Error parsing body', error);\n // Zod validation errors should return 400 Bad Request, not 500\n return res.status(400).json({\n error: 'Invalid request body',\n details: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n\n const handlerParams = {\n ...params.urlParams,\n ...params.queryParams,\n ...(typeof params.body === 'object' ? params.body : {}),\n requestContext: res.locals.requestContext,\n mastra: this.mastra,\n tools: res.locals.tools,\n taskStore: res.locals.taskStore,\n abortSignal: res.locals.abortSignal,\n };\n\n try {\n const result = await route.handler(handlerParams);\n await this.sendResponse(route, res, result);\n } catch (error) {\n console.error('Error calling handler', error);\n // Check if it's an HTTPException or MastraError with a status code\n let status = 500;\n if (error && typeof error === 'object') {\n // Check for direct status property (HTTPException)\n if ('status' in error) {\n status = (error as any).status;\n }\n // Check for MastraError with status in details\n else if (\n 'details' in error &&\n error.details &&\n typeof error.details === 'object' &&\n 'status' in error.details\n ) {\n status = (error.details as any).status;\n }\n }\n res.status(status).json({ error: error instanceof Error ? error.message : 'Unknown error' });\n }\n },\n );\n }\n\n registerContextMiddleware(app: Application): void {\n app.use(this.createContextMiddleware());\n }\n\n async registerRoutes(\n app: Application,\n { prefix, openapiPath }: { prefix?: string; openapiPath?: string },\n ): Promise<void> {\n await super.registerRoutes(app, { prefix, openapiPath });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/auth-middleware.ts","../src/index.ts"],"names":["isDevPlaygroundRequest","isProtectedPath","canAccessPublicly","checkRules","defaultAuthConfig","MastraServerBase","redactStreamChunk"],"mappings":";;;;;;AASO,IAAM,wBAAA,GAA2B,OAAO,GAAA,EAAc,GAAA,EAAe,IAAA,KAAuB;AACjG,EAAA,MAAM,MAAA,GAAS,IAAI,MAAA,CAAO,MAAA;AAC1B,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,SAAA,EAAU,EAAG,IAAA;AACvC,EAAA,MAAM,qBAAA,GAAwB,IAAI,MAAA,CAAO,qBAAA;AAEzC,EAAA,IAAI,CAAC,UAAA,EAAY;AAEf,IAAA,OAAO,IAAA,EAAK;AAAA,EACd;AAEA,EAAA,MAAM,OAAO,GAAA,CAAI,IAAA;AACjB,EAAA,MAAM,SAAS,GAAA,CAAI,MAAA;AACnB,EAAA,MAAM,YAAY,CAAC,IAAA,KAAiB,IAAI,OAAA,CAAQ,IAAA,CAAK,aAAa,CA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KAAA,CAAM,OAAA,GAAU,eAAA,EAAiB,CAAA;AAAA,QAC7F;AAAA,MACF;AAAA,KACF;AAAA,EACF;AAAA,EAEA,yBAAA,GAAkC;AAChC,IAAA,IAAA,CAAK,GAAA,CAAI,GAAA,CAAI,IAAA,CAAK,uBAAA,EAAyB,CAAA;AAAA,EAC7C;AAAA,EAEA,sBAAA,GAA+B;AAC7B,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,MAAA,CAAO,SAAA,EAAU,EAAG,IAAA;AAC5C,IAAA,IAAI,CAAC,UAAA,EAAY;AAEf,MAAA;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,GAAA,CAAI,IAAI,wBAAwB,CAAA;AACrC,IAAA,IAAA,CAAK,GAAA,CAAI,IAAI,uBAAuB,CAAA;AAAA,EACtC;AACF","file":"index.cjs","sourcesContent":["import {\n canAccessPublicly,\n checkRules,\n defaultAuthConfig,\n isDevPlaygroundRequest,\n isProtectedPath,\n} from '@mastra/server/auth';\nimport type { NextFunction, Request, Response } from 'express';\n\nexport const authenticationMiddleware = async (req: Request, res: Response, next: NextFunction) => {\n const mastra = res.locals.mastra;\n const authConfig = mastra.getServer()?.auth;\n const customRouteAuthConfig = res.locals.customRouteAuthConfig;\n\n if (!authConfig) {\n // No auth config, skip authentication\n return next();\n }\n\n const path = req.path;\n const method = req.method;\n const getHeader = (name: string) => req.headers[name.toLowerCase()] as string | undefined;\n\n if (isDevPlaygroundRequest(path, method, getHeader, authConfig)) {\n // Skip authentication for dev playground requests\n return next();\n }\n\n if (!isProtectedPath(req.path, req.method, authConfig, customRouteAuthConfig)) {\n return next();\n }\n\n // Skip authentication for public routes\n if (canAccessPublicly(req.path, req.method, authConfig)) {\n return next();\n }\n\n // Get token from header or query\n const authHeader = req.headers.authorization;\n let token: string | null = authHeader ? authHeader.replace('Bearer ', '') : null;\n\n if (!token && req.query.apiKey) {\n token = (req.query.apiKey as string) || null;\n }\n\n // Handle missing token\n if (!token) {\n return res.status(401).json({ error: 'Authentication required' });\n }\n\n try {\n // Verify token and get user data\n let user: unknown;\n\n // Client provided verify function\n if (typeof authConfig.authenticateToken === 'function') {\n // Note: Express doesn't have HonoRequest, so we pass the Express Request\n // The auth config function signature accepts HonoRequest, but in practice\n // it should work with any request object that has the necessary properties\n user = await authConfig.authenticateToken(token, req as any);\n } else {\n throw new Error('No token verification method configured');\n }\n\n if (!user) {\n return res.status(401).json({ error: 'Invalid or expired token' });\n }\n\n // Store user in context\n res.locals.requestContext.set('user', user);\n\n return next();\n } catch (err) {\n console.error(err);\n return res.status(401).json({ error: 'Invalid or expired token' });\n }\n};\n\nexport const authorizationMiddleware = async (req: Request, res: Response, next: NextFunction) => {\n const mastra = res.locals.mastra;\n const authConfig = mastra.getServer()?.auth;\n const customRouteAuthConfig = res.locals.customRouteAuthConfig;\n\n if (!authConfig) {\n // No auth config, skip authorization\n return next();\n }\n\n const path = req.path;\n const method = req.method;\n const getHeader = (name: string) => req.headers[name.toLowerCase()] as string | undefined;\n\n if (isDevPlaygroundRequest(path, method, getHeader, authConfig)) {\n // Skip authorization for dev playground requests\n return next();\n }\n\n if (!isProtectedPath(req.path, req.method, authConfig, customRouteAuthConfig)) {\n return next();\n }\n\n // Skip for public routes\n if (canAccessPublicly(path, method, authConfig)) {\n return next();\n }\n\n const user = res.locals.requestContext.get('user');\n\n if ('authorizeUser' in authConfig && typeof authConfig.authorizeUser === 'function') {\n try {\n const isAuthorized = await authConfig.authorizeUser(user, req as any);\n\n if (isAuthorized) {\n return next();\n }\n\n return res.status(403).json({ error: 'Access denied' });\n } catch (err) {\n console.error(err);\n return res.status(500).json({ error: 'Authorization error' });\n }\n }\n\n // Client-provided authorization function\n if ('authorize' in authConfig && typeof authConfig.authorize === 'function') {\n try {\n // Note: The authorize function signature expects ContextWithMastra as 4th param\n // For Express, we pass a compatible object with similar structure\n const context = {\n get: (key: string) => {\n if (key === 'mastra') return res.locals.mastra;\n if (key === 'requestContext') return res.locals.requestContext;\n if (key === 'tools') return res.locals.tools;\n if (key === 'taskStore') return res.locals.taskStore;\n if (key === 'customRouteAuthConfig') return res.locals.customRouteAuthConfig;\n if (key === 'playground') return res.locals.playground;\n if (key === 'isDev') return res.locals.isDev;\n return undefined;\n },\n req: req as any,\n } as any;\n\n const isAuthorized = await authConfig.authorize(path, method, user, context);\n\n if (isAuthorized) {\n return next();\n }\n\n return res.status(403).json({ error: 'Access denied' });\n } catch (err) {\n console.error(err);\n return res.status(500).json({ error: 'Authorization error' });\n }\n }\n\n // Custom rule-based authorization\n if ('rules' in authConfig && authConfig.rules && authConfig.rules.length > 0) {\n const isAuthorized = await checkRules(authConfig.rules, path, method, user);\n\n if (isAuthorized) {\n return next();\n }\n\n return res.status(403).json({ error: 'Access denied' });\n }\n\n // Default rule-based authorization\n if (defaultAuthConfig.rules && defaultAuthConfig.rules.length > 0) {\n const isAuthorized = await checkRules(defaultAuthConfig.rules, path, method, user);\n\n if (isAuthorized) {\n return next();\n }\n }\n\n return res.status(403).json({ error: 'Access denied' });\n};\n","import type { Mastra } from '@mastra/core/mastra';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { Tool } from '@mastra/core/tools';\nimport type { InMemoryTaskStore } from '@mastra/server/a2a/store';\nimport type { MCPHttpTransportResult, MCPSseTransportResult } from '@mastra/server/handlers/mcp';\nimport type { ServerRoute } from '@mastra/server/server-adapter';\nimport { MastraServer as MastraServerBase, redactStreamChunk } from '@mastra/server/server-adapter';\nimport type { Application, NextFunction, Request, Response } from 'express';\n\nimport { authenticationMiddleware, authorizationMiddleware } from './auth-middleware';\n\n// Extend Express types to include Mastra context\ndeclare global {\n namespace Express {\n interface Locals {\n mastra: Mastra;\n requestContext: RequestContext;\n abortSignal: AbortSignal;\n tools: Record<string, Tool>;\n taskStore: InMemoryTaskStore;\n customRouteAuthConfig?: Map<string, boolean>;\n playground?: boolean;\n isDev?: boolean;\n }\n }\n}\n\nexport class MastraServer extends MastraServerBase<Application, Request, Response> {\n createContextMiddleware(): (req: Request, res: Response, next: NextFunction) => Promise<void> {\n return async (req: Request, res: Response, next: NextFunction) => {\n // Parse request context from request body and add to context\n let bodyRequestContext: Record<string, any> | undefined;\n let paramsRequestContext: Record<string, any> | undefined;\n\n // Parse request context from request body (POST/PUT)\n if (req.method === 'POST' || req.method === 'PUT') {\n const contentType = req.headers['content-type'];\n if (contentType?.includes('application/json') && req.body) {\n if (req.body.requestContext) {\n bodyRequestContext = req.body.requestContext;\n }\n }\n }\n\n // Parse request context from query params (GET)\n if (req.method === 'GET') {\n try {\n const encodedRequestContext = req.query.requestContext;\n if (typeof encodedRequestContext === 'string') {\n // Try JSON first\n try {\n paramsRequestContext = JSON.parse(encodedRequestContext);\n } catch {\n // Fallback to base64(JSON)\n try {\n const json = Buffer.from(encodedRequestContext, 'base64').toString('utf-8');\n paramsRequestContext = JSON.parse(json);\n } catch {\n // ignore if still invalid\n }\n }\n }\n } catch {\n // ignore query parsing errors\n }\n }\n\n const requestContext = this.mergeRequestContext({ paramsRequestContext, bodyRequestContext });\n\n // Set context in res.locals\n res.locals.requestContext = requestContext;\n res.locals.mastra = this.mastra;\n res.locals.tools = this.tools || {};\n if (this.taskStore) {\n res.locals.taskStore = this.taskStore;\n }\n res.locals.playground = this.playground === true;\n res.locals.isDev = this.isDev === true;\n res.locals.customRouteAuthConfig = this.customRouteAuthConfig;\n const controller = new AbortController();\n req.on('close', () => {\n controller.abort();\n });\n res.locals.abortSignal = controller.signal;\n next();\n };\n }\n async stream(route: ServerRoute, res: Response, result: { fullStream: ReadableStream }): Promise<void> {\n res.setHeader('Content-Type', 'text/plain');\n res.setHeader('Transfer-Encoding', 'chunked');\n\n const streamFormat = route.streamFormat || 'stream';\n\n const readableStream = result instanceof ReadableStream ? result : result.fullStream;\n const reader = readableStream.getReader();\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n if (value) {\n // Optionally redact sensitive data (system prompts, tool definitions, API keys) before sending to the client\n const shouldRedact = this.streamOptions?.redact ?? true;\n const outputValue = shouldRedact ? redactStreamChunk(value) : value;\n if (streamFormat === 'sse') {\n res.write(`data: ${JSON.stringify(outputValue)}\\n\\n`);\n } else {\n res.write(JSON.stringify(outputValue) + '\\x1E');\n }\n }\n }\n } catch (error) {\n console.error(error);\n } finally {\n res.end();\n }\n }\n\n async getParams(\n route: ServerRoute,\n request: Request,\n ): Promise<{ urlParams: Record<string, string>; queryParams: Record<string, string>; body: unknown }> {\n const urlParams = request.params;\n const queryParams = request.query;\n const body = await request.body;\n return { urlParams, queryParams: queryParams as Record<string, string>, body };\n }\n\n async sendResponse(route: ServerRoute, response: Response, result: unknown, request?: Request): Promise<void> {\n if (route.responseType === 'json') {\n response.json(result);\n } else if (route.responseType === 'stream') {\n await this.stream(route, response, result as { fullStream: ReadableStream });\n } else if (route.responseType === 'datastream-response') {\n // Handle AI SDK Response objects - pipe Response.body to Express response\n const fetchResponse = result as globalThis.Response;\n fetchResponse.headers.forEach((value, key) => response.setHeader(key, value));\n response.status(fetchResponse.status);\n if (fetchResponse.body) {\n const reader = fetchResponse.body.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n response.write(value);\n }\n } finally {\n response.end();\n }\n } else {\n response.end();\n }\n } else if (route.responseType === 'mcp-http') {\n // MCP Streamable HTTP transport - request is required\n if (!request) {\n response.status(500).json({ error: 'Request object required for MCP transport' });\n return;\n }\n\n const { server, httpPath } = result as MCPHttpTransportResult;\n\n try {\n await server.startHTTP({\n url: new URL(request.url, `http://${request.headers.host}`),\n httpPath,\n req: request,\n res: response,\n });\n // Response handled by startHTTP\n } catch {\n if (!response.headersSent) {\n response.status(500).json({\n jsonrpc: '2.0',\n error: { code: -32603, message: 'Internal server error' },\n id: null,\n });\n }\n }\n } else if (route.responseType === 'mcp-sse') {\n // MCP SSE transport - request is required\n if (!request) {\n response.status(500).json({ error: 'Request object required for MCP transport' });\n return;\n }\n\n const { server, ssePath, messagePath } = result as MCPSseTransportResult;\n\n try {\n await server.startSSE({\n url: new URL(request.url, `http://${request.headers.host}`),\n ssePath,\n messagePath,\n req: request,\n res: response,\n });\n // Response handled by startSSE\n } catch {\n if (!response.headersSent) {\n response.status(500).json({ error: 'Error handling MCP SSE request' });\n }\n }\n } else {\n response.sendStatus(500);\n }\n }\n\n async registerRoute(app: Application, route: ServerRoute, { prefix }: { prefix?: string }): Promise<void> {\n // Determine if body limits should be applied\n const shouldApplyBodyLimit = this.bodyLimitOptions && ['POST', 'PUT', 'PATCH'].includes(route.method.toUpperCase());\n\n // Get the body size limit for this route (route-specific or default)\n const maxSize = route.maxBodySize ?? this.bodyLimitOptions?.maxSize;\n\n // Create middleware array\n const middlewares: Array<(req: Request, res: Response, next: NextFunction) => void> = [];\n\n // Add body limit middleware if needed\n if (shouldApplyBodyLimit && maxSize && this.bodyLimitOptions) {\n const bodyLimitMiddleware = (req: Request, res: Response, next: NextFunction) => {\n const contentLength = req.headers['content-length'];\n if (contentLength && parseInt(contentLength, 10) > maxSize) {\n try {\n const errorResponse = this.bodyLimitOptions!.onError({ error: 'Request body too large' });\n return res.status(413).json(errorResponse);\n } catch {\n return res.status(413).json({ error: 'Request body too large' });\n }\n }\n next();\n };\n middlewares.push(bodyLimitMiddleware);\n }\n\n app[route.method.toLowerCase() as keyof Application](\n `${prefix}${route.path}`,\n ...middlewares,\n async (req: Request, res: Response) => {\n const params = await this.getParams(route, req);\n\n if (params.queryParams) {\n try {\n params.queryParams = await this.parseQueryParams(route, params.queryParams as Record<string, string>);\n } catch (error) {\n console.error('Error parsing query params', error);\n // Zod validation errors should return 400 Bad Request, not 500\n return res.status(400).json({\n error: 'Invalid query parameters',\n details: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n\n if (params.body) {\n try {\n params.body = await this.parseBody(route, params.body);\n } catch (error) {\n console.error('Error parsing body:', error instanceof Error ? error.message : String(error));\n // Zod validation errors should return 400 Bad Request, not 500\n return res.status(400).json({\n error: 'Invalid request body',\n details: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n\n const handlerParams = {\n ...params.urlParams,\n ...params.queryParams,\n ...(typeof params.body === 'object' ? params.body : {}),\n requestContext: res.locals.requestContext,\n mastra: this.mastra,\n tools: res.locals.tools,\n taskStore: res.locals.taskStore,\n abortSignal: res.locals.abortSignal,\n };\n\n try {\n const result = await route.handler(handlerParams);\n await this.sendResponse(route, res, result, req);\n } catch (error) {\n console.error('Error calling handler', error);\n // Check if it's an HTTPException or MastraError with a status code\n let status = 500;\n if (error && typeof error === 'object') {\n // Check for direct status property (HTTPException)\n if ('status' in error) {\n status = (error as any).status;\n }\n // Check for MastraError with status in details\n else if (\n 'details' in error &&\n error.details &&\n typeof error.details === 'object' &&\n 'status' in error.details\n ) {\n status = (error.details as any).status;\n }\n }\n res.status(status).json({ error: error instanceof Error ? error.message : 'Unknown error' });\n }\n },\n );\n }\n\n registerContextMiddleware(): void {\n this.app.use(this.createContextMiddleware());\n }\n\n registerAuthMiddleware(): void {\n const authConfig = this.mastra.getServer()?.auth;\n if (!authConfig) {\n // No auth config, skip registration\n return;\n }\n\n this.app.use(authenticationMiddleware);\n this.app.use(authorizationMiddleware);\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Mastra } from '@mastra/core/mastra';
|
|
2
2
|
import type { RequestContext } from '@mastra/core/request-context';
|
|
3
3
|
import type { Tool } from '@mastra/core/tools';
|
|
4
|
-
import { InMemoryTaskStore } from '@mastra/server/a2a/store';
|
|
5
|
-
import type { ServerRoute
|
|
6
|
-
import {
|
|
4
|
+
import type { InMemoryTaskStore } from '@mastra/server/a2a/store';
|
|
5
|
+
import type { ServerRoute } from '@mastra/server/server-adapter';
|
|
6
|
+
import { MastraServer as MastraServerBase } from '@mastra/server/server-adapter';
|
|
7
7
|
import type { Application, NextFunction, Request, Response } from 'express';
|
|
8
8
|
declare global {
|
|
9
9
|
namespace Express {
|
|
@@ -19,20 +19,7 @@ declare global {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
export declare class
|
|
23
|
-
private taskStore;
|
|
24
|
-
private customRouteAuthConfig?;
|
|
25
|
-
private playground?;
|
|
26
|
-
private isDev?;
|
|
27
|
-
constructor({ mastra, tools, taskStore, customRouteAuthConfig, playground, isDev, bodyLimitOptions, }: {
|
|
28
|
-
mastra: Mastra;
|
|
29
|
-
tools?: Record<string, Tool>;
|
|
30
|
-
taskStore?: InMemoryTaskStore;
|
|
31
|
-
customRouteAuthConfig?: Map<string, boolean>;
|
|
32
|
-
playground?: boolean;
|
|
33
|
-
isDev?: boolean;
|
|
34
|
-
bodyLimitOptions?: BodyLimitOptions;
|
|
35
|
-
});
|
|
22
|
+
export declare class MastraServer extends MastraServerBase<Application, Request, Response> {
|
|
36
23
|
createContextMiddleware(): (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
37
24
|
stream(route: ServerRoute, res: Response, result: {
|
|
38
25
|
fullStream: ReadableStream;
|
|
@@ -42,14 +29,11 @@ export declare class ExpressServerAdapter extends MastraServerAdapter<Applicatio
|
|
|
42
29
|
queryParams: Record<string, string>;
|
|
43
30
|
body: unknown;
|
|
44
31
|
}>;
|
|
45
|
-
sendResponse(route: ServerRoute, response: Response, result: unknown): Promise<void>;
|
|
32
|
+
sendResponse(route: ServerRoute, response: Response, result: unknown, request?: Request): Promise<void>;
|
|
46
33
|
registerRoute(app: Application, route: ServerRoute, { prefix }: {
|
|
47
34
|
prefix?: string;
|
|
48
35
|
}): Promise<void>;
|
|
49
|
-
registerContextMiddleware(
|
|
50
|
-
|
|
51
|
-
prefix?: string;
|
|
52
|
-
openapiPath?: string;
|
|
53
|
-
}): Promise<void>;
|
|
36
|
+
registerContextMiddleware(): void;
|
|
37
|
+
registerAuthMiddleware(): void;
|
|
54
38
|
}
|
|
55
39
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","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AE,OAAO,EAAE,QAAQ,CAAC;IAChF,uBAAuB,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC;IA2DvF,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE;QAAE,UAAU,EAAE,cAAc,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAgChG,SAAS,CACb,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC;QAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAAC,IAAI,EAAE,OAAO,CAAA;KAAE,CAAC;IAO/F,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IA8EvG,aAAa,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAkGzG,yBAAyB,IAAI,IAAI;IAIjC,sBAAsB,IAAI,IAAI;CAU/B"}
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,126 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { MastraServer as MastraServer$1, redactStreamChunk } from '@mastra/server/server-adapter';
|
|
2
|
+
import { isDevPlaygroundRequest, isProtectedPath, canAccessPublicly, checkRules, defaultAuthConfig } from '@mastra/server/auth';
|
|
3
3
|
|
|
4
4
|
// src/index.ts
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
mastra,
|
|
12
|
-
tools,
|
|
13
|
-
taskStore,
|
|
14
|
-
customRouteAuthConfig,
|
|
15
|
-
playground,
|
|
16
|
-
isDev,
|
|
17
|
-
bodyLimitOptions
|
|
18
|
-
}) {
|
|
19
|
-
super({ mastra, bodyLimitOptions, tools });
|
|
20
|
-
this.taskStore = taskStore || new InMemoryTaskStore();
|
|
21
|
-
this.customRouteAuthConfig = customRouteAuthConfig;
|
|
22
|
-
this.playground = playground;
|
|
23
|
-
this.isDev = isDev;
|
|
5
|
+
var authenticationMiddleware = async (req, res, next) => {
|
|
6
|
+
const mastra = res.locals.mastra;
|
|
7
|
+
const authConfig = mastra.getServer()?.auth;
|
|
8
|
+
const customRouteAuthConfig = res.locals.customRouteAuthConfig;
|
|
9
|
+
if (!authConfig) {
|
|
10
|
+
return next();
|
|
24
11
|
}
|
|
12
|
+
const path = req.path;
|
|
13
|
+
const method = req.method;
|
|
14
|
+
const getHeader = (name) => req.headers[name.toLowerCase()];
|
|
15
|
+
if (isDevPlaygroundRequest(path, method, getHeader, authConfig)) {
|
|
16
|
+
return next();
|
|
17
|
+
}
|
|
18
|
+
if (!isProtectedPath(req.path, req.method, authConfig, customRouteAuthConfig)) {
|
|
19
|
+
return next();
|
|
20
|
+
}
|
|
21
|
+
if (canAccessPublicly(req.path, req.method, authConfig)) {
|
|
22
|
+
return next();
|
|
23
|
+
}
|
|
24
|
+
const authHeader = req.headers.authorization;
|
|
25
|
+
let token = authHeader ? authHeader.replace("Bearer ", "") : null;
|
|
26
|
+
if (!token && req.query.apiKey) {
|
|
27
|
+
token = req.query.apiKey || null;
|
|
28
|
+
}
|
|
29
|
+
if (!token) {
|
|
30
|
+
return res.status(401).json({ error: "Authentication required" });
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
let user;
|
|
34
|
+
if (typeof authConfig.authenticateToken === "function") {
|
|
35
|
+
user = await authConfig.authenticateToken(token, req);
|
|
36
|
+
} else {
|
|
37
|
+
throw new Error("No token verification method configured");
|
|
38
|
+
}
|
|
39
|
+
if (!user) {
|
|
40
|
+
return res.status(401).json({ error: "Invalid or expired token" });
|
|
41
|
+
}
|
|
42
|
+
res.locals.requestContext.set("user", user);
|
|
43
|
+
return next();
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.error(err);
|
|
46
|
+
return res.status(401).json({ error: "Invalid or expired token" });
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var authorizationMiddleware = async (req, res, next) => {
|
|
50
|
+
const mastra = res.locals.mastra;
|
|
51
|
+
const authConfig = mastra.getServer()?.auth;
|
|
52
|
+
const customRouteAuthConfig = res.locals.customRouteAuthConfig;
|
|
53
|
+
if (!authConfig) {
|
|
54
|
+
return next();
|
|
55
|
+
}
|
|
56
|
+
const path = req.path;
|
|
57
|
+
const method = req.method;
|
|
58
|
+
const getHeader = (name) => req.headers[name.toLowerCase()];
|
|
59
|
+
if (isDevPlaygroundRequest(path, method, getHeader, authConfig)) {
|
|
60
|
+
return next();
|
|
61
|
+
}
|
|
62
|
+
if (!isProtectedPath(req.path, req.method, authConfig, customRouteAuthConfig)) {
|
|
63
|
+
return next();
|
|
64
|
+
}
|
|
65
|
+
if (canAccessPublicly(path, method, authConfig)) {
|
|
66
|
+
return next();
|
|
67
|
+
}
|
|
68
|
+
const user = res.locals.requestContext.get("user");
|
|
69
|
+
if ("authorizeUser" in authConfig && typeof authConfig.authorizeUser === "function") {
|
|
70
|
+
try {
|
|
71
|
+
const isAuthorized = await authConfig.authorizeUser(user, req);
|
|
72
|
+
if (isAuthorized) {
|
|
73
|
+
return next();
|
|
74
|
+
}
|
|
75
|
+
return res.status(403).json({ error: "Access denied" });
|
|
76
|
+
} catch (err) {
|
|
77
|
+
console.error(err);
|
|
78
|
+
return res.status(500).json({ error: "Authorization error" });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if ("authorize" in authConfig && typeof authConfig.authorize === "function") {
|
|
82
|
+
try {
|
|
83
|
+
const context = {
|
|
84
|
+
get: (key) => {
|
|
85
|
+
if (key === "mastra") return res.locals.mastra;
|
|
86
|
+
if (key === "requestContext") return res.locals.requestContext;
|
|
87
|
+
if (key === "tools") return res.locals.tools;
|
|
88
|
+
if (key === "taskStore") return res.locals.taskStore;
|
|
89
|
+
if (key === "customRouteAuthConfig") return res.locals.customRouteAuthConfig;
|
|
90
|
+
if (key === "playground") return res.locals.playground;
|
|
91
|
+
if (key === "isDev") return res.locals.isDev;
|
|
92
|
+
return void 0;
|
|
93
|
+
},
|
|
94
|
+
req
|
|
95
|
+
};
|
|
96
|
+
const isAuthorized = await authConfig.authorize(path, method, user, context);
|
|
97
|
+
if (isAuthorized) {
|
|
98
|
+
return next();
|
|
99
|
+
}
|
|
100
|
+
return res.status(403).json({ error: "Access denied" });
|
|
101
|
+
} catch (err) {
|
|
102
|
+
console.error(err);
|
|
103
|
+
return res.status(500).json({ error: "Authorization error" });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if ("rules" in authConfig && authConfig.rules && authConfig.rules.length > 0) {
|
|
107
|
+
const isAuthorized = await checkRules(authConfig.rules, path, method, user);
|
|
108
|
+
if (isAuthorized) {
|
|
109
|
+
return next();
|
|
110
|
+
}
|
|
111
|
+
return res.status(403).json({ error: "Access denied" });
|
|
112
|
+
}
|
|
113
|
+
if (defaultAuthConfig.rules && defaultAuthConfig.rules.length > 0) {
|
|
114
|
+
const isAuthorized = await checkRules(defaultAuthConfig.rules, path, method, user);
|
|
115
|
+
if (isAuthorized) {
|
|
116
|
+
return next();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return res.status(403).json({ error: "Access denied" });
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// src/index.ts
|
|
123
|
+
var MastraServer = class extends MastraServer$1 {
|
|
25
124
|
createContextMiddleware() {
|
|
26
125
|
return async (req, res, next) => {
|
|
27
126
|
let bodyRequestContext;
|
|
@@ -55,7 +154,9 @@ var ExpressServerAdapter = class extends MastraServerAdapter {
|
|
|
55
154
|
res.locals.requestContext = requestContext;
|
|
56
155
|
res.locals.mastra = this.mastra;
|
|
57
156
|
res.locals.tools = this.tools || {};
|
|
58
|
-
|
|
157
|
+
if (this.taskStore) {
|
|
158
|
+
res.locals.taskStore = this.taskStore;
|
|
159
|
+
}
|
|
59
160
|
res.locals.playground = this.playground === true;
|
|
60
161
|
res.locals.isDev = this.isDev === true;
|
|
61
162
|
res.locals.customRouteAuthConfig = this.customRouteAuthConfig;
|
|
@@ -78,12 +179,14 @@ var ExpressServerAdapter = class extends MastraServerAdapter {
|
|
|
78
179
|
const { done, value } = await reader.read();
|
|
79
180
|
if (done) break;
|
|
80
181
|
if (value) {
|
|
182
|
+
const shouldRedact = this.streamOptions?.redact ?? true;
|
|
183
|
+
const outputValue = shouldRedact ? redactStreamChunk(value) : value;
|
|
81
184
|
if (streamFormat === "sse") {
|
|
82
|
-
res.write(`data: ${JSON.stringify(
|
|
185
|
+
res.write(`data: ${JSON.stringify(outputValue)}
|
|
83
186
|
|
|
84
187
|
`);
|
|
85
188
|
} else {
|
|
86
|
-
res.write(JSON.stringify(
|
|
189
|
+
res.write(JSON.stringify(outputValue) + "");
|
|
87
190
|
}
|
|
88
191
|
}
|
|
89
192
|
}
|
|
@@ -99,7 +202,7 @@ var ExpressServerAdapter = class extends MastraServerAdapter {
|
|
|
99
202
|
const body = await request.body;
|
|
100
203
|
return { urlParams, queryParams, body };
|
|
101
204
|
}
|
|
102
|
-
async sendResponse(route, response, result) {
|
|
205
|
+
async sendResponse(route, response, result, request) {
|
|
103
206
|
if (route.responseType === "json") {
|
|
104
207
|
response.json(result);
|
|
105
208
|
} else if (route.responseType === "stream") {
|
|
@@ -122,6 +225,47 @@ var ExpressServerAdapter = class extends MastraServerAdapter {
|
|
|
122
225
|
} else {
|
|
123
226
|
response.end();
|
|
124
227
|
}
|
|
228
|
+
} else if (route.responseType === "mcp-http") {
|
|
229
|
+
if (!request) {
|
|
230
|
+
response.status(500).json({ error: "Request object required for MCP transport" });
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
const { server, httpPath } = result;
|
|
234
|
+
try {
|
|
235
|
+
await server.startHTTP({
|
|
236
|
+
url: new URL(request.url, `http://${request.headers.host}`),
|
|
237
|
+
httpPath,
|
|
238
|
+
req: request,
|
|
239
|
+
res: response
|
|
240
|
+
});
|
|
241
|
+
} catch {
|
|
242
|
+
if (!response.headersSent) {
|
|
243
|
+
response.status(500).json({
|
|
244
|
+
jsonrpc: "2.0",
|
|
245
|
+
error: { code: -32603, message: "Internal server error" },
|
|
246
|
+
id: null
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
} else if (route.responseType === "mcp-sse") {
|
|
251
|
+
if (!request) {
|
|
252
|
+
response.status(500).json({ error: "Request object required for MCP transport" });
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
const { server, ssePath, messagePath } = result;
|
|
256
|
+
try {
|
|
257
|
+
await server.startSSE({
|
|
258
|
+
url: new URL(request.url, `http://${request.headers.host}`),
|
|
259
|
+
ssePath,
|
|
260
|
+
messagePath,
|
|
261
|
+
req: request,
|
|
262
|
+
res: response
|
|
263
|
+
});
|
|
264
|
+
} catch {
|
|
265
|
+
if (!response.headersSent) {
|
|
266
|
+
response.status(500).json({ error: "Error handling MCP SSE request" });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
125
269
|
} else {
|
|
126
270
|
response.sendStatus(500);
|
|
127
271
|
}
|
|
@@ -165,7 +309,7 @@ var ExpressServerAdapter = class extends MastraServerAdapter {
|
|
|
165
309
|
try {
|
|
166
310
|
params.body = await this.parseBody(route, params.body);
|
|
167
311
|
} catch (error) {
|
|
168
|
-
console.error("Error parsing body", error);
|
|
312
|
+
console.error("Error parsing body:", error instanceof Error ? error.message : String(error));
|
|
169
313
|
return res.status(400).json({
|
|
170
314
|
error: "Invalid request body",
|
|
171
315
|
details: error instanceof Error ? error.message : "Unknown error"
|
|
@@ -184,7 +328,7 @@ var ExpressServerAdapter = class extends MastraServerAdapter {
|
|
|
184
328
|
};
|
|
185
329
|
try {
|
|
186
330
|
const result = await route.handler(handlerParams);
|
|
187
|
-
await this.sendResponse(route, res, result);
|
|
331
|
+
await this.sendResponse(route, res, result, req);
|
|
188
332
|
} catch (error) {
|
|
189
333
|
console.error("Error calling handler", error);
|
|
190
334
|
let status = 500;
|
|
@@ -200,14 +344,19 @@ var ExpressServerAdapter = class extends MastraServerAdapter {
|
|
|
200
344
|
}
|
|
201
345
|
);
|
|
202
346
|
}
|
|
203
|
-
registerContextMiddleware(
|
|
204
|
-
app.use(this.createContextMiddleware());
|
|
347
|
+
registerContextMiddleware() {
|
|
348
|
+
this.app.use(this.createContextMiddleware());
|
|
205
349
|
}
|
|
206
|
-
|
|
207
|
-
|
|
350
|
+
registerAuthMiddleware() {
|
|
351
|
+
const authConfig = this.mastra.getServer()?.auth;
|
|
352
|
+
if (!authConfig) {
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
this.app.use(authenticationMiddleware);
|
|
356
|
+
this.app.use(authorizationMiddleware);
|
|
208
357
|
}
|
|
209
358
|
};
|
|
210
359
|
|
|
211
|
-
export {
|
|
360
|
+
export { MastraServer };
|
|
212
361
|
//# sourceMappingURL=index.js.map
|
|
213
362
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;AAwBO,IAAM,oBAAA,GAAN,cAAmC,mBAAA,CAAoD;AAAA,EACpF,SAAA;AAAA,EACA,qBAAA;AAAA,EACA,UAAA;AAAA,EACA,KAAA;AAAA,EAER,WAAA,CAAY;AAAA,IACV,MAAA;AAAA,IACA,KAAA;AAAA,IACA,SAAA;AAAA,IACA,qBAAA;AAAA,IACA,UAAA;AAAA,IACA,KAAA;AAAA,IACA;AAAA,GACF,EAQG;AACD,IAAA,KAAA,CAAM,EAAE,MAA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,EAAO,GAAA,EAAK,MAAM,CAAA;AAAA,QAC5C,SAAS,KAAA,EAAO;AACd,UAAA,OAAA,CAAQ,KAAA,CAAM,yBAAyB,KAAK,CAAA;AAE5C,UAAA,IAAI,MAAA,GAAS,GAAA;AACb,UAAA,IAAI,KAAA,IAAS,OAAO,KAAA,KAAU,QAAA,EAAU;AAEtC,YAAA,IAAI,YAAY,KAAA,EAAO;AACrB,cAAA,MAAA,GAAU,KAAA,CAAc,MAAA;AAAA,YAC1B,CAAA,MAAA,IAGE,SAAA,IAAa,KAAA,IACb,KAAA,CAAM,OAAA,IACN,OAAO,KAAA,CAAM,OAAA,KAAY,QAAA,IACzB,QAAA,IAAY,KAAA,CAAM,OAAA,EAClB;AACA,cAAA,MAAA,GAAU,MAAM,OAAA,CAAgB,MAAA;AAAA,YAClC;AAAA,UACF;AACA,UAAA,GAAA,CAAI,MAAA,CAAO,MAAM,CAAA,CAAE,IAAA,CAAK,EAAE,KAAA,EAAO,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,eAAA,EAAiB,CAAA;AAAA,QAC7F;AAAA,MACF;AAAA,KACF;AAAA,EACF;AAAA,EAEA,0BAA0B,GAAA,EAAwB;AAChD,IAAA,GAAA,CAAI,GAAA,CAAI,IAAA,CAAK,uBAAA,EAAyB,CAAA;AAAA,EACxC;AAAA,EAEA,MAAM,cAAA,CACJ,GAAA,EACA,EAAE,MAAA,EAAQ,aAAY,EACP;AACf,IAAA,MAAM,MAAM,cAAA,CAAe,GAAA,EAAK,EAAE,MAAA,EAAQ,aAAa,CAAA;AAAA,EACzD;AACF","file":"index.js","sourcesContent":["import type { Mastra } from '@mastra/core/mastra';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { Tool } from '@mastra/core/tools';\nimport { InMemoryTaskStore } from '@mastra/server/a2a/store';\nimport type { ServerRoute, BodyLimitOptions } from '@mastra/server/server-adapter';\nimport { MastraServerAdapter } from '@mastra/server/server-adapter';\nimport type { Application, NextFunction, Request, Response } from 'express';\n\n// Extend Express types to include Mastra context\ndeclare global {\n namespace Express {\n interface Locals {\n mastra: Mastra;\n requestContext: RequestContext;\n abortSignal: AbortSignal;\n tools: Record<string, Tool>;\n taskStore: InMemoryTaskStore;\n customRouteAuthConfig?: Map<string, boolean>;\n playground?: boolean;\n isDev?: boolean;\n }\n }\n}\n\nexport class ExpressServerAdapter extends MastraServerAdapter<Application, Request, Response> {\n private taskStore: InMemoryTaskStore;\n private customRouteAuthConfig?: Map<string, boolean>;\n private playground?: boolean;\n private isDev?: boolean;\n\n constructor({\n mastra,\n tools,\n taskStore,\n customRouteAuthConfig,\n playground,\n isDev,\n bodyLimitOptions,\n }: {\n mastra: Mastra;\n tools?: Record<string, Tool>;\n taskStore?: InMemoryTaskStore;\n customRouteAuthConfig?: Map<string, boolean>;\n playground?: boolean;\n isDev?: boolean;\n bodyLimitOptions?: BodyLimitOptions;\n }) {\n super({ mastra, bodyLimitOptions, tools });\n this.taskStore = taskStore || new InMemoryTaskStore();\n this.customRouteAuthConfig = customRouteAuthConfig;\n this.playground = playground;\n this.isDev = isDev;\n }\n\n createContextMiddleware(): (req: Request, res: Response, next: NextFunction) => Promise<void> {\n return async (req: Request, res: Response, next: NextFunction) => {\n // Parse request context from request body and add to context\n let bodyRequestContext: Record<string, any> | undefined;\n let paramsRequestContext: Record<string, any> | undefined;\n\n // Parse request context from request body (POST/PUT)\n if (req.method === 'POST' || req.method === 'PUT') {\n const contentType = req.headers['content-type'];\n if (contentType?.includes('application/json') && req.body) {\n if (req.body.requestContext) {\n bodyRequestContext = req.body.requestContext;\n }\n }\n }\n\n // Parse request context from query params (GET)\n if (req.method === 'GET') {\n try {\n const encodedRequestContext = req.query.requestContext;\n if (typeof encodedRequestContext === 'string') {\n // Try JSON first\n try {\n paramsRequestContext = JSON.parse(encodedRequestContext);\n } catch {\n // Fallback to base64(JSON)\n try {\n const json = Buffer.from(encodedRequestContext, 'base64').toString('utf-8');\n paramsRequestContext = JSON.parse(json);\n } catch {\n // ignore if still invalid\n }\n }\n }\n } catch {\n // ignore query parsing errors\n }\n }\n\n const requestContext = this.mergeRequestContext({ paramsRequestContext, bodyRequestContext });\n\n // Set context in res.locals\n res.locals.requestContext = requestContext;\n res.locals.mastra = this.mastra;\n res.locals.tools = this.tools || {};\n res.locals.taskStore = this.taskStore;\n res.locals.playground = this.playground === true;\n res.locals.isDev = this.isDev === true;\n res.locals.customRouteAuthConfig = this.customRouteAuthConfig;\n const controller = new AbortController();\n req.on('close', () => {\n controller.abort();\n });\n res.locals.abortSignal = controller.signal;\n next();\n };\n }\n async stream(route: ServerRoute, res: Response, result: { fullStream: ReadableStream }): Promise<void> {\n res.setHeader('Content-Type', 'text/plain');\n res.setHeader('Transfer-Encoding', 'chunked');\n\n const streamFormat = route.streamFormat || 'stream';\n\n const readableStream = result instanceof ReadableStream ? result : result.fullStream;\n const reader = readableStream.getReader();\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n if (value) {\n if (streamFormat === 'sse') {\n res.write(`data: ${JSON.stringify(value)}\\n\\n`);\n } else {\n res.write(JSON.stringify(value) + '\\x1E');\n }\n }\n }\n } catch (error) {\n console.error(error);\n } finally {\n res.end();\n }\n }\n\n async getParams(\n route: ServerRoute,\n request: Request,\n ): Promise<{ urlParams: Record<string, string>; queryParams: Record<string, string>; body: unknown }> {\n const urlParams = request.params;\n const queryParams = request.query;\n const body = await request.body;\n return { urlParams, queryParams: queryParams as Record<string, string>, body };\n }\n\n async sendResponse(route: ServerRoute, response: Response, result: unknown): Promise<void> {\n if (route.responseType === 'json') {\n response.json(result);\n } else if (route.responseType === 'stream') {\n await this.stream(route, response, result as { fullStream: ReadableStream });\n } else if (route.responseType === 'datastream-response') {\n // Handle AI SDK Response objects - pipe Response.body to Express response\n const fetchResponse = result as globalThis.Response;\n fetchResponse.headers.forEach((value, key) => response.setHeader(key, value));\n response.status(fetchResponse.status);\n if (fetchResponse.body) {\n const reader = fetchResponse.body.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n response.write(value);\n }\n } finally {\n response.end();\n }\n } else {\n response.end();\n }\n } else {\n response.sendStatus(500);\n }\n }\n\n async registerRoute(app: Application, route: ServerRoute, { prefix }: { prefix?: string }): Promise<void> {\n // Determine if body limits should be applied\n const shouldApplyBodyLimit = this.bodyLimitOptions && ['POST', 'PUT', 'PATCH'].includes(route.method.toUpperCase());\n\n // Get the body size limit for this route (route-specific or default)\n const maxSize = route.maxBodySize ?? this.bodyLimitOptions?.maxSize;\n\n // Create middleware array\n const middlewares: Array<(req: Request, res: Response, next: NextFunction) => void> = [];\n\n // Add body limit middleware if needed\n if (shouldApplyBodyLimit && maxSize && this.bodyLimitOptions) {\n const bodyLimitMiddleware = (req: Request, res: Response, next: NextFunction) => {\n const contentLength = req.headers['content-length'];\n if (contentLength && parseInt(contentLength, 10) > maxSize) {\n try {\n const errorResponse = this.bodyLimitOptions!.onError({ error: 'Request body too large' });\n return res.status(413).json(errorResponse);\n } catch {\n return res.status(413).json({ error: 'Request body too large' });\n }\n }\n next();\n };\n middlewares.push(bodyLimitMiddleware);\n }\n\n app[route.method.toLowerCase() as keyof Application](\n `${prefix}${route.path}`,\n ...middlewares,\n async (req: Request, res: Response) => {\n const params = await this.getParams(route, req);\n\n if (params.queryParams) {\n try {\n params.queryParams = await this.parseQueryParams(route, params.queryParams as Record<string, string>);\n } catch (error) {\n console.error('Error parsing query params', error);\n // Zod validation errors should return 400 Bad Request, not 500\n return res.status(400).json({\n error: 'Invalid query parameters',\n details: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n\n if (params.body) {\n try {\n params.body = await this.parseBody(route, params.body);\n } catch (error) {\n console.error('Error parsing body', error);\n // Zod validation errors should return 400 Bad Request, not 500\n return res.status(400).json({\n error: 'Invalid request body',\n details: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n\n const handlerParams = {\n ...params.urlParams,\n ...params.queryParams,\n ...(typeof params.body === 'object' ? params.body : {}),\n requestContext: res.locals.requestContext,\n mastra: this.mastra,\n tools: res.locals.tools,\n taskStore: res.locals.taskStore,\n abortSignal: res.locals.abortSignal,\n };\n\n try {\n const result = await route.handler(handlerParams);\n await this.sendResponse(route, res, result);\n } catch (error) {\n console.error('Error calling handler', error);\n // Check if it's an HTTPException or MastraError with a status code\n let status = 500;\n if (error && typeof error === 'object') {\n // Check for direct status property (HTTPException)\n if ('status' in error) {\n status = (error as any).status;\n }\n // Check for MastraError with status in details\n else if (\n 'details' in error &&\n error.details &&\n typeof error.details === 'object' &&\n 'status' in error.details\n ) {\n status = (error.details as any).status;\n }\n }\n res.status(status).json({ error: error instanceof Error ? error.message : 'Unknown error' });\n }\n },\n );\n }\n\n registerContextMiddleware(app: Application): void {\n app.use(this.createContextMiddleware());\n }\n\n async registerRoutes(\n app: Application,\n { prefix, openapiPath }: { prefix?: string; openapiPath?: string },\n ): Promise<void> {\n await super.registerRoutes(app, { prefix, openapiPath });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/auth-middleware.ts","../src/index.ts"],"names":["MastraServerBase"],"mappings":";;;;AASO,IAAM,wBAAA,GAA2B,OAAO,GAAA,EAAc,GAAA,EAAe,IAAA,KAAuB;AACjG,EAAA,MAAM,MAAA,GAAS,IAAI,MAAA,CAAO,MAAA;AAC1B,EAAA,MAAM,UAAA,GAAa,MAAA,CAAO,SAAA,EAAU,EAAG,IAAA;AACvC,EAAA,MAAM,qBAAA,GAAwB,IAAI,MAAA,CAAO,qBAAA;AAEzC,EAAA,IAAI,CAAC,UAAA,EAAY;AAEf,IAAA,OAAO,IAAA,EAAK;AAAA,EACd;AAEA,EAAA,MAAM,OAAO,GAAA,CAAI,IAAA;AACjB,EAAA,MAAM,SAAS,GAAA,CAAI,MAAA;AACnB,EAAA,MAAM,YAAY,CAAC,IAAA,KAAiB,IAAI,OAAA,CAAQ,IAAA,CAAK,aAAa,CAAA;AAElE,EAAA,IAAI,sBAAA,CAAuB,IAAA,EAAM,MA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MACF;AAAA,KACF;AAAA,EACF;AAAA,EAEA,yBAAA,GAAkC;AAChC,IAAA,IAAA,CAAK,GAAA,CAAI,GAAA,CAAI,IAAA,CAAK,uBAAA,EAAyB,CAAA;AAAA,EAC7C;AAAA,EAEA,sBAAA,GAA+B;AAC7B,IAAA,MAAM,UAAA,GAAa,IAAA,CAAK,MAAA,CAAO,SAAA,EAAU,EAAG,IAAA;AAC5C,IAAA,IAAI,CAAC,UAAA,EAAY;AAEf,MAAA;AAAA,IACF;AAEA,IAAA,IAAA,CAAK,GAAA,CAAI,IAAI,wBAAwB,CAAA;AACrC,IAAA,IAAA,CAAK,GAAA,CAAI,IAAI,uBAAuB,CAAA;AAAA,EACtC;AACF","file":"index.js","sourcesContent":["import {\n canAccessPublicly,\n checkRules,\n defaultAuthConfig,\n isDevPlaygroundRequest,\n isProtectedPath,\n} from '@mastra/server/auth';\nimport type { NextFunction, Request, Response } from 'express';\n\nexport const authenticationMiddleware = async (req: Request, res: Response, next: NextFunction) => {\n const mastra = res.locals.mastra;\n const authConfig = mastra.getServer()?.auth;\n const customRouteAuthConfig = res.locals.customRouteAuthConfig;\n\n if (!authConfig) {\n // No auth config, skip authentication\n return next();\n }\n\n const path = req.path;\n const method = req.method;\n const getHeader = (name: string) => req.headers[name.toLowerCase()] as string | undefined;\n\n if (isDevPlaygroundRequest(path, method, getHeader, authConfig)) {\n // Skip authentication for dev playground requests\n return next();\n }\n\n if (!isProtectedPath(req.path, req.method, authConfig, customRouteAuthConfig)) {\n return next();\n }\n\n // Skip authentication for public routes\n if (canAccessPublicly(req.path, req.method, authConfig)) {\n return next();\n }\n\n // Get token from header or query\n const authHeader = req.headers.authorization;\n let token: string | null = authHeader ? authHeader.replace('Bearer ', '') : null;\n\n if (!token && req.query.apiKey) {\n token = (req.query.apiKey as string) || null;\n }\n\n // Handle missing token\n if (!token) {\n return res.status(401).json({ error: 'Authentication required' });\n }\n\n try {\n // Verify token and get user data\n let user: unknown;\n\n // Client provided verify function\n if (typeof authConfig.authenticateToken === 'function') {\n // Note: Express doesn't have HonoRequest, so we pass the Express Request\n // The auth config function signature accepts HonoRequest, but in practice\n // it should work with any request object that has the necessary properties\n user = await authConfig.authenticateToken(token, req as any);\n } else {\n throw new Error('No token verification method configured');\n }\n\n if (!user) {\n return res.status(401).json({ error: 'Invalid or expired token' });\n }\n\n // Store user in context\n res.locals.requestContext.set('user', user);\n\n return next();\n } catch (err) {\n console.error(err);\n return res.status(401).json({ error: 'Invalid or expired token' });\n }\n};\n\nexport const authorizationMiddleware = async (req: Request, res: Response, next: NextFunction) => {\n const mastra = res.locals.mastra;\n const authConfig = mastra.getServer()?.auth;\n const customRouteAuthConfig = res.locals.customRouteAuthConfig;\n\n if (!authConfig) {\n // No auth config, skip authorization\n return next();\n }\n\n const path = req.path;\n const method = req.method;\n const getHeader = (name: string) => req.headers[name.toLowerCase()] as string | undefined;\n\n if (isDevPlaygroundRequest(path, method, getHeader, authConfig)) {\n // Skip authorization for dev playground requests\n return next();\n }\n\n if (!isProtectedPath(req.path, req.method, authConfig, customRouteAuthConfig)) {\n return next();\n }\n\n // Skip for public routes\n if (canAccessPublicly(path, method, authConfig)) {\n return next();\n }\n\n const user = res.locals.requestContext.get('user');\n\n if ('authorizeUser' in authConfig && typeof authConfig.authorizeUser === 'function') {\n try {\n const isAuthorized = await authConfig.authorizeUser(user, req as any);\n\n if (isAuthorized) {\n return next();\n }\n\n return res.status(403).json({ error: 'Access denied' });\n } catch (err) {\n console.error(err);\n return res.status(500).json({ error: 'Authorization error' });\n }\n }\n\n // Client-provided authorization function\n if ('authorize' in authConfig && typeof authConfig.authorize === 'function') {\n try {\n // Note: The authorize function signature expects ContextWithMastra as 4th param\n // For Express, we pass a compatible object with similar structure\n const context = {\n get: (key: string) => {\n if (key === 'mastra') return res.locals.mastra;\n if (key === 'requestContext') return res.locals.requestContext;\n if (key === 'tools') return res.locals.tools;\n if (key === 'taskStore') return res.locals.taskStore;\n if (key === 'customRouteAuthConfig') return res.locals.customRouteAuthConfig;\n if (key === 'playground') return res.locals.playground;\n if (key === 'isDev') return res.locals.isDev;\n return undefined;\n },\n req: req as any,\n } as any;\n\n const isAuthorized = await authConfig.authorize(path, method, user, context);\n\n if (isAuthorized) {\n return next();\n }\n\n return res.status(403).json({ error: 'Access denied' });\n } catch (err) {\n console.error(err);\n return res.status(500).json({ error: 'Authorization error' });\n }\n }\n\n // Custom rule-based authorization\n if ('rules' in authConfig && authConfig.rules && authConfig.rules.length > 0) {\n const isAuthorized = await checkRules(authConfig.rules, path, method, user);\n\n if (isAuthorized) {\n return next();\n }\n\n return res.status(403).json({ error: 'Access denied' });\n }\n\n // Default rule-based authorization\n if (defaultAuthConfig.rules && defaultAuthConfig.rules.length > 0) {\n const isAuthorized = await checkRules(defaultAuthConfig.rules, path, method, user);\n\n if (isAuthorized) {\n return next();\n }\n }\n\n return res.status(403).json({ error: 'Access denied' });\n};\n","import type { Mastra } from '@mastra/core/mastra';\nimport type { RequestContext } from '@mastra/core/request-context';\nimport type { Tool } from '@mastra/core/tools';\nimport type { InMemoryTaskStore } from '@mastra/server/a2a/store';\nimport type { MCPHttpTransportResult, MCPSseTransportResult } from '@mastra/server/handlers/mcp';\nimport type { ServerRoute } from '@mastra/server/server-adapter';\nimport { MastraServer as MastraServerBase, redactStreamChunk } from '@mastra/server/server-adapter';\nimport type { Application, NextFunction, Request, Response } from 'express';\n\nimport { authenticationMiddleware, authorizationMiddleware } from './auth-middleware';\n\n// Extend Express types to include Mastra context\ndeclare global {\n namespace Express {\n interface Locals {\n mastra: Mastra;\n requestContext: RequestContext;\n abortSignal: AbortSignal;\n tools: Record<string, Tool>;\n taskStore: InMemoryTaskStore;\n customRouteAuthConfig?: Map<string, boolean>;\n playground?: boolean;\n isDev?: boolean;\n }\n }\n}\n\nexport class MastraServer extends MastraServerBase<Application, Request, Response> {\n createContextMiddleware(): (req: Request, res: Response, next: NextFunction) => Promise<void> {\n return async (req: Request, res: Response, next: NextFunction) => {\n // Parse request context from request body and add to context\n let bodyRequestContext: Record<string, any> | undefined;\n let paramsRequestContext: Record<string, any> | undefined;\n\n // Parse request context from request body (POST/PUT)\n if (req.method === 'POST' || req.method === 'PUT') {\n const contentType = req.headers['content-type'];\n if (contentType?.includes('application/json') && req.body) {\n if (req.body.requestContext) {\n bodyRequestContext = req.body.requestContext;\n }\n }\n }\n\n // Parse request context from query params (GET)\n if (req.method === 'GET') {\n try {\n const encodedRequestContext = req.query.requestContext;\n if (typeof encodedRequestContext === 'string') {\n // Try JSON first\n try {\n paramsRequestContext = JSON.parse(encodedRequestContext);\n } catch {\n // Fallback to base64(JSON)\n try {\n const json = Buffer.from(encodedRequestContext, 'base64').toString('utf-8');\n paramsRequestContext = JSON.parse(json);\n } catch {\n // ignore if still invalid\n }\n }\n }\n } catch {\n // ignore query parsing errors\n }\n }\n\n const requestContext = this.mergeRequestContext({ paramsRequestContext, bodyRequestContext });\n\n // Set context in res.locals\n res.locals.requestContext = requestContext;\n res.locals.mastra = this.mastra;\n res.locals.tools = this.tools || {};\n if (this.taskStore) {\n res.locals.taskStore = this.taskStore;\n }\n res.locals.playground = this.playground === true;\n res.locals.isDev = this.isDev === true;\n res.locals.customRouteAuthConfig = this.customRouteAuthConfig;\n const controller = new AbortController();\n req.on('close', () => {\n controller.abort();\n });\n res.locals.abortSignal = controller.signal;\n next();\n };\n }\n async stream(route: ServerRoute, res: Response, result: { fullStream: ReadableStream }): Promise<void> {\n res.setHeader('Content-Type', 'text/plain');\n res.setHeader('Transfer-Encoding', 'chunked');\n\n const streamFormat = route.streamFormat || 'stream';\n\n const readableStream = result instanceof ReadableStream ? result : result.fullStream;\n const reader = readableStream.getReader();\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n if (value) {\n // Optionally redact sensitive data (system prompts, tool definitions, API keys) before sending to the client\n const shouldRedact = this.streamOptions?.redact ?? true;\n const outputValue = shouldRedact ? redactStreamChunk(value) : value;\n if (streamFormat === 'sse') {\n res.write(`data: ${JSON.stringify(outputValue)}\\n\\n`);\n } else {\n res.write(JSON.stringify(outputValue) + '\\x1E');\n }\n }\n }\n } catch (error) {\n console.error(error);\n } finally {\n res.end();\n }\n }\n\n async getParams(\n route: ServerRoute,\n request: Request,\n ): Promise<{ urlParams: Record<string, string>; queryParams: Record<string, string>; body: unknown }> {\n const urlParams = request.params;\n const queryParams = request.query;\n const body = await request.body;\n return { urlParams, queryParams: queryParams as Record<string, string>, body };\n }\n\n async sendResponse(route: ServerRoute, response: Response, result: unknown, request?: Request): Promise<void> {\n if (route.responseType === 'json') {\n response.json(result);\n } else if (route.responseType === 'stream') {\n await this.stream(route, response, result as { fullStream: ReadableStream });\n } else if (route.responseType === 'datastream-response') {\n // Handle AI SDK Response objects - pipe Response.body to Express response\n const fetchResponse = result as globalThis.Response;\n fetchResponse.headers.forEach((value, key) => response.setHeader(key, value));\n response.status(fetchResponse.status);\n if (fetchResponse.body) {\n const reader = fetchResponse.body.getReader();\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n response.write(value);\n }\n } finally {\n response.end();\n }\n } else {\n response.end();\n }\n } else if (route.responseType === 'mcp-http') {\n // MCP Streamable HTTP transport - request is required\n if (!request) {\n response.status(500).json({ error: 'Request object required for MCP transport' });\n return;\n }\n\n const { server, httpPath } = result as MCPHttpTransportResult;\n\n try {\n await server.startHTTP({\n url: new URL(request.url, `http://${request.headers.host}`),\n httpPath,\n req: request,\n res: response,\n });\n // Response handled by startHTTP\n } catch {\n if (!response.headersSent) {\n response.status(500).json({\n jsonrpc: '2.0',\n error: { code: -32603, message: 'Internal server error' },\n id: null,\n });\n }\n }\n } else if (route.responseType === 'mcp-sse') {\n // MCP SSE transport - request is required\n if (!request) {\n response.status(500).json({ error: 'Request object required for MCP transport' });\n return;\n }\n\n const { server, ssePath, messagePath } = result as MCPSseTransportResult;\n\n try {\n await server.startSSE({\n url: new URL(request.url, `http://${request.headers.host}`),\n ssePath,\n messagePath,\n req: request,\n res: response,\n });\n // Response handled by startSSE\n } catch {\n if (!response.headersSent) {\n response.status(500).json({ error: 'Error handling MCP SSE request' });\n }\n }\n } else {\n response.sendStatus(500);\n }\n }\n\n async registerRoute(app: Application, route: ServerRoute, { prefix }: { prefix?: string }): Promise<void> {\n // Determine if body limits should be applied\n const shouldApplyBodyLimit = this.bodyLimitOptions && ['POST', 'PUT', 'PATCH'].includes(route.method.toUpperCase());\n\n // Get the body size limit for this route (route-specific or default)\n const maxSize = route.maxBodySize ?? this.bodyLimitOptions?.maxSize;\n\n // Create middleware array\n const middlewares: Array<(req: Request, res: Response, next: NextFunction) => void> = [];\n\n // Add body limit middleware if needed\n if (shouldApplyBodyLimit && maxSize && this.bodyLimitOptions) {\n const bodyLimitMiddleware = (req: Request, res: Response, next: NextFunction) => {\n const contentLength = req.headers['content-length'];\n if (contentLength && parseInt(contentLength, 10) > maxSize) {\n try {\n const errorResponse = this.bodyLimitOptions!.onError({ error: 'Request body too large' });\n return res.status(413).json(errorResponse);\n } catch {\n return res.status(413).json({ error: 'Request body too large' });\n }\n }\n next();\n };\n middlewares.push(bodyLimitMiddleware);\n }\n\n app[route.method.toLowerCase() as keyof Application](\n `${prefix}${route.path}`,\n ...middlewares,\n async (req: Request, res: Response) => {\n const params = await this.getParams(route, req);\n\n if (params.queryParams) {\n try {\n params.queryParams = await this.parseQueryParams(route, params.queryParams as Record<string, string>);\n } catch (error) {\n console.error('Error parsing query params', error);\n // Zod validation errors should return 400 Bad Request, not 500\n return res.status(400).json({\n error: 'Invalid query parameters',\n details: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n\n if (params.body) {\n try {\n params.body = await this.parseBody(route, params.body);\n } catch (error) {\n console.error('Error parsing body:', error instanceof Error ? error.message : String(error));\n // Zod validation errors should return 400 Bad Request, not 500\n return res.status(400).json({\n error: 'Invalid request body',\n details: error instanceof Error ? error.message : 'Unknown error',\n });\n }\n }\n\n const handlerParams = {\n ...params.urlParams,\n ...params.queryParams,\n ...(typeof params.body === 'object' ? params.body : {}),\n requestContext: res.locals.requestContext,\n mastra: this.mastra,\n tools: res.locals.tools,\n taskStore: res.locals.taskStore,\n abortSignal: res.locals.abortSignal,\n };\n\n try {\n const result = await route.handler(handlerParams);\n await this.sendResponse(route, res, result, req);\n } catch (error) {\n console.error('Error calling handler', error);\n // Check if it's an HTTPException or MastraError with a status code\n let status = 500;\n if (error && typeof error === 'object') {\n // Check for direct status property (HTTPException)\n if ('status' in error) {\n status = (error as any).status;\n }\n // Check for MastraError with status in details\n else if (\n 'details' in error &&\n error.details &&\n typeof error.details === 'object' &&\n 'status' in error.details\n ) {\n status = (error.details as any).status;\n }\n }\n res.status(status).json({ error: error instanceof Error ? error.message : 'Unknown error' });\n }\n },\n );\n }\n\n registerContextMiddleware(): void {\n this.app.use(this.createContextMiddleware());\n }\n\n registerAuthMiddleware(): void {\n const authConfig = this.mastra.getServer()?.auth;\n if (!authConfig) {\n // No auth config, skip registration\n return;\n }\n\n this.app.use(authenticationMiddleware);\n this.app.use(authorizationMiddleware);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/express",
|
|
3
|
-
"version": "0.0.2-beta.
|
|
3
|
+
"version": "0.0.2-beta.1",
|
|
4
4
|
"description": "Mastra Express adapter for the server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@mastra/server": "1.0.0-beta.
|
|
23
|
+
"@mastra/server": "1.0.0-beta.6"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/node": "^20.19.0",
|
|
@@ -39,11 +39,11 @@
|
|
|
39
39
|
"@internal/lint": "0.0.53",
|
|
40
40
|
"@internal/server-adapter-test-utils": "0.0.1",
|
|
41
41
|
"@internal/storage-test-utils": "0.0.49",
|
|
42
|
-
"@mastra/core": "1.0.0-beta.
|
|
43
|
-
"@mastra/
|
|
44
|
-
"@mastra/observability": "1.0.0-beta.
|
|
45
|
-
"@mastra/
|
|
46
|
-
"@mastra/
|
|
42
|
+
"@mastra/core": "1.0.0-beta.6",
|
|
43
|
+
"@mastra/libsql": "1.0.0-beta.3",
|
|
44
|
+
"@mastra/observability": "1.0.0-beta.2",
|
|
45
|
+
"@mastra/memory": "1.0.0-beta.3",
|
|
46
|
+
"@mastra/evals": "1.0.0-beta.2",
|
|
47
47
|
"@internal/types-builder": "0.0.28"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|