Skip to content

Commit 71c14ea

Browse files
authored
Add .js to the error import to resolve ESM correctly (#54)
* src/next/auth-context.ts src/next/auth-wrapper.ts * .changeset/mean-readers-punch.md * .github/workflows/release-snapshot.yml * package.json * .changeset/slick-beers-flash.md
1 parent 4b9d6d0 commit 71c14ea

File tree

6 files changed

+35
-15
lines changed

6 files changed

+35
-15
lines changed

.changeset/mean-readers-punch.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vercel/mcp-adapter": patch
3+
---
4+
5+
Fix module resolution

.changeset/slick-beers-flash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@vercel/mcp-adapter": minor
3+
---
4+
5+
Fix import error with mcp sdk

.github/workflows/release-snapshot.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ jobs:
3131
version: 9.4.0
3232
run_install: false
3333

34+
- name: Add npm auth token to pnpm
35+
run: pnpm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN_ELEVATED}"
36+
env:
37+
NPM_TOKEN_ELEVATED: ${{secrets.NPM_TOKEN_ELEVATED}}
3438
- name: Install Dependencies
3539
id: pnpm-install
3640
run: pnpm install --frozen-lockfile
@@ -41,6 +45,7 @@ jobs:
4145
- name: Create Snapshot Release
4246
run: |
4347
pnpm changeset version --snapshot ${SHORT_SHA}
48+
pnpm build
4449
pnpm changeset publish --no-git-tag --tag snapshot
4550
env:
4651
GITHUB_TOKEN: ${{ secrets.GH_TOKEN_PULL_REQUESTS }}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@
6868
"peerDependenciesMeta": {
6969
"@modelcontextprotocol/sdk": {
7070
"optional": false
71+
},
72+
"next": {
73+
"optional": true
7174
}
7275
},
7376
"packageManager": "[email protected]",

src/next/auth-context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types";
1+
import { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
22
import { AsyncLocalStorage } from "node:async_hooks";
33

44
const authContext = new AsyncLocalStorage<AuthInfo>();

src/next/auth-wrapper.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types";
2-
import { InvalidTokenError, InsufficientScopeError, ServerError } from "@modelcontextprotocol/sdk/server/auth/errors";
1+
import { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
2+
import {
3+
InvalidTokenError,
4+
InsufficientScopeError,
5+
ServerError,
6+
} from "@modelcontextprotocol/sdk/server/auth/errors.js";
37
import { withAuthContext } from "./auth-context";
48

59
declare global {
@@ -34,7 +38,7 @@ export function withMcpAuth(
3438
const bearerToken = type?.toLowerCase() === "bearer" ? token : undefined;
3539

3640
const authInfo = await verifyToken(req, bearerToken);
37-
41+
3842
if (required && !authInfo) {
3943
throw new InvalidTokenError("No authorization provided");
4044
}
@@ -45,7 +49,7 @@ export function withMcpAuth(
4549

4650
// Check if token has the required scopes (if any)
4751
if (requiredScopes?.length) {
48-
const hasAllScopes = requiredScopes.every(scope =>
52+
const hasAllScopes = requiredScopes.every((scope) =>
4953
authInfo.scopes.includes(scope)
5054
);
5155

@@ -72,36 +76,34 @@ export function withMcpAuth(
7276
status: 401,
7377
headers: {
7478
"WWW-Authenticate": `Bearer error="${error.errorCode}", error_description="${error.message}", resource_metadata="${resourceMetadataUrl}"`,
75-
"Content-Type": "application/json"
76-
}
79+
"Content-Type": "application/json",
80+
},
7781
});
7882
} else if (error instanceof InsufficientScopeError) {
7983
return new Response(JSON.stringify(error.toResponseObject()), {
8084
status: 403,
8185
headers: {
8286
"WWW-Authenticate": `Bearer error="${error.errorCode}", error_description="${error.message}", resource_metadata="${resourceMetadataUrl}"`,
83-
"Content-Type": "application/json"
84-
}
87+
"Content-Type": "application/json",
88+
},
8589
});
8690
} else if (error instanceof ServerError) {
8791
return new Response(JSON.stringify(error.toResponseObject()), {
8892
status: 500,
8993
headers: {
90-
"Content-Type": "application/json"
91-
}
94+
"Content-Type": "application/json",
95+
},
9296
});
9397
} else {
9498
console.error("Unexpected error authenticating bearer token:", error);
9599
const serverError = new ServerError("Internal Server Error");
96100
return new Response(JSON.stringify(serverError.toResponseObject()), {
97101
status: 500,
98102
headers: {
99-
"Content-Type": "application/json"
100-
}
103+
"Content-Type": "application/json",
104+
},
101105
});
102106
}
103107
}
104108
};
105109
}
106-
107-

0 commit comments

Comments
 (0)