Skip to content

Commit 73a6d95

Browse files
alistair3149claude
andauthored
Ground the OAuth metadata doc types in the SDK's (#524)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
1 parent 2e42985 commit 73a6d95

3 files changed

Lines changed: 29 additions & 20 deletions

File tree

src/auth/authorizationServer/asMetadata.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1+
import type { OAuthMetadata } from '@modelcontextprotocol/server';
12
import type { ProxyConfig } from './proxyConfig.ts';
23

3-
export interface AsMetadataDoc {
4-
issuer: string;
5-
authorization_endpoint: string;
6-
token_endpoint: string;
7-
registration_endpoint: string;
8-
response_types_supported: string[];
9-
grant_types_supported: string[];
10-
code_challenge_methods_supported: string[];
11-
token_endpoint_auth_methods_supported: string[];
12-
authorization_response_iss_parameter_supported: boolean;
13-
client_id_metadata_document_supported: boolean;
14-
scopes_supported?: string[];
15-
}
4+
// The SDK's RFC 8414 document type, narrowed to the fields this proxy always
5+
// emits: the spec and its registry extensions make them optional, but clients
6+
// pick a compatible flow from these advertisements (grant types, auth
7+
// methods, PKCE, DCR, iss, CIMD).
8+
export type AsMetadataDoc = OAuthMetadata &
9+
Required<
10+
Pick<
11+
OAuthMetadata,
12+
| 'registration_endpoint'
13+
| 'grant_types_supported'
14+
| 'code_challenge_methods_supported'
15+
| 'token_endpoint_auth_methods_supported'
16+
| 'authorization_response_iss_parameter_supported'
17+
| 'client_id_metadata_document_supported'
18+
>
19+
>;
1620

1721
/**
1822
* Builds the RFC 8414 authorization-server metadata document advertising this

src/auth/oauthFlow.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
const TIMEOUT_MS = 5000;
44

5+
// Deliberately not the SDK's OAuthTokens, which requires token_type and makes
6+
// expires_in optional — the inverse of what post() enforces. expires_in must
7+
// be present because token stores schedule refresh from it; token_type may be
8+
// absent in MediaWiki responses.
59
export interface TokenResponse {
610
access_token: string;
711
refresh_token?: string;

src/auth/protectedResource.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// src/auth/protectedResource.ts
2+
import type { OAuthProtectedResourceMetadata } from '@modelcontextprotocol/server';
23
import type { UpstreamAsMetadata } from './metadata.ts';
34

45
const RESOURCE_DOCUMENTATION =
@@ -21,13 +22,13 @@ export interface ProtectedResourceInput {
2122
authorizationServers: readonly string[];
2223
}
2324

24-
export interface ProtectedResourceDoc {
25-
resource: string;
26-
authorization_servers: string[];
27-
bearer_methods_supported: string[];
28-
scopes_supported?: string[];
29-
resource_documentation?: string;
30-
}
25+
// The SDK's RFC 9728 document type, narrowed to the fields this server always
26+
// emits: RFC 9728 makes them optional, but a doc without an authorization
27+
// server would leave a client nowhere to sign in.
28+
export type ProtectedResourceDoc = OAuthProtectedResourceMetadata &
29+
Required<
30+
Pick<OAuthProtectedResourceMetadata, 'authorization_servers' | 'bearer_methods_supported'>
31+
>;
3132

3233
function anyWikiHasOAuth(wikis: Record<string, { oauth2ClientId?: string | null }>): boolean {
3334
return Object.values(wikis).some(

0 commit comments

Comments
 (0)