- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.7k
Add test for ProtectedResourceMetadataParsing #1236
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
          
     Merged
      
      
            pcarleton
  merged 21 commits into
  modelcontextprotocol:main
from
yannj-fr:feature/expose-protected-resource-metadata
  
      
      
   
  Sep 23, 2025 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            21 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f348481
              
                Improved supported for ProtectedResourceMetadata
              
              
                yannj-fr 39e7576
              
                formatting
              
              
                pcarleton e3c1eef
              
                Add test for ProtectedResourceMetadata parsing
              
              
                yannj-fr e4de61b
              
                typo fix
              
              
                yannj-fr 2b5cc94
              
                Merge branch 'main' into feature/expose-protected-resource-metadata
              
              
                yannj-fr 12eddcc
              
                fix precommit hook
              
              
                yannj-fr e8bfe35
              
                Update tests/shared/test_auth.py
              
              
                yannj-fr 79e1b16
              
                Update tests/shared/test_auth.py
              
              
                yannj-fr 0967a9e
              
                Merge branch 'main' into feature/expose-protected-resource-metadata
              
              
                Kludex 32151a6
              
                Add test for protected resources through .well-known/oauth-protected-…
              
              
                yannj-fr dd22d76
              
                remove prints in the entire file
              
              
                yannj-fr 149f752
              
                remove prints and change test class, use snapshot
              
              
                yannj-fr 1fea1f3
              
                removing uneeded assert on response code
              
              
                yannj-fr 154b754
              
                separate test in a new file
              
              
                yannj-fr 69238ad
              
                fix pre check commit
              
              
                yannj-fr 23fa8d4
              
                Merge branch 'main' into feature/expose-protected-resource-metadata
              
              
                yannj-fr 82852be
              
                Update tests/server/auth/test_protected_resource.py
              
              
                yannj-fr 0826232
              
                Update tests/server/auth/test_protected_resource.py
              
              
                yannj-fr 0b800fe
              
                remove uneeded test and rename methods
              
              
                yannj-fr f791a82
              
                Merge branch 'main' into feature/expose-protected-resource-metadata
              
              
                yannj-fr 1994475
              
                Merge branch 'main' into feature/expose-protected-resource-metadata
              
              
                felixweinberger 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """ | ||
| Integration tests for MCP Oauth Protected Resource. | ||
| """ | ||
|  | ||
| import httpx | ||
| import pytest | ||
| from inline_snapshot import snapshot | ||
| from pydantic import AnyHttpUrl | ||
| from starlette.applications import Starlette | ||
|  | ||
| from mcp.server.auth.routes import create_protected_resource_routes | ||
|  | ||
|  | ||
| @pytest.fixture | ||
| def test_app(): | ||
| """Fixture to create protected resource routes for testing.""" | ||
|  | ||
| # Create the protected resource routes | ||
| protected_resource_routes = create_protected_resource_routes( | ||
| resource_url=AnyHttpUrl("https://example.com/resource"), | ||
| authorization_servers=[AnyHttpUrl("https://auth.example.com/authorization")], | ||
| scopes_supported=["read", "write"], | ||
| resource_name="Example Resource", | ||
| resource_documentation=AnyHttpUrl("https://docs.example.com/resource"), | ||
| ) | ||
|  | ||
| app = Starlette(routes=protected_resource_routes) | ||
| return app | ||
|  | ||
|  | ||
| @pytest.fixture | ||
| async def test_client(test_app: Starlette): | ||
| """Fixture to create an HTTP client for the protected resource app.""" | ||
| async with httpx.AsyncClient(transport=httpx.ASGITransport(app=test_app), base_url="https://mcptest.com") as client: | ||
| yield client | ||
|  | ||
|  | ||
| @pytest.mark.anyio | ||
| async def test_metadata_endpoint(test_client: httpx.AsyncClient): | ||
| """Test the OAuth 2.0 Protected Resource metadata endpoint.""" | ||
|  | ||
| response = await test_client.get("/.well-known/oauth-protected-resource") | ||
| assert response.json() == snapshot( | ||
| { | ||
| "resource": "https://example.com/resource", | ||
| "authorization_servers": ["https://auth.example.com/authorization"], | ||
| "scopes_supported": ["read", "write"], | ||
| "resource_name": "Example Resource", | ||
| "resource_documentation": "https://docs.example.com/resource", | ||
| "bearer_methods_supported": ["header"], | ||
| } | ||
| ) | 
  
    
      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
    
  
  
    
              
      
      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.