Skip to content

Commit bf72f87

Browse files
committed
cleanups
1 parent c2150f0 commit bf72f87

File tree

5 files changed

+9
-20
lines changed

5 files changed

+9
-20
lines changed

src/examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ npx tsx src/examples/server/simpleStreamableHttp.ts
7878
npx tsx src/examples/server/simpleStreamableHttp.ts --oauth
7979

8080
# To mitigate impersonation risks, enable strict Resource Identifier verification:
81-
npx tsx src/examples/server/simpleStreamableHttp.ts --oauth --oauth-resource=https://some-mcp-server.com --oauth-resource-strict
81+
npx tsx src/examples/server/simpleStreamableHttp.ts --oauth --oauth-strict
8282
```
8383

8484
##### JSON Response Mode Server

src/examples/server/demoInMemoryOAuthProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class DemoInMemoryAuthProvider implements OAuthServerProvider {
102102
}
103103

104104
if (this.validateResource && !this.validateResource(codeData.params.resource)) {
105-
throw new Error('Invalid resource');
105+
throw new Error(`Invalid resource: ${codeData.params.resource}`);
106106
}
107107

108108
this.codes.delete(authorizationCode);

src/examples/server/simpleStreamableHttp.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@ import { OAuthMetadata } from 'src/shared/auth.js';
1212

1313
// Check for OAuth flag
1414
const useOAuth = process.argv.includes('--oauth');
15-
// Resource Indicator the OAuth tokens are checked against (RFC8707).
16-
const expectedOAuthResource = (iArg => iArg < 0 ? undefined: process.argv[iArg + 1])(process.argv.indexOf('--oauth-resource'));
17-
// Requires Resource Indicator check (implies protocol more recent than 2025-03-26)
18-
const strictOAuthResourceCheck = process.argv.includes('--oauth-resource-strict');
19-
if (strictOAuthResourceCheck && !expectedOAuthResource) {
20-
throw new Error(`Strict resource indicator checking requires passing the expected resource with --oauth-resource https://...`);
21-
}
15+
const strictOAuth = process.argv.includes('--oauth-strict');
2216

2317
// Create an MCP server with implementation details
2418
const getServer = () => {
@@ -292,7 +286,7 @@ if (useOAuth) {
292286
const oauthMetadata: OAuthMetadata = setupAuthServer(authServerUrl, mcpServerUrl);
293287

294288
const tokenVerifier = {
295-
verifyAccessToken: async (token: string, protocolVersion: string) => {
289+
verifyAccessToken: async (token: string) => {
296290
const endpoint = oauthMetadata.introspection_endpoint;
297291

298292
if (!endpoint) {
@@ -316,11 +310,11 @@ if (useOAuth) {
316310

317311
const data = await response.json();
318312

319-
if (expectedOAuthResource) {
320-
if (strictOAuthResourceCheck && !data.resource) {
313+
if (strictOAuth) {
314+
if (!data.resource) {
321315
throw new Error('Resource Indicator (RFC8707) missing');
322316
}
323-
if (data.resource && data.resource !== expectedOAuthResource) {
317+
if (data.resource !== expectedOAuthResource) {
324318
throw new Error(`Expected resource indicator ${expectedOAuthResource}, got: ${data.resource}`);
325319
}
326320
}

src/server/auth/middleware/bearerAuth.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,7 @@ export function requireBearerAuth({ verifier, requiredScopes = [], resourceMetad
5151
throw new InvalidTokenError("Invalid Authorization header format, expected 'Bearer TOKEN'");
5252
}
5353

54-
let protocolVersion = req.headers["mcp-protocol-version"] ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
55-
if (Array.isArray(protocolVersion)) {
56-
protocolVersion = protocolVersion[protocolVersion.length - 1];
57-
}
58-
59-
const authInfo = await verifier.verifyAccessToken(token, protocolVersion);
54+
const authInfo = await verifier.verifyAccessToken(token);
6055

6156
// Check if token has the required scopes (if any)
6257
if (requiredScopes.length > 0) {

src/server/auth/provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,5 @@ export interface OAuthTokenVerifier {
8080
/**
8181
* Verifies an access token and returns information about it.
8282
*/
83-
verifyAccessToken(token: string, protocolVersion: string): Promise<AuthInfo>;
83+
verifyAccessToken(token: string): Promise<AuthInfo>;
8484
}

0 commit comments

Comments
 (0)