@@ -128,37 +128,42 @@ def experimental(self) -> ExperimentalServerSessionFeatures:
128128
129129 def check_client_capability (self , capability : types .ClientCapabilities ) -> bool :
130130 """Check if the client supports a specific capability."""
131- if self ._client_params is None : # pragma: lax no cover
131+ if self ._client_params is None :
132132 return False
133133
134134 client_caps = self ._client_params .capabilities
135135
136- if capability .roots is not None : # pragma: lax no cover
137- if client_caps .roots is None :
138- return False
139- if capability .roots .list_changed and not client_caps .roots .list_changed :
140- return False
136+ # Check roots capability
137+ if capability .roots and not client_caps .roots :
138+ return False
139+ if (capability .roots and capability .roots .list_changed and
140+ client_caps .roots and not client_caps .roots .list_changed ):
141+ return False
141142
142- if capability .sampling is not None : # pragma: lax no cover
143- if client_caps .sampling is None :
144- return False
145- if capability .sampling .context is not None and client_caps .sampling .context is None :
143+ # Check sampling capability
144+ if capability .sampling and not client_caps .sampling :
145+ return False
146+ if capability .sampling :
147+ if capability .sampling .context and not client_caps .sampling .context :
146148 return False
147- if capability .sampling .tools is not None and client_caps .sampling .tools is None :
149+ if capability .sampling .tools and not client_caps .sampling .tools :
148150 return False
149151
150- if capability .elicitation is not None and client_caps .elicitation is None : # pragma: lax no cover
152+ # Check elicitation capability
153+ if capability .elicitation and not client_caps .elicitation :
151154 return False
152155
153- if capability .experimental is not None : # pragma: lax no cover
154- if client_caps .experimental is None :
156+ # Check experimental capability
157+ if capability .experimental :
158+ if not client_caps .experimental :
155159 return False
156160 for exp_key , exp_value in capability .experimental .items ():
157161 if exp_key not in client_caps .experimental or client_caps .experimental [exp_key ] != exp_value :
158162 return False
159163
160- if capability .tasks is not None : # pragma: lax no cover
161- if client_caps .tasks is None :
164+ # Check tasks capability
165+ if capability .tasks :
166+ if not client_caps .tasks :
162167 return False
163168 if not check_tasks_capability (capability .tasks , client_caps .tasks ):
164169 return False
@@ -207,6 +212,9 @@ async def _received_notification(self, notification: types.ClientNotification) -
207212 match notification :
208213 case types .InitializedNotification ():
209214 self ._initialization_state = InitializationState .Initialized
215+ case types .RootsListChangedNotification ():
216+ # When roots list changes, server should request updated list
217+ await self .list_roots ()
210218 case _:
211219 if self ._initialization_state != InitializationState .Initialized : # pragma: no cover
212220 raise RuntimeError ("Received notification before initialization was complete" )
0 commit comments