|
1 | 1 | import logging |
2 | 2 | from dataclasses import dataclass |
3 | 3 | from typing import Any, Literal |
4 | | -from urllib.parse import urlencode, urlparse, urlunparse |
5 | 4 |
|
6 | 5 | from pydantic import AnyHttpUrl, AnyUrl, BaseModel, Field, RootModel, ValidationError |
7 | 6 | from starlette.datastructures import FormData, QueryParams |
8 | 7 | from starlette.requests import Request |
9 | 8 | from starlette.responses import RedirectResponse, Response |
10 | 9 |
|
11 | 10 | from mcp.server.auth.errors import ( |
12 | | - OAuthError, |
13 | 11 | stringify_pydantic_error, |
14 | 12 | ) |
15 | 13 | from mcp.server.auth.json_response import PydanticJSONResponse |
@@ -225,34 +223,3 @@ async def error_response( |
225 | 223 | return await error_response( |
226 | 224 | error="server_error", error_description="An unexpected error occurred" |
227 | 225 | ) |
228 | | - |
229 | | - |
230 | | -def create_error_redirect( |
231 | | - redirect_uri: AnyUrl, error: Exception | AuthorizationErrorResponse |
232 | | -) -> str: |
233 | | - parsed_uri = urlparse(str(redirect_uri)) |
234 | | - |
235 | | - if isinstance(error, AuthorizationErrorResponse): |
236 | | - # Convert ErrorResponse to dict |
237 | | - error_dict = error.model_dump(exclude_none=True) |
238 | | - query_params = {} |
239 | | - for key, value in error_dict.items(): |
240 | | - if value is not None: |
241 | | - if key == "error_uri" and hasattr(value, "__str__"): |
242 | | - query_params[key] = str(value) |
243 | | - else: |
244 | | - query_params[key] = value |
245 | | - |
246 | | - elif isinstance(error, OAuthError): |
247 | | - query_params = {"error": error.error_code, "error_description": str(error)} |
248 | | - else: |
249 | | - query_params = { |
250 | | - "error": "server_error", |
251 | | - "error_description": "An unknown error occurred", |
252 | | - } |
253 | | - |
254 | | - new_query = urlencode(query_params) |
255 | | - if parsed_uri.query: |
256 | | - new_query = f"{parsed_uri.query}&{new_query}" |
257 | | - |
258 | | - return urlunparse(parsed_uri._replace(query=new_query)) |
0 commit comments