@mastra/mcp-docs-server 1.1.46-alpha.2 → 1.1.46-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  # Custom model gateways
2
2
 
3
- Custom model gateways allow you to implement private or specialized LLM provider integrations by extending the `MastraModelGateway` base class.
3
+ Custom model gateways allow you to implement private or specialized LLM provider integrations with the `MastraModelGatewayInterface` interface or the `MastraModelGateway` base class.
4
4
 
5
5
  ## Overview
6
6
 
@@ -20,7 +20,43 @@ Create custom gateways to support:
20
20
 
21
21
  ## Creating a Custom Gateway
22
22
 
23
- Extend the `MastraModelGateway` class and implement the required methods:
23
+ Implement `MastraModelGatewayInterface` for a plain object gateway, or extend `MastraModelGateway` when you want base class defaults.
24
+
25
+ ```typescript
26
+ import { type MastraModelGatewayInterface, type ProviderConfig } from '@mastra/core/llm';
27
+ import { createOpenAICompatible } from '@ai-sdk/openai-compatible-v5';
28
+
29
+ const myPrivateGateway: MastraModelGatewayInterface = {
30
+ id: 'private',
31
+ name: 'My Private Gateway',
32
+ async fetchProviders(): Promise<Record<string, ProviderConfig>> {
33
+ return {
34
+ 'my-provider': {
35
+ name: 'My Provider',
36
+ models: ['openai/gpt-5.5'],
37
+ apiKeyEnvVar: 'MY_API_KEY',
38
+ gateway: 'private',
39
+ url: 'https://api.myprovider.com/v1',
40
+ },
41
+ };
42
+ },
43
+ buildUrl() {
44
+ return 'https://api.myprovider.com/v1';
45
+ },
46
+ async getApiKey() {
47
+ return process.env.MY_API_KEY ?? '';
48
+ },
49
+ async resolveLanguageModel({ modelId, providerId, apiKey }) {
50
+ return createOpenAICompatible({
51
+ name: providerId,
52
+ apiKey,
53
+ baseURL: 'https://api.myprovider.com/v1',
54
+ }).chatModel(modelId);
55
+ },
56
+ };
57
+ ```
58
+
59
+ The following example extends the `MastraModelGateway` class:
24
60
 
25
61
  ```typescript
26
62
  import { MastraModelGateway, type ProviderConfig } from '@mastra/core/llm';
@@ -43,7 +79,7 @@ class MyPrivateGateway extends MastraModelGateway {
43
79
  return {
44
80
  'my-provider': {
45
81
  name: 'My Provider',
46
- models: ['model-1', 'model-2', 'model-3'],
82
+ models: ['openai/gpt-5.5', 'anthropic/claude-sonnet-4-6'],
47
83
  apiKeyEnvVar: 'MY_API_KEY',
48
84
  gateway: this.id,
49
85
  url: 'https://api.myprovider.com/v1',
@@ -97,6 +133,20 @@ class MyPrivateGateway extends MastraModelGateway {
97
133
  }
98
134
  ```
99
135
 
136
+ ### Gateway-owned authentication
137
+
138
+ Add `resolveAuth` when the gateway owns credential lookup. Mastra uses this hook before falling back to `getApiKey()`.
139
+
140
+ ```typescript
141
+ const myPrivateGateway: MastraModelGatewayInterface = {
142
+ // ...gateway fields and methods
143
+ async resolveAuth() {
144
+ const apiKey = process.env.MY_API_KEY;
145
+ return apiKey ? { apiKey, source: 'gateway' } : undefined;
146
+ },
147
+ };
148
+ ```
149
+
100
150
  ## Registering Custom Gateways
101
151
 
102
152
  ### During Initialization
@@ -140,7 +190,7 @@ const agent = new Agent({
140
190
  id: 'my-agent',
141
191
  name: 'My Agent',
142
192
  instructions: 'You are a helpful assistant',
143
- model: 'private/my-provider/model-1', // Uses MyPrivateGateway
193
+ model: 'private/my-provider/openai/gpt-5.5', // Uses MyPrivateGateway
144
194
  });
145
195
 
146
196
  mastra.addAgent(agent, 'myAgent');
@@ -150,9 +200,9 @@ When you create an agent or use a model, Mastra's model router automatically sel
150
200
 
151
201
  ### TypeScript Autocomplete
152
202
 
153
- **Automatic Type Generation in Development**
203
+ #### Automatic type generation in development
154
204
 
155
- When running in development mode (`MASTRA_DEV=true`), Mastra automatically generates TypeScript types for your custom gateways!
205
+ When running in development mode (`MASTRA_DEV=true`), Mastra automatically generates TypeScript types for your custom gateways.
156
206
 
157
207
  1. **Set the environment variable**:
158
208
 
@@ -185,7 +235,7 @@ When running in development mode (`MASTRA_DEV=true`), Mastra automatically gener
185
235
  });
186
236
  ```
187
237
 
188
- **How It Works**
238
+ #### How it works
189
239
 
190
240
  The GatewayRegistry runs an hourly sync that:
191
241
 
@@ -2,6 +2,8 @@
2
2
 
3
3
  Abstract base class for implementing custom model gateways. Gateways handle provider-specific logic for accessing language models, including provider configuration, authentication, URL construction, and model instantiation.
4
4
 
5
+ Use `MastraModelGatewayInterface` when you want to provide a plain object gateway instead of extending the base class.
6
+
5
7
  ## Class overview
6
8
 
7
9
  ```typescript
@@ -17,7 +19,7 @@ class MyCustomGateway extends MastraModelGateway {
17
19
  return {
18
20
  'my-provider': {
19
21
  name: 'My Provider',
20
- models: ['model-1', 'model-2'],
22
+ models: ['openai/gpt-5.5', 'anthropic/claude-sonnet-4-6'],
21
23
  apiKeyEnvVar: 'MY_API_KEY',
22
24
  gateway: this.id,
23
25
  },
@@ -107,6 +109,18 @@ Retrieves the API key for authentication.
107
109
 
108
110
  **Returns:** `Promise<string>`
109
111
 
112
+ ### `resolveAuth()`
113
+
114
+ Resolves credentials before Mastra creates the language model. Implement this optional hook when a gateway owns authentication. If omitted, Mastra falls back to `getApiKey()`.
115
+
116
+ **Parameters:**
117
+
118
+ **request** (`GatewayAuthRequest`): Incoming request context containing gatewayId, providerId, modelId, and routerId for the gateway to inspect and validate.
119
+
120
+ **Returns:** `GatewayAuthResult | undefined | Promise<GatewayAuthResult | undefined>`
121
+
122
+ A `GatewayAuthResult` may include `apiKey`, `bearerToken`, `headers`, and an optional `source` field to trace where auth came from.
123
+
110
124
  ### `resolveLanguageModel()`
111
125
 
112
126
  Creates a language model instance.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @mastra/mcp-docs-server
2
2
 
3
+ ## 1.1.46-alpha.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`34839c1`](https://github.com/mastra-ai/mastra/commit/34839c1910b6964bf59ed0cee58844efebbb684e), [`053735a`](https://github.com/mastra-ai/mastra/commit/053735a75c2c18e23ce34d9468007efa4a45f4c4), [`34839c1`](https://github.com/mastra-ai/mastra/commit/34839c1910b6964bf59ed0cee58844efebbb684e), [`34839c1`](https://github.com/mastra-ai/mastra/commit/34839c1910b6964bf59ed0cee58844efebbb684e), [`a952852`](https://github.com/mastra-ai/mastra/commit/a952852c971a21fb646cd907c75fcf4443cdc963)]:
8
+ - @mastra/core@1.42.0-alpha.3
9
+
3
10
  ## 1.1.46-alpha.2
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp-docs-server",
3
- "version": "1.1.46-alpha.2",
3
+ "version": "1.1.46-alpha.3",
4
4
  "description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,8 +28,8 @@
28
28
  "jsdom": "^26.1.0",
29
29
  "local-pkg": "^1.1.2",
30
30
  "zod": "^4.4.3",
31
- "@mastra/core": "1.42.0-alpha.2",
32
- "@mastra/mcp": "^1.9.2-alpha.0"
31
+ "@mastra/mcp": "^1.9.2-alpha.0",
32
+ "@mastra/core": "1.42.0-alpha.3"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@hono/node-server": "^1.19.11",
@@ -45,9 +45,9 @@
45
45
  "tsx": "^4.22.4",
46
46
  "typescript": "^6.0.3",
47
47
  "vitest": "4.1.5",
48
- "@internal/types-builder": "0.0.78",
49
48
  "@internal/lint": "0.0.103",
50
- "@mastra/core": "1.42.0-alpha.2"
49
+ "@mastra/core": "1.42.0-alpha.3",
50
+ "@internal/types-builder": "0.0.78"
51
51
  },
52
52
  "homepage": "https://mastra.ai",
53
53
  "repository": {