Skip to content

Commit 76e31d4

Browse files
praboud-antdsp-ant
authored andcommitted
Lint
1 parent 3968f86 commit 76e31d4

File tree

8 files changed

+36
-20
lines changed

8 files changed

+36
-20
lines changed

src/mcp/server/auth/handlers/token.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ async def token_handler(request: Request):
5555
client_info = await client_authenticator(token_request)
5656

5757
if token_request.grant_type not in client_info.grant_types:
58-
raise InvalidRequestError(f"Unsupported grant type (supported grant types are {client_info.grant_types})")
58+
raise InvalidRequestError(
59+
f"Unsupported grant type (supported grant types are "
60+
f"{client_info.grant_types})"
61+
)
5962

6063
tokens: OAuthTokens
6164

src/mcp/server/auth/middleware/client_auth.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class ClientAuthRequest(BaseModel):
2222
"""
2323
Model for client authentication request body.
2424
25-
Corresponds to ClientAuthenticatedRequestSchema in src/server/auth/middleware/clientAuth.ts
25+
Corresponds to ClientAuthenticatedRequestSchema in
26+
src/server/auth/middleware/clientAuth.ts
2627
"""
2728

2829
client_id: str
@@ -31,12 +32,14 @@ class ClientAuthRequest(BaseModel):
3132

3233
class ClientAuthenticator:
3334
"""
34-
ClientAuthenticator is a callable which validates requests from a client application,
35+
ClientAuthenticator is a callable which validates requests from a client
36+
application,
3537
used to verify /token and /revoke calls.
36-
If, during registration, the client requested to be issued a secret, the authenticator
37-
asserts that /token and /register calls must be authenticated with that same token.
38-
NOTE: clients can opt for no authentication during registration, in which case this logic
39-
is skipped.
38+
If, during registration, the client requested to be issued a secret, the
39+
authenticator asserts that /token and /register calls must be authenticated with
40+
that same token.
41+
NOTE: clients can opt for no authentication during registration, in which case this
42+
logic is skipped.
4043
"""
4144
def __init__(self, clients_store: OAuthRegisteredClientsStore):
4245
"""
@@ -53,7 +56,8 @@ async def __call__(self, request: ClientAuthRequest) -> OAuthClientInformationFu
5356
if not client:
5457
raise InvalidClientError("Invalid client_id")
5558

56-
# If client from the store expects a secret, validate that the request provides that secret
59+
# If client from the store expects a secret, validate that the request provides
60+
# that secret
5761
if client.client_secret:
5862
if not request.client_secret:
5963
raise InvalidClientError("Client secret is required")

src/mcp/server/auth/provider.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ async def create_authorization_code(
8181
self, client: OAuthClientInformationFull, params: AuthorizationParams
8282
) -> str:
8383
"""
84-
Generates and stores an authorization code as part of completing the /authorize OAuth step.
84+
Generates and stores an authorization code as part of completing the /authorize
85+
OAuth step.
8586
86-
Implementations SHOULD generate an authorization code with at least 160 bits of entropy,
87+
Implementations SHOULD generate an authorization code with at least 160 bits of
88+
entropy,
8789
and MUST generate an authorization code with at least 128 bits of entropy.
8890
See https://datatracker.ietf.org/doc/html/rfc6749#section-10.10.
8991
"""

src/mcp/server/fastmcp/server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ def starlette_app(self) -> Starlette:
494494

495495
async def handle_sse(request) -> EventSourceResponse:
496496
# Add client ID from auth context into request context if available
497-
request_meta = {}
498497

499498
async with sse.connect_sse(
500499
request.scope, request.receive, request._send

src/mcp/server/sse.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ async def sse_writer():
132132
logger.debug("Yielding read and write streams")
133133
# TODO: hold on; shouldn't we be returning the EventSourceResponse?
134134
# I think this is why the tests hang
135-
# TODO: we probably shouldn't return response here, since it's a breaking change
135+
# TODO: we probably shouldn't return response here, since it's a breaking
136+
# change
136137
# this is just to test
137138
yield (read_stream, write_stream, response)
138139

src/mcp/shared/auth.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,20 @@ class OAuthClientMetadata(BaseModel):
4343
"""
4444

4545
redirect_uris: List[AnyHttpUrl] = Field(..., min_length=1)
46-
# token_endpoint_auth_method: this implementation only supports none & client_secret_basic;
46+
# token_endpoint_auth_method: this implementation only supports none &
47+
# client_secret_basic;
4748
# ie: we do not support client_secret_post
48-
token_endpoint_auth_method: Literal["none", "client_secret_basic"] = "client_secret_basic"
49+
token_endpoint_auth_method: Literal["none", "client_secret_basic"] = \
50+
"client_secret_basic"
4951
# grant_types: this implementation only supports authorization_code & refresh_token
50-
grant_types: List[Literal["authorization_code", "refresh_token"]] = ["authorization_code"]
52+
grant_types: List[Literal["authorization_code", "refresh_token"]] = \
53+
["authorization_code"]
5154
# this implementation only supports code; ie: it does not support implicit grants
5255
response_types: List[Literal["code"]] = ["code"]
5356
scope: Optional[str] = None
5457

55-
# these fields are currently unused, but we support & store them for potential future use
58+
# these fields are currently unused, but we support & store them for potential
59+
# future use
5660
client_name: Optional[str] = None
5761
client_uri: Optional[AnyHttpUrl] = None
5862
logo_uri: Optional[AnyHttpUrl] = None

tests/server/fastmcp/auth/streaming_asgi_transport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ async def process_messages() -> None:
161161
response_complete.set()
162162

163163
# Create tasks for running the app and processing messages
164-
app_task = asyncio.create_task(run_app())
165-
process_task = asyncio.create_task(process_messages())
164+
asyncio.create_task(run_app())
165+
asyncio.create_task(process_messages())
166166

167167
# Wait for the initial response or timeout
168168
await initial_response_ready.wait()

tests/server/fastmcp/auth/test_auth_integration.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ async def test_client_registration(
324324
assert client_info["redirect_uris"] == ["https://client.example.com/callback"]
325325

326326
# Verify that the client was registered
327-
# assert await mock_oauth_provider.clients_store.get_client(client_info["client_id"]) is not None
327+
# assert await mock_oauth_provider.clients_store.get_client(
328+
# client_info["client_id"]
329+
# ) is not None
328330

329331
@pytest.mark.anyio
330332
async def test_authorization_flow(
@@ -553,7 +555,8 @@ def test_tool(x: int) -> str:
553555
assert sse.data.startswith("/messages/?session_id=")
554556
messages_uri = sse.data
555557

556-
# verify that we can now post to the /messages endpoint, and get a response on the /sse endpoint
558+
# verify that we can now post to the /messages endpoint, and get a response
559+
# on the /sse endpoint
557560
response = await test_client.post(
558561
messages_uri,
559562
headers={"Authorization": authorization},

0 commit comments

Comments
 (0)