Skip to content

Commit 81570d2

Browse files
authored
Merge branch 'main' into main
2 parents d4c4dcc + 744b9ea commit 81570d2

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@
3636
],
3737
"scripts": {
3838
"build": "npm run build:esm && npm run build:cjs",
39-
"build:esm": "tsc -p tsconfig.prod.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",
40-
"build:cjs": "tsc -p tsconfig.cjs.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json",
39+
"build:esm": "mkdir -p dist/esm && echo '{\"type\": \"module\"}' > dist/esm/package.json && tsc -p tsconfig.prod.json",
40+
"build:esm:w": "npm run build:esm -- -w",
41+
"build:cjs": "mkdir -p dist/cjs && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json && tsc -p tsconfig.cjs.json",
42+
"build:cjs:w": "npm run build:cjs -- -w",
43+
"examples:simple-server:w": "tsx --watch src/examples/server/simpleStreamableHttp.ts --oauth",
4144
"prepack": "npm run build:esm && npm run build:cjs",
4245
"lint": "eslint src/",
4346
"test": "jest",

src/examples/server/demoInMemoryOAuthProvider.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,8 @@ export class DemoInMemoryAuthProvider implements OAuthServerProvider {
3535
params: AuthorizationParams,
3636
client: OAuthClientInformationFull}>();
3737
private tokens = new Map<string, AuthInfo>();
38-
private validateResource?: (resource?: URL) => boolean;
39-
40-
constructor({mcpServerUrl}: {mcpServerUrl?: URL} = {}) {
41-
if (mcpServerUrl) {
42-
const expectedResource = resourceUrlFromServerUrl(mcpServerUrl);
43-
this.validateResource = (resource?: URL) => {
44-
if (!resource) return false;
45-
return resource.toString() === expectedResource.toString();
46-
};
47-
}
48-
}
38+
39+
constructor(private validateResource?: (resource?: URL) => boolean) {}
4940

5041
async authorize(
5142
client: OAuthClientInformationFull,
@@ -153,13 +144,20 @@ export class DemoInMemoryAuthProvider implements OAuthServerProvider {
153144
}
154145

155146

156-
export const setupAuthServer = (authServerUrl: URL, mcpServerUrl: URL): OAuthMetadata => {
147+
export const setupAuthServer = ({authServerUrl, mcpServerUrl, strictResource}: {authServerUrl: URL, mcpServerUrl: URL, strictResource: boolean}): OAuthMetadata => {
157148
// Create separate auth server app
158149
// NOTE: This is a separate app on a separate port to illustrate
159150
// how to separate an OAuth Authorization Server from a Resource
160151
// server in the SDK. The SDK is not intended to be provide a standalone
161152
// authorization server.
162-
const provider = new DemoInMemoryAuthProvider({mcpServerUrl});
153+
154+
const validateResource = strictResource ? (resource?: URL) => {
155+
if (!resource) return false;
156+
const expectedResource = resourceUrlFromServerUrl(mcpServerUrl);
157+
return resource.toString() === expectedResource.toString();
158+
} : undefined;
159+
160+
const provider = new DemoInMemoryAuthProvider(validateResource);
163161
const authApp = express();
164162
authApp.use(express.json());
165163
// For introspection requests

src/examples/server/simpleStreamableHttp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ if (useOAuth) {
432432
const mcpServerUrl = new URL(`http://localhost:${MCP_PORT}/mcp`);
433433
const authServerUrl = new URL(`http://localhost:${AUTH_PORT}`);
434434

435-
const oauthMetadata: OAuthMetadata = setupAuthServer(authServerUrl, mcpServerUrl);
435+
const oauthMetadata: OAuthMetadata = setupAuthServer({authServerUrl, mcpServerUrl, strictResource: strictOAuth});
436436

437437
const tokenVerifier = {
438438
verifyAccessToken: async (token: string) => {

0 commit comments

Comments
 (0)