Skip to content

Commit ae7793e

Browse files
authored
refactor: avoid double JSON parsing (#1917)
1 parent 6d463bb commit ae7793e

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ class RegistrationHandler:
3232
async def handle(self, request: Request) -> Response:
3333
# Implements dynamic client registration as defined in https://datatracker.ietf.org/doc/html/rfc7591#section-3.1
3434
try:
35-
# Parse request body as JSON
36-
# TODO(Marcelo): This is unnecessary. We should use `request.body()`.
37-
body = await request.json()
38-
client_metadata = OAuthClientMetadata.model_validate(body)
35+
body = await request.body()
36+
client_metadata = OAuthClientMetadata.model_validate_json(body)
3937

4038
# Scope validation is handled below
4139
except ValidationError as validation_error:

src/mcp/server/fastmcp/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def __init__(
114114
website_url: str | None = None,
115115
icons: list[Icon] | None = None,
116116
version: str | None = None,
117-
auth_server_provider: (OAuthAuthorizationServerProvider[Any, Any, Any] | None) = None,
117+
auth_server_provider: OAuthAuthorizationServerProvider[Any, Any, Any] | None = None,
118118
token_verifier: TokenVerifier | None = None,
119119
*,
120120
tools: list[Tool] | None = None,
@@ -123,7 +123,7 @@ def __init__(
123123
warn_on_duplicate_resources: bool = True,
124124
warn_on_duplicate_tools: bool = True,
125125
warn_on_duplicate_prompts: bool = True,
126-
lifespan: (Callable[[FastMCP[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None) = None,
126+
lifespan: Callable[[FastMCP[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None = None,
127127
auth: AuthSettings | None = None,
128128
):
129129
self.settings = Settings(

0 commit comments

Comments
 (0)