@mastra/mcp 1.0.0-beta.8 → 1.0.0
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 +368 -0
- package/README.md +191 -22
- package/dist/__fixtures__/tools.d.ts +8 -5
- package/dist/__fixtures__/tools.d.ts.map +1 -1
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/oauth-provider.d.ts +230 -0
- package/dist/client/oauth-provider.d.ts.map +1 -0
- package/dist/docs/README.md +1 -1
- package/dist/docs/SKILL.md +14 -2
- package/dist/docs/SOURCE_MAP.json +55 -2
- package/dist/docs/mcp/01-overview.md +24 -14
- package/dist/docs/mcp/02-publishing-mcp-server.md +2 -2
- package/dist/docs/tools/01-reference.md +326 -25
- package/dist/docs/tools-mcp/01-mcp-overview.md +8 -0
- package/dist/index.cjs +459 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +399 -5
- package/dist/index.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/oauth-middleware.d.ts +142 -0
- package/dist/server/oauth-middleware.d.ts.map +1 -0
- package/dist/server/server.d.ts.map +1 -1
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/oauth-types.d.ts +137 -0
- package/dist/shared/oauth-types.d.ts.map +1 -0
- package/package.json +5 -5
package/dist/server/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth Middleware for MCP Server
|
|
3
|
+
*
|
|
4
|
+
* Implements OAuth 2.0 Protected Resource support per RFC 9728 for MCP servers.
|
|
5
|
+
* This allows MCP servers to require OAuth authentication from clients.
|
|
6
|
+
*
|
|
7
|
+
* @see https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization
|
|
8
|
+
* @see https://www.rfc-editor.org/rfc/rfc9728.html
|
|
9
|
+
*/
|
|
10
|
+
import type * as http from 'node:http';
|
|
11
|
+
import type { MCPServerOAuthConfig, TokenValidationResult } from '../shared/oauth-types.js';
|
|
12
|
+
/**
|
|
13
|
+
* Simple logger interface for OAuth middleware.
|
|
14
|
+
*/
|
|
15
|
+
interface OAuthMiddlewareLogger {
|
|
16
|
+
debug?: (message: string, ...args: unknown[]) => void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Options for the OAuth middleware.
|
|
20
|
+
*/
|
|
21
|
+
export interface OAuthMiddlewareOptions {
|
|
22
|
+
/**
|
|
23
|
+
* OAuth configuration for the MCP server.
|
|
24
|
+
*/
|
|
25
|
+
oauth: MCPServerOAuthConfig;
|
|
26
|
+
/**
|
|
27
|
+
* Path where the MCP endpoint is served.
|
|
28
|
+
* @default '/mcp'
|
|
29
|
+
*/
|
|
30
|
+
mcpPath?: string;
|
|
31
|
+
/**
|
|
32
|
+
* Logger instance for debugging.
|
|
33
|
+
*/
|
|
34
|
+
logger?: OAuthMiddlewareLogger;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Result of the middleware check.
|
|
38
|
+
*/
|
|
39
|
+
export interface OAuthMiddlewareResult {
|
|
40
|
+
/**
|
|
41
|
+
* Whether the request should proceed.
|
|
42
|
+
*/
|
|
43
|
+
proceed: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* If false, the response has already been sent.
|
|
46
|
+
*/
|
|
47
|
+
handled: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Token validation result if authentication was attempted.
|
|
50
|
+
*/
|
|
51
|
+
tokenValidation?: TokenValidationResult;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Creates an OAuth middleware function for protecting MCP server endpoints.
|
|
55
|
+
*
|
|
56
|
+
* This middleware:
|
|
57
|
+
* 1. Serves Protected Resource Metadata at `/.well-known/oauth-protected-resource`
|
|
58
|
+
* 2. Validates bearer tokens on protected endpoints
|
|
59
|
+
* 3. Returns proper 401 responses with WWW-Authenticate headers
|
|
60
|
+
*
|
|
61
|
+
* @param options - Middleware configuration
|
|
62
|
+
* @returns Middleware function that returns whether request should proceed
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* import http from 'node:http';
|
|
67
|
+
* import { MCPServer, createOAuthMiddleware } from '@mastra/mcp';
|
|
68
|
+
*
|
|
69
|
+
* const server = new MCPServer({ name: 'Protected Server', version: '1.0.0', tools: {} });
|
|
70
|
+
*
|
|
71
|
+
* const oauthMiddleware = createOAuthMiddleware({
|
|
72
|
+
* oauth: {
|
|
73
|
+
* resource: 'https://mcp.example.com/mcp',
|
|
74
|
+
* authorizationServers: ['https://auth.example.com'],
|
|
75
|
+
* validateToken: async (token, resource) => {
|
|
76
|
+
* // Your token validation logic here
|
|
77
|
+
* return { valid: true, scopes: ['mcp:read', 'mcp:write'] };
|
|
78
|
+
* },
|
|
79
|
+
* },
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* const httpServer = http.createServer(async (req, res) => {
|
|
83
|
+
* const url = new URL(req.url || '', 'http://localhost:3000');
|
|
84
|
+
*
|
|
85
|
+
* // Apply OAuth middleware first
|
|
86
|
+
* const result = await oauthMiddleware(req, res, url);
|
|
87
|
+
* if (!result.proceed) return; // Middleware handled the response
|
|
88
|
+
*
|
|
89
|
+
* // Continue to MCP handler
|
|
90
|
+
* await server.startHTTP({ url, httpPath: '/mcp', req, res });
|
|
91
|
+
* });
|
|
92
|
+
*
|
|
93
|
+
* httpServer.listen(3000);
|
|
94
|
+
* ```
|
|
95
|
+
*/
|
|
96
|
+
export declare function createOAuthMiddleware(options: OAuthMiddlewareOptions): (req: http.IncomingMessage, res: http.ServerResponse, url: URL) => Promise<OAuthMiddlewareResult>;
|
|
97
|
+
/**
|
|
98
|
+
* Helper to create a simple token validator that checks against a list of valid tokens.
|
|
99
|
+
*
|
|
100
|
+
* Useful for testing and development. For production, use a proper JWT validator
|
|
101
|
+
* or call your authorization server's introspection endpoint.
|
|
102
|
+
*
|
|
103
|
+
* @param validTokens - Array of valid token strings
|
|
104
|
+
* @returns Token validation function
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const validateToken = createStaticTokenValidator(['secret-token-1', 'secret-token-2']);
|
|
109
|
+
*
|
|
110
|
+
* const middleware = createOAuthMiddleware({
|
|
111
|
+
* oauth: {
|
|
112
|
+
* resource: 'https://mcp.example.com/mcp',
|
|
113
|
+
* authorizationServers: ['https://auth.example.com'],
|
|
114
|
+
* validateToken,
|
|
115
|
+
* },
|
|
116
|
+
* });
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
export declare function createStaticTokenValidator(validTokens: string[]): MCPServerOAuthConfig['validateToken'];
|
|
120
|
+
/**
|
|
121
|
+
* Creates a token validator that calls an introspection endpoint.
|
|
122
|
+
*
|
|
123
|
+
* Per RFC 7662, the introspection endpoint returns token metadata.
|
|
124
|
+
*
|
|
125
|
+
* @param introspectionEndpoint - URL of the token introspection endpoint
|
|
126
|
+
* @param clientCredentials - Optional client credentials for authenticated introspection
|
|
127
|
+
* @returns Token validation function
|
|
128
|
+
*
|
|
129
|
+
* @example
|
|
130
|
+
* ```typescript
|
|
131
|
+
* const validateToken = createIntrospectionValidator(
|
|
132
|
+
* 'https://auth.example.com/oauth/introspect',
|
|
133
|
+
* { clientId: 'mcp-server', clientSecret: 'secret' }
|
|
134
|
+
* );
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export declare function createIntrospectionValidator(introspectionEndpoint: string, clientCredentials?: {
|
|
138
|
+
clientId: string;
|
|
139
|
+
clientSecret: string;
|
|
140
|
+
}): MCPServerOAuthConfig['validateToken'];
|
|
141
|
+
export {};
|
|
142
|
+
//# sourceMappingURL=oauth-middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-middleware.d.ts","sourceRoot":"","sources":["../../src/server/oauth-middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,KAAK,IAAI,MAAM,WAAW,CAAC;AAEvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAO5F;;GAEG;AACH,UAAU,qBAAqB;IAC7B,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACvD;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,KAAK,EAAE,oBAAoB,CAAC;IAE5B;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,MAAM,CAAC,EAAE,qBAAqB,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,eAAe,CAAC,EAAE,qBAAqB,CAAC;CACzC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,IASjE,KAAK,IAAI,CAAC,eAAe,EACzB,KAAK,IAAI,CAAC,cAAc,EACxB,KAAK,GAAG,KACP,OAAO,CAAC,qBAAqB,CAAC,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EACd,IAAI,EAAE,GAAG,EACT,gBAAgB,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,GAC3D,OAAO,CAAC,GAAG,CAAC;CAiFhB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth Types for MCP Authentication
|
|
3
|
+
*
|
|
4
|
+
* Re-exports and extends OAuth types from the MCP SDK for use in Mastra's
|
|
5
|
+
* MCP client and server implementations.
|
|
6
|
+
*
|
|
7
|
+
* @see https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization
|
|
8
|
+
*/
|
|
9
|
+
import type { OAuthProtectedResourceMetadata as SDKOAuthProtectedResourceMetadata } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
10
|
+
export type { OAuthMetadata, OAuthTokens, OAuthErrorResponse, OAuthClientMetadata, OAuthClientInformation, OAuthClientInformationFull, OAuthClientRegistrationError, OAuthTokenRevocationRequest, OAuthProtectedResourceMetadata, AuthorizationServerMetadata, } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
11
|
+
export { auth, discoverOAuthProtectedResourceMetadata, discoverOAuthMetadata, discoverAuthorizationServerMetadata, startAuthorization, exchangeAuthorization, refreshAuthorization, registerClient, extractResourceMetadataUrl, selectResourceURL, parseErrorResponse, UnauthorizedError, buildDiscoveryUrls, } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
12
|
+
export type { OAuthClientProvider, AuthResult } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for OAuth-protected MCP server.
|
|
15
|
+
*
|
|
16
|
+
* Used to configure Protected Resource Metadata (RFC 9728) and
|
|
17
|
+
* token validation for MCP servers that require OAuth authentication.
|
|
18
|
+
*/
|
|
19
|
+
export interface MCPServerOAuthConfig {
|
|
20
|
+
/**
|
|
21
|
+
* The resource identifier URI for this MCP server.
|
|
22
|
+
* This MUST be the canonical URL of the MCP server.
|
|
23
|
+
*
|
|
24
|
+
* @example 'https://mcp.example.com/mcp'
|
|
25
|
+
*/
|
|
26
|
+
resource: string;
|
|
27
|
+
/**
|
|
28
|
+
* URLs of authorization servers that can issue tokens for this resource.
|
|
29
|
+
* At least one authorization server should be specified.
|
|
30
|
+
*
|
|
31
|
+
* @example ['https://auth.example.com']
|
|
32
|
+
*/
|
|
33
|
+
authorizationServers: string[];
|
|
34
|
+
/**
|
|
35
|
+
* Scopes supported by this MCP server.
|
|
36
|
+
*
|
|
37
|
+
* @default ['mcp:read', 'mcp:write']
|
|
38
|
+
*/
|
|
39
|
+
scopesSupported?: string[];
|
|
40
|
+
/**
|
|
41
|
+
* Human-readable name of this resource server.
|
|
42
|
+
*/
|
|
43
|
+
resourceName?: string;
|
|
44
|
+
/**
|
|
45
|
+
* URL to documentation about this resource server.
|
|
46
|
+
*/
|
|
47
|
+
resourceDocumentation?: string;
|
|
48
|
+
/**
|
|
49
|
+
* Custom function to validate access tokens.
|
|
50
|
+
*
|
|
51
|
+
* If not provided, tokens are accepted without validation
|
|
52
|
+
* (useful for testing but NOT recommended for production).
|
|
53
|
+
*
|
|
54
|
+
* @param token - The bearer token from the Authorization header
|
|
55
|
+
* @param resource - The resource URI this server represents
|
|
56
|
+
* @returns Promise resolving to validation result
|
|
57
|
+
*/
|
|
58
|
+
validateToken?: (token: string, resource: string) => Promise<TokenValidationResult>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Result of token validation.
|
|
62
|
+
*/
|
|
63
|
+
export interface TokenValidationResult {
|
|
64
|
+
/**
|
|
65
|
+
* Whether the token is valid.
|
|
66
|
+
*/
|
|
67
|
+
valid: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* If invalid, the reason for rejection.
|
|
70
|
+
*/
|
|
71
|
+
error?: string;
|
|
72
|
+
/**
|
|
73
|
+
* If invalid, a more detailed error description.
|
|
74
|
+
*/
|
|
75
|
+
errorDescription?: string;
|
|
76
|
+
/**
|
|
77
|
+
* The scopes granted by this token.
|
|
78
|
+
*/
|
|
79
|
+
scopes?: string[];
|
|
80
|
+
/**
|
|
81
|
+
* The subject (user) identifier from the token.
|
|
82
|
+
*/
|
|
83
|
+
subject?: string;
|
|
84
|
+
/**
|
|
85
|
+
* When the token expires (Unix timestamp).
|
|
86
|
+
*/
|
|
87
|
+
expiresAt?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Additional claims from the token.
|
|
90
|
+
*/
|
|
91
|
+
claims?: Record<string, unknown>;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Options for OAuth-related HTTP responses.
|
|
95
|
+
*/
|
|
96
|
+
export interface OAuthResponseOptions {
|
|
97
|
+
/**
|
|
98
|
+
* URL to the Protected Resource Metadata endpoint.
|
|
99
|
+
*/
|
|
100
|
+
resourceMetadataUrl?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Additional WWW-Authenticate parameters.
|
|
103
|
+
*/
|
|
104
|
+
additionalParams?: Record<string, string>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Generates a WWW-Authenticate header value for OAuth 401 responses.
|
|
108
|
+
*
|
|
109
|
+
* @param options - Options for generating the header
|
|
110
|
+
* @returns The WWW-Authenticate header value
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const header = generateWWWAuthenticateHeader({
|
|
115
|
+
* resourceMetadataUrl: 'https://mcp.example.com/.well-known/oauth-protected-resource',
|
|
116
|
+
* });
|
|
117
|
+
* // Returns: 'Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource"'
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare function generateWWWAuthenticateHeader(options?: OAuthResponseOptions): string;
|
|
121
|
+
/**
|
|
122
|
+
* Generates Protected Resource Metadata (RFC 9728) JSON response.
|
|
123
|
+
*
|
|
124
|
+
* @param config - OAuth configuration for the MCP server
|
|
125
|
+
* @returns The Protected Resource Metadata object
|
|
126
|
+
*
|
|
127
|
+
* @see https://www.rfc-editor.org/rfc/rfc9728.html
|
|
128
|
+
*/
|
|
129
|
+
export declare function generateProtectedResourceMetadata(config: MCPServerOAuthConfig): SDKOAuthProtectedResourceMetadata;
|
|
130
|
+
/**
|
|
131
|
+
* Extracts the bearer token from an Authorization header.
|
|
132
|
+
*
|
|
133
|
+
* @param authHeader - The Authorization header value
|
|
134
|
+
* @returns The bearer token, or undefined if not present
|
|
135
|
+
*/
|
|
136
|
+
export declare function extractBearerToken(authHeader: string | null | undefined): string | undefined;
|
|
137
|
+
//# sourceMappingURL=oauth-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-types.d.ts","sourceRoot":"","sources":["../../src/shared/oauth-types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,8BAA8B,IAAI,iCAAiC,EAAE,MAAM,0CAA0C,CAAC;AAGpI,YAAY,EACV,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,sBAAsB,EACtB,0BAA0B,EAC1B,4BAA4B,EAC5B,2BAA2B,EAC3B,8BAA8B,EAC9B,2BAA2B,GAC5B,MAAM,0CAA0C,CAAC;AAGlD,OAAO,EACL,IAAI,EACJ,sCAAsC,EACtC,qBAAqB,EACrB,mCAAmC,EACnC,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,0BAA0B,EAC1B,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,0CAA0C,CAAC;AAGlD,YAAY,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEhG;;;;;GAKG;AACH,MAAM,WAA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U,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAU5F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/mcp",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"@modelcontextprotocol/sdk": "^1.17.5",
|
|
31
31
|
"exit-hook": "^5.0.1",
|
|
32
32
|
"fast-deep-equal": "^3.1.3",
|
|
33
|
-
"uuid": "^
|
|
33
|
+
"uuid": "^13.0.0",
|
|
34
34
|
"zod-from-json-schema": "^0.5.0",
|
|
35
35
|
"zod-from-json-schema-v3": "npm:zod-from-json-schema@^0.0.5"
|
|
36
36
|
},
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"vitest": "4.0.16",
|
|
55
55
|
"zod": "^3.25.76",
|
|
56
56
|
"zod-to-json-schema": "^3.24.6",
|
|
57
|
-
"@internal/
|
|
58
|
-
"@mastra/core": "1.0.0
|
|
59
|
-
"@internal/
|
|
57
|
+
"@internal/lint": "0.0.54",
|
|
58
|
+
"@mastra/core": "1.0.0",
|
|
59
|
+
"@internal/types-builder": "0.0.29"
|
|
60
60
|
},
|
|
61
61
|
"homepage": "https://mastra.ai",
|
|
62
62
|
"repository": {
|