@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/README.md
CHANGED
|
@@ -381,37 +381,204 @@ Prompt notifications are delivered via SSE or compatible transports. Register ha
|
|
|
381
381
|
|
|
382
382
|
## Authentication
|
|
383
383
|
|
|
384
|
-
### OAuth
|
|
384
|
+
### OAuth 2.0 Authentication (MCP Auth Spec)
|
|
385
|
+
|
|
386
|
+
Mastra provides full support for the [MCP OAuth specification](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization), including:
|
|
387
|
+
|
|
388
|
+
- **Server-side**: Protected Resource Metadata (RFC 9728), token validation middleware
|
|
389
|
+
- **Client-side**: OAuth client provider implementation with PKCE, token storage, and automatic refresh
|
|
385
390
|
|
|
386
|
-
|
|
391
|
+
#### Client-Side: Connecting to OAuth-Protected MCP Servers
|
|
392
|
+
|
|
393
|
+
Use `MCPOAuthClientProvider` to connect to MCP servers that require OAuth authentication:
|
|
387
394
|
|
|
388
395
|
```typescript
|
|
389
|
-
|
|
396
|
+
import { MCPClient, MCPOAuthClientProvider } from '@mastra/mcp';
|
|
397
|
+
|
|
398
|
+
// Create an OAuth provider for your client
|
|
399
|
+
const oauthProvider = new MCPOAuthClientProvider({
|
|
400
|
+
redirectUrl: 'http://localhost:3000/oauth/callback',
|
|
401
|
+
clientMetadata: {
|
|
402
|
+
redirect_uris: ['http://localhost:3000/oauth/callback'],
|
|
403
|
+
client_name: 'My MCP Client',
|
|
404
|
+
grant_types: ['authorization_code', 'refresh_token'],
|
|
405
|
+
response_types: ['code'],
|
|
406
|
+
},
|
|
407
|
+
// Handle authorization redirects (for CLI apps, open browser; for web apps, redirect response)
|
|
408
|
+
onRedirectToAuthorization: url => {
|
|
409
|
+
console.log(`Please visit: ${url}`);
|
|
410
|
+
// Or: window.location.href = url.toString();
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// Create client with OAuth provider
|
|
415
|
+
const client = new MCPClient({
|
|
390
416
|
servers: {
|
|
391
|
-
|
|
392
|
-
url: new URL('https://
|
|
393
|
-
authProvider:
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
417
|
+
protectedServer: {
|
|
418
|
+
url: new URL('https://mcp.example.com/mcp'),
|
|
419
|
+
authProvider: oauthProvider,
|
|
420
|
+
},
|
|
421
|
+
},
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
await client.connect();
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
For testing or when you already have a valid token, use `createSimpleTokenProvider`:
|
|
428
|
+
|
|
429
|
+
```typescript
|
|
430
|
+
import { MCPClient, createSimpleTokenProvider } from '@mastra/mcp';
|
|
431
|
+
|
|
432
|
+
const provider = createSimpleTokenProvider('your-access-token', {
|
|
433
|
+
redirectUrl: 'http://localhost:3000/callback',
|
|
434
|
+
clientMetadata: {
|
|
435
|
+
redirect_uris: ['http://localhost:3000/callback'],
|
|
436
|
+
client_name: 'Test Client',
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
const client = new MCPClient({
|
|
441
|
+
servers: {
|
|
442
|
+
testServer: {
|
|
443
|
+
url: new URL('https://mcp.example.com/mcp'),
|
|
444
|
+
authProvider: provider,
|
|
409
445
|
},
|
|
410
446
|
},
|
|
411
447
|
});
|
|
412
448
|
```
|
|
413
449
|
|
|
414
|
-
|
|
450
|
+
#### Server-Side: Protecting Your MCP Server with OAuth
|
|
451
|
+
|
|
452
|
+
Use `createOAuthMiddleware` to protect your MCP server endpoints:
|
|
453
|
+
|
|
454
|
+
```typescript
|
|
455
|
+
import http from 'node:http';
|
|
456
|
+
import { MCPServer, createOAuthMiddleware, createStaticTokenValidator } from '@mastra/mcp';
|
|
457
|
+
|
|
458
|
+
// Create your MCP server
|
|
459
|
+
const mcpServer = new MCPServer({
|
|
460
|
+
id: 'protected-mcp-server',
|
|
461
|
+
name: 'Protected MCP Server',
|
|
462
|
+
version: '1.0.0',
|
|
463
|
+
tools: {
|
|
464
|
+
/* your tools */
|
|
465
|
+
},
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
// Create OAuth middleware
|
|
469
|
+
const oauthMiddleware = createOAuthMiddleware({
|
|
470
|
+
oauth: {
|
|
471
|
+
resource: 'https://mcp.example.com/mcp',
|
|
472
|
+
authorizationServers: ['https://auth.example.com'],
|
|
473
|
+
scopesSupported: ['mcp:read', 'mcp:write'],
|
|
474
|
+
resourceName: 'My Protected MCP Server',
|
|
475
|
+
// For production, use proper token validation (JWT, introspection, etc.)
|
|
476
|
+
validateToken: createStaticTokenValidator(['allowed-token-1', 'allowed-token-2']),
|
|
477
|
+
},
|
|
478
|
+
mcpPath: '/mcp',
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
// Create HTTP server with OAuth protection
|
|
482
|
+
const httpServer = http.createServer(async (req, res) => {
|
|
483
|
+
const url = new URL(req.url || '', 'https://mcp.example.com');
|
|
484
|
+
|
|
485
|
+
// Apply OAuth middleware first
|
|
486
|
+
const result = await oauthMiddleware(req, res, url);
|
|
487
|
+
if (!result.proceed) return; // Middleware handled the response (401, metadata, etc.)
|
|
488
|
+
|
|
489
|
+
// Token is valid, proceed to MCP handler
|
|
490
|
+
await mcpServer.startHTTP({ url, httpPath: '/mcp', req, res });
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
httpServer.listen(3000);
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
The middleware automatically:
|
|
497
|
+
|
|
498
|
+
- Serves Protected Resource Metadata at `/.well-known/oauth-protected-resource`
|
|
499
|
+
- Returns `401 Unauthorized` with proper `WWW-Authenticate` headers when authentication is required
|
|
500
|
+
- Validates bearer tokens using your provided validator
|
|
501
|
+
|
|
502
|
+
#### Token Validation Options
|
|
503
|
+
|
|
504
|
+
For production use, implement proper token validation:
|
|
505
|
+
|
|
506
|
+
```typescript
|
|
507
|
+
import { createOAuthMiddleware, createIntrospectionValidator } from '@mastra/mcp';
|
|
508
|
+
|
|
509
|
+
// Option 1: Token introspection (RFC 7662)
|
|
510
|
+
const middleware = createOAuthMiddleware({
|
|
511
|
+
oauth: {
|
|
512
|
+
resource: 'https://mcp.example.com/mcp',
|
|
513
|
+
authorizationServers: ['https://auth.example.com'],
|
|
514
|
+
validateToken: createIntrospectionValidator('https://auth.example.com/oauth/introspect', {
|
|
515
|
+
clientId: 'mcp-server',
|
|
516
|
+
clientSecret: 'secret',
|
|
517
|
+
}),
|
|
518
|
+
},
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
// Option 2: Custom validation (JWT, database lookup, etc.)
|
|
522
|
+
const middlewareCustom = createOAuthMiddleware({
|
|
523
|
+
oauth: {
|
|
524
|
+
resource: 'https://mcp.example.com/mcp',
|
|
525
|
+
authorizationServers: ['https://auth.example.com'],
|
|
526
|
+
validateToken: async (token, resource) => {
|
|
527
|
+
// Your custom validation logic
|
|
528
|
+
const decoded = await verifyJWT(token);
|
|
529
|
+
if (!decoded) {
|
|
530
|
+
return { valid: false, error: 'invalid_token', errorDescription: 'Token verification failed' };
|
|
531
|
+
}
|
|
532
|
+
return {
|
|
533
|
+
valid: true,
|
|
534
|
+
scopes: decoded.scope?.split(' ') || [],
|
|
535
|
+
subject: decoded.sub,
|
|
536
|
+
expiresAt: decoded.exp,
|
|
537
|
+
};
|
|
538
|
+
},
|
|
539
|
+
},
|
|
540
|
+
});
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
#### Custom OAuth Storage
|
|
544
|
+
|
|
545
|
+
For persistent token storage across sessions, implement the `OAuthStorage` interface:
|
|
546
|
+
|
|
547
|
+
```typescript
|
|
548
|
+
import { MCPOAuthClientProvider, OAuthStorage } from '@mastra/mcp';
|
|
549
|
+
|
|
550
|
+
// Example: Redis-based storage
|
|
551
|
+
class RedisOAuthStorage implements OAuthStorage {
|
|
552
|
+
constructor(
|
|
553
|
+
private redis: RedisClient,
|
|
554
|
+
private prefix: string,
|
|
555
|
+
) {}
|
|
556
|
+
|
|
557
|
+
async set(key: string, value: string): Promise<void> {
|
|
558
|
+
await this.redis.set(`${this.prefix}:${key}`, value);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
async get(key: string): Promise<string | undefined> {
|
|
562
|
+
return (await this.redis.get(`${this.prefix}:${key}`)) ?? undefined;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
async delete(key: string): Promise<void> {
|
|
566
|
+
await this.redis.del(`${this.prefix}:${key}`);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const provider = new MCPOAuthClientProvider({
|
|
571
|
+
redirectUrl: 'http://localhost:3000/callback',
|
|
572
|
+
clientMetadata: {
|
|
573
|
+
/* ... */
|
|
574
|
+
},
|
|
575
|
+
storage: new RedisOAuthStorage(redisClient, 'oauth:user123'),
|
|
576
|
+
});
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
### OAuth Token Refresh with AuthProvider
|
|
580
|
+
|
|
581
|
+
For simpler OAuth scenarios where you just need token refresh, you can pass an `authProvider` directly:
|
|
415
582
|
|
|
416
583
|
### Custom Fetch for Dynamic Authentication
|
|
417
584
|
|
|
@@ -613,6 +780,8 @@ The client includes comprehensive error handling:
|
|
|
613
780
|
## Related Links
|
|
614
781
|
|
|
615
782
|
- [Model Context Protocol Specification](https://modelcontextprotocol.io/specification)
|
|
783
|
+
- [MCP Authorization Specification](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization)
|
|
784
|
+
- [RFC 9728 - OAuth 2.0 Protected Resource Metadata](https://www.rfc-editor.org/rfc/rfc9728.html)
|
|
616
785
|
- [@modelcontextprotocol/sdk Documentation](https://github.com/modelcontextprotocol/typescript-sdk)
|
|
617
786
|
- [Mastra Docs: Using MCP With Mastra](/docs/agents/mcp-guide)
|
|
618
787
|
- [Mastra Docs: MastraMCPClient Reference](/reference/tools/client)
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const weatherTool: import("@mastra/core/tools").Tool<z.ZodObject<{
|
|
3
|
-
location: z.ZodString;
|
|
4
|
-
}, "strip", z.ZodTypeAny, {
|
|
1
|
+
export declare const weatherTool: import("@mastra/core/tools").Tool<{
|
|
5
2
|
location: string;
|
|
6
3
|
}, {
|
|
4
|
+
temperature: number;
|
|
5
|
+
feelsLike: number;
|
|
6
|
+
humidity: number;
|
|
7
|
+
windSpeed: number;
|
|
8
|
+
windGust: number;
|
|
9
|
+
conditions: string;
|
|
7
10
|
location: string;
|
|
8
|
-
}
|
|
11
|
+
}, unknown, unknown, import("@mastra/core/tools").ToolExecutionContext<unknown, unknown>, "get-weather">;
|
|
9
12
|
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/__fixtures__/tools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/__fixtures__/tools.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,WAAW;;;;;;;;;;wGAUtB,CAAC"}
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type { LoggingLevel, LogMessage, LogHandler, MastraMCPServerDefinition, ElicitationHandler, ProgressHandler, InternalMastraMCPClientOptions, } from './types.js';
|
|
2
2
|
export * from './client.js';
|
|
3
3
|
export * from './configuration.js';
|
|
4
|
+
export * from './oauth-provider.js';
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,YAAY,EACZ,UAAU,EACV,UAAU,EACV,yBAAyB,EACzB,kBAAkB,EAClB,eAAe,EACf,8BAA8B,GACjC,MAAM,SAAS,CAAC;AACjB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACR,YAAY,EACZ,UAAU,EACV,UAAU,EACV,yBAAyB,EACzB,kBAAkB,EAClB,eAAe,EACf,8BAA8B,GACjC,MAAM,SAAS,CAAC;AACjB,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OAuth Client Provider Implementation for MCP Client
|
|
3
|
+
*
|
|
4
|
+
* Provides a ready-to-use OAuthClientProvider implementation that can be used
|
|
5
|
+
* with Mastra's MCPClient for connecting to OAuth-protected MCP servers.
|
|
6
|
+
*
|
|
7
|
+
* @see https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization
|
|
8
|
+
*/
|
|
9
|
+
import type { OAuthClientProvider, OAuthClientMetadata, OAuthClientInformation, OAuthClientInformationFull, OAuthTokens, AuthorizationServerMetadata } from '../shared/oauth-types.js';
|
|
10
|
+
/**
|
|
11
|
+
* Storage interface for persisting OAuth data.
|
|
12
|
+
*
|
|
13
|
+
* Implement this interface to persist OAuth data across sessions.
|
|
14
|
+
* For simple in-memory usage, use InMemoryOAuthStorage.
|
|
15
|
+
*/
|
|
16
|
+
export interface OAuthStorage {
|
|
17
|
+
/**
|
|
18
|
+
* Store a value by key.
|
|
19
|
+
*/
|
|
20
|
+
set(key: string, value: string): Promise<void> | void;
|
|
21
|
+
/**
|
|
22
|
+
* Retrieve a value by key.
|
|
23
|
+
*/
|
|
24
|
+
get(key: string): Promise<string | undefined> | string | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Delete a value by key.
|
|
27
|
+
*/
|
|
28
|
+
delete(key: string): Promise<void> | void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Simple in-memory OAuth storage.
|
|
32
|
+
*
|
|
33
|
+
* Data is lost when the process exits. For production, implement
|
|
34
|
+
* OAuthStorage with a persistent store like Redis or a database.
|
|
35
|
+
*/
|
|
36
|
+
export declare class InMemoryOAuthStorage implements OAuthStorage {
|
|
37
|
+
private data;
|
|
38
|
+
set(key: string, value: string): void;
|
|
39
|
+
get(key: string): string | undefined;
|
|
40
|
+
delete(key: string): void;
|
|
41
|
+
clear(): void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Options for creating a MCPOAuthClientProvider.
|
|
45
|
+
*/
|
|
46
|
+
export interface MCPOAuthClientProviderOptions {
|
|
47
|
+
/**
|
|
48
|
+
* The redirect URL for the OAuth callback.
|
|
49
|
+
* This should be a URL your application controls that can handle
|
|
50
|
+
* the authorization code callback.
|
|
51
|
+
*
|
|
52
|
+
* @example 'http://localhost:3000/oauth/callback'
|
|
53
|
+
*/
|
|
54
|
+
redirectUrl: string | URL;
|
|
55
|
+
/**
|
|
56
|
+
* OAuth client metadata for registration.
|
|
57
|
+
* If the client is not pre-registered with the authorization server,
|
|
58
|
+
* this metadata will be used for dynamic client registration.
|
|
59
|
+
*/
|
|
60
|
+
clientMetadata: OAuthClientMetadata;
|
|
61
|
+
/**
|
|
62
|
+
* Pre-registered client information.
|
|
63
|
+
* If provided, skips dynamic client registration.
|
|
64
|
+
*/
|
|
65
|
+
clientInformation?: OAuthClientInformation;
|
|
66
|
+
/**
|
|
67
|
+
* Storage for persisting OAuth data (tokens, client info, etc.).
|
|
68
|
+
* Defaults to InMemoryOAuthStorage if not provided.
|
|
69
|
+
*/
|
|
70
|
+
storage?: OAuthStorage;
|
|
71
|
+
/**
|
|
72
|
+
* Callback invoked when the user needs to be redirected to authorize.
|
|
73
|
+
*
|
|
74
|
+
* For CLI applications, you might open the URL in a browser.
|
|
75
|
+
* For web applications, you might redirect the response.
|
|
76
|
+
*
|
|
77
|
+
* @param url - The authorization URL to redirect to
|
|
78
|
+
*/
|
|
79
|
+
onRedirectToAuthorization?: (url: URL) => void | Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Generate a random state parameter for OAuth requests.
|
|
82
|
+
* Defaults to using crypto.randomUUID.
|
|
83
|
+
*/
|
|
84
|
+
stateGenerator?: () => string | Promise<string>;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Mastra's OAuth Client Provider implementation.
|
|
88
|
+
*
|
|
89
|
+
* This provider handles the OAuth 2.1 flow for connecting to OAuth-protected
|
|
90
|
+
* MCP servers, including:
|
|
91
|
+
* - Dynamic client registration (RFC 7591)
|
|
92
|
+
* - PKCE (Proof Key for Code Exchange)
|
|
93
|
+
* - Token storage and refresh
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* import { MCPClient, MCPOAuthClientProvider, InMemoryOAuthStorage } from '@mastra/mcp';
|
|
98
|
+
*
|
|
99
|
+
* // Create the OAuth provider
|
|
100
|
+
* const oauthProvider = new MCPOAuthClientProvider({
|
|
101
|
+
* redirectUrl: 'http://localhost:3000/oauth/callback',
|
|
102
|
+
* clientMetadata: {
|
|
103
|
+
* redirect_uris: ['http://localhost:3000/oauth/callback'],
|
|
104
|
+
* client_name: 'My MCP Client',
|
|
105
|
+
* grant_types: ['authorization_code', 'refresh_token'],
|
|
106
|
+
* response_types: ['code'],
|
|
107
|
+
* },
|
|
108
|
+
* onRedirectToAuthorization: (url) => {
|
|
109
|
+
* // Open URL in browser for CLI, or redirect response for web
|
|
110
|
+
* console.log(`Please visit: ${url}`);
|
|
111
|
+
* },
|
|
112
|
+
* });
|
|
113
|
+
*
|
|
114
|
+
* // Create the MCP client with OAuth
|
|
115
|
+
* const client = new MCPClient({
|
|
116
|
+
* servers: {
|
|
117
|
+
* 'protected-server': {
|
|
118
|
+
* url: 'https://mcp.example.com/mcp',
|
|
119
|
+
* authProvider: oauthProvider,
|
|
120
|
+
* },
|
|
121
|
+
* },
|
|
122
|
+
* });
|
|
123
|
+
*
|
|
124
|
+
* await client.connect();
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare class MCPOAuthClientProvider implements OAuthClientProvider {
|
|
128
|
+
private readonly _redirectUrl;
|
|
129
|
+
private readonly _clientMetadata;
|
|
130
|
+
private readonly storage;
|
|
131
|
+
private readonly onRedirect?;
|
|
132
|
+
private readonly generateState;
|
|
133
|
+
private _clientInfo?;
|
|
134
|
+
constructor(options: MCPOAuthClientProviderOptions);
|
|
135
|
+
/**
|
|
136
|
+
* The URL to redirect the user agent to after authorization.
|
|
137
|
+
*/
|
|
138
|
+
get redirectUrl(): string | URL;
|
|
139
|
+
/**
|
|
140
|
+
* Metadata about this OAuth client.
|
|
141
|
+
*/
|
|
142
|
+
get clientMetadata(): OAuthClientMetadata;
|
|
143
|
+
/**
|
|
144
|
+
* Returns a OAuth2 state parameter.
|
|
145
|
+
*/
|
|
146
|
+
state(): Promise<string>;
|
|
147
|
+
/**
|
|
148
|
+
* Loads information about this OAuth client.
|
|
149
|
+
*/
|
|
150
|
+
clientInformation(): Promise<OAuthClientInformation | undefined>;
|
|
151
|
+
/**
|
|
152
|
+
* Saves dynamically registered client information.
|
|
153
|
+
*/
|
|
154
|
+
saveClientInformation(clientInformation: OAuthClientInformationFull): Promise<void>;
|
|
155
|
+
/**
|
|
156
|
+
* Loads existing OAuth tokens.
|
|
157
|
+
*/
|
|
158
|
+
tokens(): Promise<OAuthTokens | undefined>;
|
|
159
|
+
/**
|
|
160
|
+
* Stores new OAuth tokens after successful authorization.
|
|
161
|
+
*/
|
|
162
|
+
saveTokens(tokens: OAuthTokens): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Invoked to redirect the user agent to the authorization URL.
|
|
165
|
+
*/
|
|
166
|
+
redirectToAuthorization(authorizationUrl: URL): Promise<void>;
|
|
167
|
+
/**
|
|
168
|
+
* Saves a PKCE code verifier before redirecting to authorization.
|
|
169
|
+
*/
|
|
170
|
+
saveCodeVerifier(codeVerifier: string): Promise<void>;
|
|
171
|
+
/**
|
|
172
|
+
* Loads the PKCE code verifier for validating authorization result.
|
|
173
|
+
*/
|
|
174
|
+
codeVerifier(): Promise<string>;
|
|
175
|
+
/**
|
|
176
|
+
* Optional: Custom client authentication for token requests.
|
|
177
|
+
* Uses default behavior if not implemented.
|
|
178
|
+
*/
|
|
179
|
+
addClientAuthentication?(_headers: Headers, _params: URLSearchParams, _url: string | URL, _metadata?: AuthorizationServerMetadata): Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* Invalidate credentials when server indicates they're no longer valid.
|
|
182
|
+
*/
|
|
183
|
+
invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier'): Promise<void>;
|
|
184
|
+
/**
|
|
185
|
+
* Clear all stored OAuth data.
|
|
186
|
+
* Useful for logging out or resetting state.
|
|
187
|
+
*/
|
|
188
|
+
clear(): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* Check if the provider has valid (non-expired) tokens.
|
|
191
|
+
*/
|
|
192
|
+
hasValidTokens(): Promise<boolean>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Creates a simple OAuth provider with pre-configured tokens.
|
|
196
|
+
*
|
|
197
|
+
* This is useful for testing scenarios where you already have a valid token.
|
|
198
|
+
* For production, use the full MCPOAuthClientProvider with proper OAuth flow.
|
|
199
|
+
*
|
|
200
|
+
* @param accessToken - A valid access token
|
|
201
|
+
* @param options - Additional configuration options
|
|
202
|
+
* @returns An OAuthClientProvider that returns the pre-configured token
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```typescript
|
|
206
|
+
* const provider = createSimpleTokenProvider('my-access-token', {
|
|
207
|
+
* redirectUrl: 'http://localhost:3000/callback',
|
|
208
|
+
* clientMetadata: {
|
|
209
|
+
* redirect_uris: ['http://localhost:3000/callback'],
|
|
210
|
+
* client_name: 'Test Client',
|
|
211
|
+
* },
|
|
212
|
+
* });
|
|
213
|
+
*
|
|
214
|
+
* const client = new MCPClient({
|
|
215
|
+
* servers: {
|
|
216
|
+
* test: { url: 'https://mcp.example.com', authProvider: provider }
|
|
217
|
+
* },
|
|
218
|
+
* });
|
|
219
|
+
* ```
|
|
220
|
+
*/
|
|
221
|
+
export declare function createSimpleTokenProvider(accessToken: string, options: {
|
|
222
|
+
redirectUrl: string | URL;
|
|
223
|
+
clientMetadata: OAuthClientMetadata;
|
|
224
|
+
clientInformation?: OAuthClientInformation;
|
|
225
|
+
tokenType?: string;
|
|
226
|
+
refreshToken?: string;
|
|
227
|
+
expiresIn?: number;
|
|
228
|
+
scope?: string;
|
|
229
|
+
}): OAuthClientProvider;
|
|
230
|
+
//# sourceMappingURL=oauth-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-provider.d.ts","sourceRoot":"","sources":["../../src/client/oauth-provider.ts"],"names":[],"mappings":"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"}
|
package/dist/docs/README.md
CHANGED
package/dist/docs/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: Documentation for @mastra/mcp. Includes links to type definitions a
|
|
|
5
5
|
|
|
6
6
|
# @mastra/mcp Documentation
|
|
7
7
|
|
|
8
|
-
> **Version**: 1.0.0
|
|
8
|
+
> **Version**: 1.0.0
|
|
9
9
|
> **Package**: @mastra/mcp
|
|
10
10
|
|
|
11
11
|
## Quick Navigation
|
|
@@ -23,7 +23,19 @@ Each export maps to:
|
|
|
23
23
|
|
|
24
24
|
## Top Exports
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
- UnauthorizedError: dist/index.d.ts
|
|
27
|
+
- auth: dist/index.d.ts
|
|
28
|
+
- buildDiscoveryUrls: dist/index.d.ts
|
|
29
|
+
- discoverAuthorizationServerMetadata: dist/index.d.ts
|
|
30
|
+
- discoverOAuthMetadata: dist/index.d.ts
|
|
31
|
+
- discoverOAuthProtectedResourceMetadata: dist/index.d.ts
|
|
32
|
+
- exchangeAuthorization: dist/index.d.ts
|
|
33
|
+
- extractResourceMetadataUrl: dist/index.d.ts
|
|
34
|
+
- parseErrorResponse: dist/index.d.ts
|
|
35
|
+
- refreshAuthorization: dist/index.d.ts
|
|
36
|
+
- registerClient: dist/index.d.ts
|
|
37
|
+
- selectResourceURL: dist/index.d.ts
|
|
38
|
+
- startAuthorization: dist/index.d.ts
|
|
27
39
|
|
|
28
40
|
See SOURCE_MAP.json for the complete list.
|
|
29
41
|
|
|
@@ -1,6 +1,59 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.0.0
|
|
2
|
+
"version": "1.0.0",
|
|
3
3
|
"package": "@mastra/mcp",
|
|
4
|
-
"exports": {
|
|
4
|
+
"exports": {
|
|
5
|
+
"UnauthorizedError": {
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"implementation": "dist/auth.js"
|
|
8
|
+
},
|
|
9
|
+
"auth": {
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"implementation": "dist/auth.js"
|
|
12
|
+
},
|
|
13
|
+
"buildDiscoveryUrls": {
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"implementation": "dist/auth.js"
|
|
16
|
+
},
|
|
17
|
+
"discoverAuthorizationServerMetadata": {
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"implementation": "dist/auth.js"
|
|
20
|
+
},
|
|
21
|
+
"discoverOAuthMetadata": {
|
|
22
|
+
"types": "dist/index.d.ts",
|
|
23
|
+
"implementation": "dist/auth.js"
|
|
24
|
+
},
|
|
25
|
+
"discoverOAuthProtectedResourceMetadata": {
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"implementation": "dist/auth.js"
|
|
28
|
+
},
|
|
29
|
+
"exchangeAuthorization": {
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
31
|
+
"implementation": "dist/auth.js"
|
|
32
|
+
},
|
|
33
|
+
"extractResourceMetadataUrl": {
|
|
34
|
+
"types": "dist/index.d.ts",
|
|
35
|
+
"implementation": "dist/auth.js"
|
|
36
|
+
},
|
|
37
|
+
"parseErrorResponse": {
|
|
38
|
+
"types": "dist/index.d.ts",
|
|
39
|
+
"implementation": "dist/auth.js"
|
|
40
|
+
},
|
|
41
|
+
"refreshAuthorization": {
|
|
42
|
+
"types": "dist/index.d.ts",
|
|
43
|
+
"implementation": "dist/auth.js"
|
|
44
|
+
},
|
|
45
|
+
"registerClient": {
|
|
46
|
+
"types": "dist/index.d.ts",
|
|
47
|
+
"implementation": "dist/auth.js"
|
|
48
|
+
},
|
|
49
|
+
"selectResourceURL": {
|
|
50
|
+
"types": "dist/index.d.ts",
|
|
51
|
+
"implementation": "dist/auth.js"
|
|
52
|
+
},
|
|
53
|
+
"startAuthorization": {
|
|
54
|
+
"types": "dist/index.d.ts",
|
|
55
|
+
"implementation": "dist/auth.js"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
5
58
|
"modules": {}
|
|
6
59
|
}
|