Skip to content

Commit 9439a4c

Browse files
committed
more cleanup
1 parent 429c28f commit 9439a4c

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ async def authorize(
127127
}
128128

129129
consent_url = f"{self.settings.server_url}consent?{urlencode(consent_params)}"
130-
print(f"[DEBUGG] {consent_url} {state}")
131-
132130
return consent_url
133131

134132
async def handle_github_callback(self, code: str, state: str) -> str:
@@ -277,10 +275,15 @@ async def revoke_token(
277275
del self.tokens[token]
278276

279277

280-
@dataclass
281278
class ConsentHandler:
282-
provider: OAuthAuthorizationServerProvider[Any, Any, Any]
283-
settings: ServerSettings
279+
280+
281+
282+
def __init__(self, provider: SimpleGitHubOAuthProvider, settings: ServerSettings, path: str):
283+
self.provider: SimpleGitHubOAuthProvider = provider
284+
self.settings: ServerSettings = settings
285+
self.client_consent: dict[str, bool] = {}
286+
self.path = path
284287

285288
async def handle(self, request: Request) -> Response:
286289
# This handles both showing the consent form (GET) and processing consent (POST)
@@ -308,11 +311,11 @@ async def _show_consent_form(self, request: Request) -> HTMLResponse:
308311
if client and hasattr(client, 'client_name'):
309312
client_name = client.client_name
310313

311-
# TODO: get this passed in
312-
target_url = "/consent"
314+
target_url = self.path
313315

314-
# Create a simple consent form
316+
# TODO: allow skipping consent if we've already approved this client ID
315317

318+
# Create a simple consent form
316319
html_content = f"""
317320
<!DOCTYPE html>
318321
<html>
@@ -436,9 +439,7 @@ async def _process_consent(self, request: Request) -> RedirectResponse | HTMLRes
436439
if client_id:
437440
client = await self.provider.get_client(client_id)
438441
if client:
439-
# TODO: move this out of provider
440-
await self.provider.grant_client_consent(client)
441-
442+
self.client_consent[client.client_id] = True
442443

443444
auth_url = (
444445
f"{self.settings.github_auth_url}"
@@ -505,8 +506,6 @@ def create_simple_mcp_server(settings: ServerSettings) -> FastMCP:
505506
enabled=True,
506507
valid_scopes=[settings.mcp_scope],
507508
default_scopes=[settings.mcp_scope],
508-
# Turning off consent since we'll handle it via custom endpoint
509-
client_consent_required=False
510509
),
511510
required_scopes=[settings.mcp_scope],
512511
)
@@ -521,9 +520,10 @@ def create_simple_mcp_server(settings: ServerSettings) -> FastMCP:
521520
auth=auth_settings,
522521
)
523522

524-
consent_handler = ConsentHandler(provider=oauth_provider, settings=settings)
523+
consent_path = "/consent"
524+
consent_handler = ConsentHandler(provider=oauth_provider, settings=settings, path=consent_path)
525525

526-
@app.custom_route("/consent", methods=["GET", "POST"])
526+
@app.custom_route(consent_path, methods=["GET", "POST"])
527527
async def example_consent_handler(request: Request) -> Response:
528528
return await consent_handler.handle(request)
529529

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

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import logging
22
from dataclasses import dataclass
33
from typing import Any, Literal
4-
from urllib.parse import urlencode
54

65
from pydantic import AnyHttpUrl, AnyUrl, BaseModel, Field, RootModel, ValidationError
76
from starlette.datastructures import FormData, QueryParams

src/mcp/server/auth/routes.py

-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from starlette.types import ASGIApp
1010

1111
from mcp.server.auth.handlers.authorize import AuthorizationHandler
12-
from mcp.server.auth.handlers.consent import ConsentHandler
1312
from mcp.server.auth.handlers.metadata import MetadataHandler
1413
from mcp.server.auth.handlers.register import RegistrationHandler
1514
from mcp.server.auth.handlers.revoke import RevocationHandler
@@ -50,7 +49,6 @@ def validate_issuer_url(url: AnyHttpUrl):
5049
TOKEN_PATH = "/token"
5150
REGISTRATION_PATH = "/register"
5251
REVOCATION_PATH = "/revoke"
53-
CONSENT_PATH = "/consent"
5452

5553

5654
def cors_middleware(

0 commit comments

Comments
 (0)