Skip to content

Support Cursor OAuth client registration #895

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
merged 1 commit into from
Jun 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/mcp/server/auth/handlers/authorize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dataclasses import dataclass
from typing import Any, Literal

from pydantic import AnyHttpUrl, AnyUrl, BaseModel, Field, RootModel, ValidationError
from pydantic import AnyUrl, BaseModel, Field, RootModel, ValidationError
from starlette.datastructures import FormData, QueryParams
from starlette.requests import Request
from starlette.responses import RedirectResponse, Response
Expand All @@ -29,7 +29,7 @@
class AuthorizationRequest(BaseModel):
# See https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1
client_id: str = Field(..., description="The client ID")
redirect_uri: AnyHttpUrl | None = Field(
redirect_uri: AnyUrl | None = Field(
None, description="URL to redirect to after authorization"
)

Expand Down Expand Up @@ -68,8 +68,8 @@ def best_effort_extract_string(
return None


class AnyHttpUrlModel(RootModel[AnyHttpUrl]):
root: AnyHttpUrl
class AnyUrlModel(RootModel[AnyUrl]):
root: AnyUrl


@dataclass
Expand Down Expand Up @@ -116,7 +116,7 @@ async def error_response(
if params is not None and "redirect_uri" not in params:
raw_redirect_uri = None
else:
raw_redirect_uri = AnyHttpUrlModel.model_validate(
raw_redirect_uri = AnyUrlModel.model_validate(
best_effort_extract_string("redirect_uri", params)
).root
redirect_uri = client.validate_redirect_uri(raw_redirect_uri)
Expand Down
4 changes: 2 additions & 2 deletions src/mcp/server/auth/handlers/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dataclasses import dataclass
from typing import Annotated, Any, Literal

from pydantic import AnyHttpUrl, BaseModel, Field, RootModel, ValidationError
from pydantic import AnyHttpUrl, AnyUrl, BaseModel, Field, RootModel, ValidationError
from starlette.requests import Request

from mcp.server.auth.errors import (
Expand All @@ -27,7 +27,7 @@ class AuthorizationCodeRequest(BaseModel):
# See https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3
grant_type: Literal["authorization_code"]
code: str = Field(..., description="The authorization code")
redirect_uri: AnyHttpUrl | None = Field(
redirect_uri: AnyUrl | None = Field(
None, description="Must be the same as redirect URI provided in /authorize"
)
client_id: str
Expand Down
6 changes: 3 additions & 3 deletions src/mcp/server/auth/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Generic, Literal, Protocol, TypeVar
from urllib.parse import parse_qs, urlencode, urlparse, urlunparse

from pydantic import AnyHttpUrl, BaseModel
from pydantic import AnyUrl, BaseModel

from mcp.shared.auth import (
OAuthClientInformationFull,
Expand All @@ -14,7 +14,7 @@ class AuthorizationParams(BaseModel):
state: str | None
scopes: list[str] | None
code_challenge: str
redirect_uri: AnyHttpUrl
redirect_uri: AnyUrl
redirect_uri_provided_explicitly: bool


Expand All @@ -24,7 +24,7 @@ class AuthorizationCode(BaseModel):
expires_at: float
client_id: str
code_challenge: str
redirect_uri: AnyHttpUrl
redirect_uri: AnyUrl
redirect_uri_provided_explicitly: bool


Expand Down
6 changes: 3 additions & 3 deletions src/mcp/shared/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Literal

from pydantic import AnyHttpUrl, BaseModel, Field
from pydantic import AnyHttpUrl, AnyUrl, BaseModel, Field


class OAuthToken(BaseModel):
Expand Down Expand Up @@ -32,7 +32,7 @@ class OAuthClientMetadata(BaseModel):
for the full specification.
"""

redirect_uris: list[AnyHttpUrl] = Field(..., min_length=1)
redirect_uris: list[AnyUrl] = Field(..., min_length=1)
# token_endpoint_auth_method: this implementation only supports none &
# client_secret_post;
# ie: we do not support client_secret_basic
Expand Down Expand Up @@ -71,7 +71,7 @@ def validate_scope(self, requested_scope: str | None) -> list[str] | None:
raise InvalidScopeError(f"Client was not registered with scope {scope}")
return requested_scopes

def validate_redirect_uri(self, redirect_uri: AnyHttpUrl | None) -> AnyHttpUrl:
def validate_redirect_uri(self, redirect_uri: AnyUrl | None) -> AnyUrl:
if redirect_uri is not None:
# Validate redirect_uri against client's registered redirect URIs
if redirect_uri not in self.redirect_uris:
Expand Down
6 changes: 3 additions & 3 deletions tests/client/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import httpx
import pytest
from inline_snapshot import snapshot
from pydantic import AnyHttpUrl
from pydantic import AnyHttpUrl, AnyUrl

from mcp.client.auth import OAuthClientProvider
from mcp.server.auth.routes import build_metadata
Expand Down Expand Up @@ -52,7 +52,7 @@ def mock_storage():
@pytest.fixture
def client_metadata():
return OAuthClientMetadata(
redirect_uris=[AnyHttpUrl("http://localhost:3000/callback")],
redirect_uris=[AnyUrl("http://localhost:3000/callback")],
client_name="Test Client",
grant_types=["authorization_code", "refresh_token"],
response_types=["code"],
Expand All @@ -79,7 +79,7 @@ def oauth_client_info():
return OAuthClientInformationFull(
client_id="test_client_id",
client_secret="test_client_secret",
redirect_uris=[AnyHttpUrl("http://localhost:3000/callback")],
redirect_uris=[AnyUrl("http://localhost:3000/callback")],
client_name="Test Client",
grant_types=["authorization_code", "refresh_token"],
response_types=["code"],
Expand Down
Loading