Skip to content

Commit 53431b8

Browse files
committed
make issuer_url auth server and add resource_server_url param
1 parent a024ca8 commit 53431b8

File tree

6 files changed

+21
-20
lines changed

6 files changed

+21
-20
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ mcp = FastMCP(
444444
"My App",
445445
token_verifier=MyTokenVerifier(),
446446
auth=AuthSettings(
447-
authorization_servers=["https://auth.example.com"],
447+
issuer_url="https://auth.example.com"
448+
resource_server_url="http://localhost:3001",
448449
required_scopes=["mcp:read", "mcp:write"],
449450
),
450451
)

examples/servers/simple-auth/mcp_simple_auth/auth_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def create_authorization_server(server_settings: AuthServerSettings, github_sett
6868
default_scopes=[github_settings.mcp_scope],
6969
),
7070
required_scopes=[github_settings.mcp_scope],
71-
authorization_servers=None,
71+
resource_server_url=None,
7272
)
7373

7474
# Create OAuth routes

examples/servers/simple-auth/mcp_simple_auth/legacy_as_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ def create_simple_mcp_server(server_settings: ServerSettings, github_settings: G
5959
default_scopes=[github_settings.mcp_scope],
6060
),
6161
required_scopes=[github_settings.mcp_scope],
62-
# No authorization_servers parameter in legacy mode
63-
authorization_servers=None,
62+
# No resource_server_url parameter in legacy mode
63+
resource_server_url=None,
6464
)
6565

6666
app = FastMCP(

examples/servers/simple-auth/mcp_simple_auth/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ def create_resource_server(settings: ResourceServerSettings) -> FastMCP:
7070
# Auth configuration for RS mode
7171
token_verifier=token_verifier,
7272
auth=AuthSettings(
73-
issuer_url=settings.server_url,
73+
issuer_url=settings.auth_server_url,
7474
required_scopes=[settings.mcp_scope],
75-
authorization_servers=[settings.auth_server_url],
75+
resource_server_url=settings.server_url,
7676
),
7777
)
7878

src/mcp/server/auth/settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class RevocationOptions(BaseModel):
1515
class AuthSettings(BaseModel):
1616
issuer_url: AnyHttpUrl = Field(
1717
...,
18-
description="Base URL where this server is reachable. For AS: OAuth issuer URL. For RS: Resource server URL.",
18+
description="OAuth authorization server URL that issues tokens for this resource server.",
1919
)
2020
service_documentation_url: AnyHttpUrl | None = None
2121
client_registration_options: ClientRegistrationOptions | None = None
2222
revocation_options: RevocationOptions | None = None
2323
required_scopes: list[str] | None = None
2424

2525
# Resource Server settings (when operating as RS only)
26-
authorization_servers: list[AnyHttpUrl] | None = Field(
27-
None,
28-
description="Authorization servers that can issue tokens for this resource (RS mode)",
26+
resource_server_url: AnyHttpUrl | None = Field(
27+
...,
28+
description="OAuth authorization server URL that issues tokens for this resource server.",
2929
)

src/mcp/server/fastmcp/server.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -743,11 +743,11 @@ async def handle_sse(scope: Scope, receive: Receive, send: Send):
743743
if self._token_verifier:
744744
# Determine resource metadata URL
745745
resource_metadata_url = None
746-
if self.settings.auth and self.settings.auth.authorization_servers:
746+
if self.settings.auth and self.settings.auth.resource_server_url:
747747
from pydantic import AnyHttpUrl
748748

749749
resource_metadata_url = AnyHttpUrl(
750-
str(self.settings.auth.issuer_url).rstrip("/") + "/.well-known/oauth-protected-resource"
750+
str(self.settings.auth.resource_server_url).rstrip("/") + "/.well-known/oauth-protected-resource"
751751
)
752752

753753
# Auth is enabled, wrap the endpoints with RequireAuthMiddleware
@@ -785,13 +785,13 @@ async def sse_endpoint(request: Request) -> Response:
785785
)
786786
)
787787
# Add protected resource metadata endpoint if configured as RS
788-
if self.settings.auth and self.settings.auth.authorization_servers:
788+
if self.settings.auth and self.settings.auth.resource_server_url:
789789
from mcp.server.auth.routes import create_protected_resource_routes
790790

791791
routes.extend(
792792
create_protected_resource_routes(
793-
resource_url=self.settings.auth.issuer_url,
794-
authorization_servers=self.settings.auth.authorization_servers,
793+
resource_url=self.settings.auth.resource_server_url,
794+
authorization_servers=[self.settings.auth.issuer_url],
795795
scopes_supported=self.settings.auth.required_scopes,
796796
)
797797
)
@@ -858,11 +858,11 @@ async def handle_streamable_http(scope: Scope, receive: Receive, send: Send) ->
858858
if self._token_verifier:
859859
# Determine resource metadata URL
860860
resource_metadata_url = None
861-
if self.settings.auth and self.settings.auth.authorization_servers:
861+
if self.settings.auth and self.settings.auth.resource_server_url:
862862
from pydantic import AnyHttpUrl
863863

864864
resource_metadata_url = AnyHttpUrl(
865-
str(self.settings.auth.issuer_url).rstrip("/") + "/.well-known/oauth-protected-resource"
865+
str(self.settings.auth.resource_server_url).rstrip("/") + "/.well-known/oauth-protected-resource"
866866
)
867867

868868
routes.append(
@@ -881,14 +881,14 @@ async def handle_streamable_http(scope: Scope, receive: Receive, send: Send) ->
881881
)
882882

883883
# Add protected resource metadata endpoint if configured as RS
884-
if self.settings.auth and self.settings.auth.authorization_servers:
884+
if self.settings.auth and self.settings.auth.resource_server_url:
885885
from mcp.server.auth.handlers.metadata import ProtectedResourceMetadataHandler
886886
from mcp.server.auth.routes import cors_middleware
887887
from mcp.shared.auth import ProtectedResourceMetadata
888888

889889
protected_resource_metadata = ProtectedResourceMetadata(
890-
resource=self.settings.auth.issuer_url,
891-
authorization_servers=self.settings.auth.authorization_servers,
890+
resource=self.settings.auth.resource_server_url,
891+
authorization_servers=[self.settings.auth.issuer_url],
892892
scopes_supported=self.settings.auth.required_scopes,
893893
)
894894
routes.append(

0 commit comments

Comments
 (0)