@mastra/express 0.0.0-a2a-vnext-20260424123427

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/LICENSE.md ADDED
@@ -0,0 +1,30 @@
1
+ Portions of this software are licensed as follows:
2
+
3
+ - All content that resides under any directory named "ee/" within this
4
+ repository, including but not limited to:
5
+ - `packages/core/src/auth/ee/`
6
+ - `packages/server/src/server/auth/ee/`
7
+ is licensed under the license defined in `ee/LICENSE`.
8
+
9
+ - All third-party components incorporated into the Mastra Software are
10
+ licensed under the original license provided by the owner of the
11
+ applicable component.
12
+
13
+ - Content outside of the above-mentioned directories or restrictions is
14
+ available under the "Apache License 2.0" as defined below.
15
+
16
+ # Apache License 2.0
17
+
18
+ Copyright (c) 2025 Kepler Software, Inc.
19
+
20
+ Licensed under the Apache License, Version 2.0 (the "License");
21
+ you may not use this file except in compliance with the License.
22
+ You may obtain a copy of the License at
23
+
24
+ http://www.apache.org/licenses/LICENSE-2.0
25
+
26
+ Unless required by applicable law or agreed to in writing, software
27
+ distributed under the License is distributed on an "AS IS" BASIS,
28
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29
+ See the License for the specific language governing permissions and
30
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @mastra/express
2
+
3
+ Express server adapter for Mastra, enabling you to run Mastra with the [Express](https://expressjs.com) framework.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/express express
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import express from 'express';
15
+ import { MastraServer } from '@mastra/express';
16
+ import { mastra } from './mastra';
17
+
18
+ const app = express();
19
+ const server = new MastraServer({ app, mastra });
20
+
21
+ await server.init();
22
+
23
+ app.listen(3000, () => {
24
+ console.log('Server running on http://localhost:3000');
25
+ });
26
+ ```
27
+
28
+ ## Adding Custom Routes
29
+
30
+ Add routes directly to the Express app with access to Mastra context:
31
+
32
+ ```typescript
33
+ // Routes added after init() have access to Mastra context
34
+ app.get('/health', (req, res) => {
35
+ const mastraInstance = res.locals.mastra;
36
+ const agents = Object.keys(mastraInstance.listAgents());
37
+ res.json({ status: 'ok', agents });
38
+ });
39
+ ```
40
+
41
+ ## Configuration Options
42
+
43
+ ```typescript
44
+ const server = new MastraServer({
45
+ app,
46
+ mastra,
47
+ prefix: '/api/v2', // Route prefix
48
+ openapiPath: '/openapi.json', // OpenAPI spec endpoint
49
+ bodyLimitOptions: {
50
+ maxSize: 10 * 1024 * 1024, // 10MB
51
+ onError: err => ({ error: 'Payload too large' }),
52
+ },
53
+ streamOptions: { redact: true }, // Redact sensitive data from streams
54
+ });
55
+ ```
56
+
57
+ ## Context Variables
58
+
59
+ Access these in route handlers via `res.locals`:
60
+
61
+ | Key | Description |
62
+ | ---------------- | --------------------------- |
63
+ | `mastra` | Mastra instance |
64
+ | `requestContext` | Request context map |
65
+ | `abortSignal` | Request cancellation signal |
66
+ | `tools` | Available tools |
67
+
68
+ ## Related Links
69
+
70
+ - [Server Adapters Documentation](https://mastra.ai/docs/server/server-adapters)
71
+ - [Express Documentation](https://expressjs.com)
@@ -0,0 +1,8 @@
1
+ import type { Mastra } from '@mastra/core/mastra';
2
+ import type { NextFunction, Request, Response } from 'express';
3
+ export interface ExpressAuthMiddlewareOptions {
4
+ mastra: Mastra;
5
+ requiresAuth?: boolean;
6
+ }
7
+ export declare function createAuthMiddleware({ mastra, requiresAuth, }: ExpressAuthMiddlewareOptions): (req: Request, res: Response, next: NextFunction) => Promise<void>;
8
+ //# 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":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAGlD,OAAO,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE/D,MAAM,WAAW,4BAA4B;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAuBD,wBAAgB,oBAAoB,CAAC,EACnC,MAAM,EACN,YAAmB,GACpB,EAAE,4BAA4B,GAAG,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAgDnG"}