o
    c۷i(                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZmZ d dlmZ d dlmZmZ G dd de
e ZG dd de	ZeG dd dZdS )    N)	dataclass)Any)uuid4)	BaseModel	RootModelValidationError)Request)Response)stringify_pydantic_error)PydanticJSONResponse) OAuthAuthorizationServerProviderRegistrationErrorRegistrationErrorCode)ClientRegistrationOptions)OAuthClientInformationFullOAuthClientMetadatac                   @   s   e Zd ZU eed< dS )RegistrationRequestrootN)__name__
__module____qualname__r   __annotations__ r   r   W/home/ubuntu/vllm_env/lib/python3.10/site-packages/mcp/server/auth/handlers/register.pyr      s   
 r   c                   @   s"   e Zd ZU eed< edB ed< dS )RegistrationErrorResponseerrorNerror_description)r   r   r   r   r   strr   r   r   r   r      s   
 r   c                   @   s:   e Zd ZU eeeef ed< eed< dedefddZ	dS )RegistrationHandlerprovideroptionsrequestreturnc              
      s|  z|  I d H }t|}W n ty- } zttdt|dddW  Y d }~S d }~ww tt }|j	d u r;d|_	d }|j	dkrGt
d}|jd u r[| jjd ur[d| jj|_n/|jd ur| jjd urt|j }t| jj}||sttdd	d
||  dddS ddht|jsttdddddS d|jvrttdddddS tt }	| jjd ur|	| jj nd }
td$i d|d|	d|d|
d|jd|j	d|jd|jd|jd|jd|jd|jd|jd|jd|j d|j!d |j"d!|j#d"|j$}z| j%&|I d H  t|d#dW S  t'y= } ztt|j(|j)dddW  Y d }~S d }~ww )%Ninvalid_client_metadata)r   r   i  )contentstatus_codeclient_secret_postnone     z Requested scopes are not valid: z, authorization_coderefresh_tokenz8grant_types must be authorization_code and refresh_tokencodez?response_types must include 'code' for authorization_code grant	client_idclient_id_issued_atclient_secretclient_secret_expires_atredirect_uristoken_endpoint_auth_methodgrant_typesresponse_typesclient_name
client_urilogo_uriscopecontactstos_uri
policy_urijwks_urijwkssoftware_idsoftware_version   r   )*jsonr   model_validater   r   r   r
   r   r   r2   secrets	token_hexr8   r    default_scopesjoinvalid_scopessetsplitissubsetr3   r4   inttimeclient_secret_expiry_secondsr   r1   r5   r6   r7   r9   r:   r;   r<   r=   r>   r?   r   register_clientr   r   r   )selfr!   bodyclient_metadatavalidation_errorr-   r/   requested_scopesrG   r.   r0   client_infoer   r   r   handle"   s   
	





	
zRegistrationHandler.handleN)
r   r   r   r   r   r   r   r   r	   rV   r   r   r   r   r      s   
 r   ) rC   rL   dataclassesr   typingr   uuidr   pydanticr   r   r   starlette.requestsr   starlette.responsesr	   mcp.server.auth.errorsr
   mcp.server.auth.json_responser   mcp.server.auth.providerr   r   r   mcp.server.auth.settingsr   mcp.shared.authr   r   r   r   r   r   r   r   r   <module>   s"    