Convert existing handlers to a ServerCapabilities object.
(
self,
notification_options: NotificationOptions | None = None,
experimental_capabilities: dict[str, dict[str, Any]] | None = None,
)
| 339 | ) |
| 340 | |
| 341 | def get_capabilities( |
| 342 | self, |
| 343 | notification_options: NotificationOptions | None = None, |
| 344 | experimental_capabilities: dict[str, dict[str, Any]] | None = None, |
| 345 | ) -> types.ServerCapabilities: |
| 346 | """Convert existing handlers to a ServerCapabilities object.""" |
| 347 | notification_options = notification_options or NotificationOptions() |
| 348 | prompts_capability = None |
| 349 | resources_capability = None |
| 350 | tools_capability = None |
| 351 | logging_capability = None |
| 352 | completions_capability = None |
| 353 | |
| 354 | # Set prompt capabilities if handler exists |
| 355 | if "prompts/list" in self._request_handlers: |
| 356 | prompts_capability = types.PromptsCapability(list_changed=notification_options.prompts_changed) |
| 357 | |
| 358 | # Set resource capabilities if handler exists |
| 359 | if "resources/list" in self._request_handlers: |
| 360 | resources_capability = types.ResourcesCapability( |
| 361 | subscribe="resources/subscribe" in self._request_handlers, |
| 362 | list_changed=notification_options.resources_changed, |
| 363 | ) |
| 364 | |
| 365 | # Set tool capabilities if handler exists |
| 366 | if "tools/list" in self._request_handlers: |
| 367 | tools_capability = types.ToolsCapability(list_changed=notification_options.tools_changed) |
| 368 | |
| 369 | # Set logging capabilities if handler exists |
| 370 | if "logging/setLevel" in self._request_handlers: |
| 371 | logging_capability = types.LoggingCapability() |
| 372 | |
| 373 | # Set completions capabilities if handler exists |
| 374 | if "completion/complete" in self._request_handlers: |
| 375 | completions_capability = types.CompletionsCapability() |
| 376 | |
| 377 | capabilities = types.ServerCapabilities( |
| 378 | prompts=prompts_capability, |
| 379 | resources=resources_capability, |
| 380 | tools=tools_capability, |
| 381 | logging=logging_capability, |
| 382 | experimental=experimental_capabilities, |
| 383 | completions=completions_capability, |
| 384 | ) |
| 385 | return capabilities |
| 386 | |
| 387 | @property |
| 388 | def server_info(self) -> types.Implementation: |