@agentailor/create-mcp-server 0.7.0 → 0.7.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/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Command, Option, InvalidArgumentError } from 'commander';
|
|
2
2
|
const NAME_REGEX = /^[a-z0-9-_]+$/i;
|
|
3
|
-
const VERSION = '0.7.
|
|
3
|
+
const VERSION = '0.7.1';
|
|
4
4
|
function validateName(value) {
|
|
5
5
|
if (!NAME_REGEX.test(value)) {
|
|
6
6
|
throw new InvalidArgumentError('Project name can only contain letters, numbers, hyphens, and underscores');
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
getOAuthProtectedResourceMetadataUrl,
|
|
7
7
|
requireBearerAuth,
|
|
8
8
|
} from '@modelcontextprotocol/express';
|
|
9
|
+
import { OAuthError, OAuthErrorCode } from '@modelcontextprotocol/server';
|
|
9
10
|
import type { OAuthMetadata, OAuthTokenVerifier } from '@modelcontextprotocol/server';
|
|
10
11
|
import type { Express, RequestHandler } from 'express';
|
|
11
12
|
|
|
@@ -47,6 +48,8 @@ interface OIDCDiscoveryDocument {
|
|
|
47
48
|
// Token verifier using JWKS/JWT validation
|
|
48
49
|
const tokenVerifier: OAuthTokenVerifier = {
|
|
49
50
|
verifyAccessToken: async (token: string) => {
|
|
51
|
+
// A plain Error here is intentional: an uninitialized JWKS is a server
|
|
52
|
+
// misconfiguration, not a bad token, so it should surface as 500 server_error.
|
|
50
53
|
if (!JWKS) {
|
|
51
54
|
throw new Error('JWKS not initialized. Call validateOAuthConfig() first.');
|
|
52
55
|
}
|
|
@@ -55,8 +58,9 @@ const tokenVerifier: OAuthTokenVerifier = {
|
|
|
55
58
|
// Check if the token looks like a JWT (three base64url-encoded parts separated by dots)
|
|
56
59
|
const parts = token.split('.');
|
|
57
60
|
if (parts.length !== 3) {
|
|
58
|
-
throw new
|
|
59
|
-
|
|
61
|
+
throw new OAuthError(
|
|
62
|
+
OAuthErrorCode.InvalidToken,
|
|
63
|
+
'Token is not a valid JWT format (expected 3 parts separated by dots).'
|
|
60
64
|
);
|
|
61
65
|
}
|
|
62
66
|
|
|
@@ -83,7 +87,14 @@ const tokenVerifier: OAuthTokenVerifier = {
|
|
|
83
87
|
if (error instanceof Error) {
|
|
84
88
|
console.error('[auth] JWT verification failed:', error.message);
|
|
85
89
|
}
|
|
86
|
-
|
|
90
|
+
if (error instanceof OAuthError) {
|
|
91
|
+
throw error;
|
|
92
|
+
}
|
|
93
|
+
// Convert jose failures (bad signature, expired, wrong issuer/audience) into
|
|
94
|
+
// an OAuthError so requireBearerAuth answers 401 with a WWW-Authenticate
|
|
95
|
+
// challenge instead of 500. The specific reason stays in the server log
|
|
96
|
+
// rather than the response body, so callers learn nothing beyond "invalid".
|
|
97
|
+
throw new OAuthError(OAuthErrorCode.InvalidToken, 'Token verification failed');
|
|
87
98
|
}
|
|
88
99
|
},
|
|
89
100
|
};
|
|
@@ -100,5 +100,34 @@ describe('auth template', () => {
|
|
|
100
100
|
const template = getAuthTemplate();
|
|
101
101
|
expect(template).toContain("jwtPayload.scope.split(' ')");
|
|
102
102
|
});
|
|
103
|
+
it('should import OAuthError and OAuthErrorCode as values, not types', () => {
|
|
104
|
+
const template = getAuthTemplate();
|
|
105
|
+
expect(template).toContain("import { OAuthError, OAuthErrorCode } from '@modelcontextprotocol/server'");
|
|
106
|
+
});
|
|
107
|
+
it('should reject malformed JWTs with an OAuthError so the response is 401', () => {
|
|
108
|
+
const template = getAuthTemplate();
|
|
109
|
+
expect(template).toContain('throw new OAuthError(\n OAuthErrorCode.InvalidToken,');
|
|
110
|
+
expect(template).not.toContain("throw new Error(\n 'Token is not a valid JWT format");
|
|
111
|
+
});
|
|
112
|
+
it('should convert jose verification failures into an OAuthError', () => {
|
|
113
|
+
const template = getAuthTemplate();
|
|
114
|
+
expect(template).toContain("throw new OAuthError(OAuthErrorCode.InvalidToken, 'Token verification failed')");
|
|
115
|
+
// The bare re-throw produced a 500 server_error with no WWW-Authenticate header.
|
|
116
|
+
expect(template).not.toMatch(/JWT verification failed:', error\.message\);\s*}\s*throw error;/);
|
|
117
|
+
});
|
|
118
|
+
it('should re-throw an existing OAuthError unchanged', () => {
|
|
119
|
+
const template = getAuthTemplate();
|
|
120
|
+
expect(template).toContain('if (error instanceof OAuthError) {');
|
|
121
|
+
});
|
|
122
|
+
it('should not leak the underlying failure reason into the error response', () => {
|
|
123
|
+
const template = getAuthTemplate();
|
|
124
|
+
// The jose message is logged server-side but must not reach error_description.
|
|
125
|
+
expect(template).toContain("console.error('[auth] JWT verification failed:', error.message)");
|
|
126
|
+
expect(template).not.toContain("error instanceof Error ? error.message : 'Token verification failed'");
|
|
127
|
+
});
|
|
128
|
+
it('should keep an uninitialized JWKS as a plain Error (server misconfiguration)', () => {
|
|
129
|
+
const template = getAuthTemplate();
|
|
130
|
+
expect(template).toContain("throw new Error('JWKS not initialized. Call validateOAuthConfig() first.')");
|
|
131
|
+
});
|
|
103
132
|
});
|
|
104
133
|
});
|