From fccd08175868be5090470df2b5e82d59702d4a46 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Thu, 25 Sep 2025 10:42:57 -0400 Subject: [PATCH] Clean up code for creating the resource url (#1916) --- src/fastmcp/server/auth/auth.py | 5 +++-- tests/server/auth/test_remote_auth_provider.py | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/fastmcp/server/auth/auth.py b/src/fastmcp/server/auth/auth.py index 6c2eafc30..e67928651 100644 --- a/src/fastmcp/server/auth/auth.py +++ b/src/fastmcp/server/auth/auth.py @@ -1,7 +1,6 @@ from __future__ import annotations from typing import Any -from urllib.parse import urljoin from mcp.server.auth.middleware.auth_context import AuthContextMiddleware from mcp.server.auth.middleware.bearer_auth import ( @@ -146,7 +145,9 @@ class AuthProvider(TokenVerifierProtocol): return None if path: - return AnyHttpUrl(f"{str(self.base_url).rstrip('/')}/{path.lstrip('/')}") + prefix = str(self.base_url).rstrip("/") + suffix = path.lstrip("/") + return AnyHttpUrl(f"{prefix}/{suffix}") return self.base_url diff --git a/tests/server/auth/test_remote_auth_provider.py b/tests/server/auth/test_remote_auth_provider.py index a5d435641..eedb871b3 100644 --- a/tests/server/auth/test_remote_auth_provider.py +++ b/tests/server/auth/test_remote_auth_provider.py @@ -239,7 +239,6 @@ class TestRemoteAuthProviderIntegration: ("https://api.example.com", "https://api.example.com/mcp"), ("https://api.example.com/", "https://api.example.com/mcp"), ("https://api.example.com/v1/", "https://api.example.com/v1/mcp"), - ], ) async def test_base_url_configurations(self, base_url: str, expected_resource: str):