Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Clean up code for creating the resource url (#1916)

Jeremiah Lowinfccd08175868
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):