@smithery/sdk 1.6.3 → 1.6.5
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/server/auth/oauth.d.ts +10 -2
- package/dist/server/auth/oauth.js +18 -4
- package/package.json +1 -1
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import type { OAuthServerProvider, OAuthTokenVerifier } from "@modelcontextprotocol/sdk/server/auth/provider.js";
|
|
2
|
+
import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
|
|
2
3
|
import type { Application, Response } from "express";
|
|
3
4
|
import { type IdentityHandler } from "./identity.js";
|
|
4
|
-
export interface
|
|
5
|
+
export interface TokenVerifier extends OAuthTokenVerifier {
|
|
6
|
+
verifyAccessToken: (token: string) => Promise<AuthInfo>;
|
|
7
|
+
requiredScopes?: string[];
|
|
8
|
+
resourceMetadataUrl?: string;
|
|
9
|
+
}
|
|
10
|
+
type ProviderVerifier = OAuthServerProvider & TokenVerifier;
|
|
11
|
+
export interface OAuthProvider extends ProviderVerifier {
|
|
5
12
|
basePath?: string;
|
|
6
13
|
callbackPath?: string;
|
|
7
14
|
handleOAuthCallback?: (code: string, state: string | undefined, res: Response) => Promise<URL>;
|
|
8
15
|
}
|
|
9
16
|
export interface OAuthMountOptions {
|
|
10
|
-
provider?:
|
|
17
|
+
provider?: OAuthProvider | ProviderVerifier;
|
|
11
18
|
identity?: IdentityHandler;
|
|
12
19
|
}
|
|
13
20
|
export declare function mountOAuth(app: Application, opts: OAuthMountOptions): void;
|
|
21
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { requireBearerAuth } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js";
|
|
2
|
-
import { mcpAuthMetadataRouter, createOAuthMetadata, } from "@modelcontextprotocol/sdk/server/auth/router.js";
|
|
3
1
|
import { authorizationHandler } from "@modelcontextprotocol/sdk/server/auth/handlers/authorize.js";
|
|
4
|
-
import {
|
|
2
|
+
import { metadataHandler } from "@modelcontextprotocol/sdk/server/auth/handlers/metadata.js";
|
|
5
3
|
import { clientRegistrationHandler } from "@modelcontextprotocol/sdk/server/auth/handlers/register.js";
|
|
6
4
|
import { revocationHandler } from "@modelcontextprotocol/sdk/server/auth/handlers/revoke.js";
|
|
7
|
-
import {
|
|
5
|
+
import { tokenHandler } from "@modelcontextprotocol/sdk/server/auth/handlers/token.js";
|
|
6
|
+
import { requireBearerAuth } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js";
|
|
7
|
+
import { createOAuthMetadata, mcpAuthMetadataRouter, } from "@modelcontextprotocol/sdk/server/auth/router.js";
|
|
8
8
|
import { mountIdentity } from "./identity.js";
|
|
9
9
|
function isOAuthProvider(provider) {
|
|
10
10
|
return !!provider && "authorize" in provider;
|
|
@@ -77,9 +77,21 @@ export function mountOAuth(app, opts) {
|
|
|
77
77
|
const issuerUrl = new URL(`${req.protocol}://${host}`);
|
|
78
78
|
const protectedResourceMetadata = {
|
|
79
79
|
resource: new URL("/mcp", issuerUrl).href,
|
|
80
|
+
authorization_servers: [issuerUrl.href],
|
|
80
81
|
};
|
|
81
82
|
return metadataHandler(protectedResourceMetadata)(req, res, next);
|
|
82
83
|
});
|
|
84
|
+
// Identity-only: also advertise minimal AS metadata for discovery per RFC 8414
|
|
85
|
+
app.use("/.well-known/oauth-authorization-server", (req, res, next) => {
|
|
86
|
+
const host = req.get("host") ?? "localhost";
|
|
87
|
+
const issuerUrl = new URL(`${req.protocol}://${host}`);
|
|
88
|
+
const oauthMetadata = {
|
|
89
|
+
issuer: issuerUrl.href,
|
|
90
|
+
token_endpoint: new URL(`${basePath}token`, issuerUrl).href,
|
|
91
|
+
grant_types_supported: ["urn:ietf:params:oauth:grant-type:jwt-bearer"],
|
|
92
|
+
};
|
|
93
|
+
return metadataHandler(oauthMetadata)(req, res, next);
|
|
94
|
+
});
|
|
83
95
|
}
|
|
84
96
|
// Mount identity (JWT bearer grant) first so OAuth token can fall through
|
|
85
97
|
if (opts.identity) {
|
|
@@ -135,6 +147,8 @@ export function mountOAuth(app, opts) {
|
|
|
135
147
|
app.use("/mcp", (req, res, next) => {
|
|
136
148
|
return requireBearerAuth({
|
|
137
149
|
verifier: provider,
|
|
150
|
+
requiredScopes: provider.requiredScopes,
|
|
151
|
+
resourceMetadataUrl: provider.resourceMetadataUrl,
|
|
138
152
|
})(req, res, next);
|
|
139
153
|
});
|
|
140
154
|
}
|