-
Notifications
You must be signed in to change notification settings - Fork 40
Add server OAuth protection conformance tests #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tobinsouth
wants to merge
11
commits into
modelcontextprotocol:main
Choose a base branch
from
tobinsouth:server-auth
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d7f90be
First pass at adding an auth test scenario (basic) (Opus 4.5)
tobinsouth 636c221
Clarifying the 6-18 spec outline
tobinsouth 5b179d8
Updating spec references with 11-05 CIMD changes (still minimal)
tobinsouth d4db6e7
Adding CIMB and better PRM testing
tobinsouth 3c4fe63
Adding CC in alignment with PR #55
tobinsouth 7b282e2
Lint & prettier
tobinsouth 9ee7bdb
Edited readme
tobinsouth d020ca2
Adding event stream header
tobinsouth 4a8aa8a
README manual review
tobinsouth 0d42ae8
Update metadata discovery for 2025-11-25
nbarbettini 891372b
Merge pull request #1 from nbarbettini/nate/update-tobinsouth-server-…
tobinsouth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| /** | ||
| * Authorization Server Metadata helpers. | ||
| * | ||
| * Provides utilities for fetching and validating AS metadata | ||
| * per RFC 8414 and OIDC Discovery. | ||
| */ | ||
|
|
||
| import { authFetch, buildPrmUrl, AuthTestResult } from './auth-fetch'; | ||
|
|
||
| /** | ||
| * Result of fetching AS metadata. | ||
| */ | ||
| export interface AsMetadataResult { | ||
| /** Whether metadata was successfully fetched */ | ||
| success: boolean; | ||
| /** The AS metadata document if successful */ | ||
| metadata?: Record<string, unknown>; | ||
| /** The URL that was used to fetch metadata */ | ||
| url?: string; | ||
| /** Whether OIDC discovery was used (vs RFC 8414) */ | ||
| isOidc?: boolean; | ||
| /** Error message if fetch failed */ | ||
| error?: string; | ||
| /** The AS URL from PRM */ | ||
| asUrl?: string; | ||
| /** Raw response for debugging */ | ||
| response?: AuthTestResult; | ||
| } | ||
|
|
||
| /** | ||
| * Result of fetching PRM. | ||
| */ | ||
| export interface PrmResult { | ||
| /** Whether PRM was successfully fetched */ | ||
| success: boolean; | ||
| /** The PRM document if successful */ | ||
| prm?: Record<string, unknown>; | ||
| /** The URL that was used to fetch PRM */ | ||
| url?: string; | ||
| /** Error message if fetch failed */ | ||
| error?: string; | ||
| /** Raw response for debugging */ | ||
| response?: AuthTestResult; | ||
| } | ||
|
|
||
| /** | ||
| * Build AS metadata discovery URL. | ||
| */ | ||
| export function buildAsMetadataUrl(asUrl: string, useOidc: boolean): string { | ||
| const parsed = new URL(asUrl); | ||
| const base = `${parsed.protocol}//${parsed.host}`; | ||
|
|
||
| if (useOidc) { | ||
| return `${base}/.well-known/openid-configuration`; | ||
| } | ||
| return `${base}/.well-known/oauth-authorization-server`; | ||
| } | ||
|
|
||
| /** | ||
| * Fetch Protected Resource Metadata from a server. | ||
| */ | ||
| export async function fetchPrm(serverUrl: string): Promise<PrmResult> { | ||
| const pathBasedUrl = buildPrmUrl(serverUrl, true); | ||
| const rootUrl = buildPrmUrl(serverUrl, false); | ||
|
|
||
| // Try path-based first | ||
| try { | ||
| const response = await authFetch(pathBasedUrl); | ||
| if ( | ||
| response.status === 200 && | ||
| typeof response.body === 'object' && | ||
| response.body !== null | ||
| ) { | ||
| return { | ||
| success: true, | ||
| prm: response.body as Record<string, unknown>, | ||
| url: pathBasedUrl, | ||
| response | ||
| }; | ||
| } | ||
| } catch { | ||
| // Will try root | ||
| } | ||
|
|
||
| // Try root | ||
| if (pathBasedUrl !== rootUrl) { | ||
| try { | ||
| const response = await authFetch(rootUrl); | ||
| if ( | ||
| response.status === 200 && | ||
| typeof response.body === 'object' && | ||
| response.body !== null | ||
| ) { | ||
| return { | ||
| success: true, | ||
| prm: response.body as Record<string, unknown>, | ||
| url: rootUrl, | ||
| response | ||
| }; | ||
| } | ||
| } catch { | ||
| // Both failed | ||
| } | ||
| } | ||
|
|
||
| return { | ||
| success: false, | ||
| error: `No valid PRM found at ${pathBasedUrl} or ${rootUrl}` | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Fetch Authorization Server metadata from the AS referenced in PRM. | ||
| * | ||
| * @param serverUrl - The MCP server URL | ||
| * @returns AS metadata result | ||
| */ | ||
| export async function fetchAsMetadata( | ||
| serverUrl: string | ||
| ): Promise<AsMetadataResult> { | ||
| // First fetch PRM | ||
| const prmResult = await fetchPrm(serverUrl); | ||
|
|
||
| if (!prmResult.success || !prmResult.prm) { | ||
| return { | ||
| success: false, | ||
| error: prmResult.error || 'Failed to fetch PRM' | ||
| }; | ||
| } | ||
|
|
||
| const authServers = prmResult.prm.authorization_servers as | ||
| | string[] | ||
| | undefined; | ||
|
|
||
| if (!Array.isArray(authServers) || authServers.length === 0) { | ||
| return { | ||
| success: false, | ||
| error: 'PRM missing authorization_servers array' | ||
| }; | ||
| } | ||
|
|
||
| const asUrl = authServers[0]; | ||
|
|
||
| // Try RFC 8414 first | ||
| const rfc8414Url = buildAsMetadataUrl(asUrl, false); | ||
| try { | ||
| const response = await authFetch(rfc8414Url); | ||
| if ( | ||
| response.status === 200 && | ||
| typeof response.body === 'object' && | ||
| response.body !== null | ||
| ) { | ||
| return { | ||
| success: true, | ||
| metadata: response.body as Record<string, unknown>, | ||
| url: rfc8414Url, | ||
| isOidc: false, | ||
| asUrl, | ||
| response | ||
| }; | ||
| } | ||
| } catch { | ||
| // Will try OIDC | ||
| } | ||
|
|
||
| // Try OIDC Discovery | ||
| const oidcUrl = buildAsMetadataUrl(asUrl, true); | ||
| try { | ||
| const response = await authFetch(oidcUrl); | ||
| if ( | ||
| response.status === 200 && | ||
| typeof response.body === 'object' && | ||
| response.body !== null | ||
| ) { | ||
| return { | ||
| success: true, | ||
| metadata: response.body as Record<string, unknown>, | ||
| url: oidcUrl, | ||
| isOidc: true, | ||
| asUrl, | ||
| response | ||
| }; | ||
| } | ||
| } catch { | ||
| // Both failed | ||
| } | ||
|
|
||
| return { | ||
| success: false, | ||
| error: `No AS metadata found at ${rfc8414Url} or ${oidcUrl}`, | ||
| asUrl | ||
| }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.