Add a tool to the server. The tool function can optionally request a Context object by adding a parameter with the Context type annotation. See the @tool decorator for examples. Args: fn: The function to register as a tool name: Optional name for the
(
self,
fn: Callable[..., Any],
name: str | None = None,
title: str | None = None,
description: str | None = None,
annotations: ToolAnnotations | None = None,
icons: list[Icon] | None = None,
meta: dict[str, Any] | None = None,
structured_output: bool | None = None,
)
| 450 | raise ResourceError(f"Error reading resource {uri}") from exc |
| 451 | |
| 452 | def add_tool( |
| 453 | self, |
| 454 | fn: Callable[..., Any], |
| 455 | name: str | None = None, |
| 456 | title: str | None = None, |
| 457 | description: str | None = None, |
| 458 | annotations: ToolAnnotations | None = None, |
| 459 | icons: list[Icon] | None = None, |
| 460 | meta: dict[str, Any] | None = None, |
| 461 | structured_output: bool | None = None, |
| 462 | ) -> None: |
| 463 | """Add a tool to the server. |
| 464 | |
| 465 | The tool function can optionally request a Context object by adding a parameter |
| 466 | with the Context type annotation. See the @tool decorator for examples. |
| 467 | |
| 468 | Args: |
| 469 | fn: The function to register as a tool |
| 470 | name: Optional name for the tool (defaults to function name) |
| 471 | title: Optional human-readable title for the tool |
| 472 | description: Optional description of what the tool does |
| 473 | annotations: Optional ToolAnnotations providing additional tool information |
| 474 | icons: Optional list of icons for the tool |
| 475 | meta: Optional metadata dictionary for the tool |
| 476 | structured_output: Controls whether the tool's output is structured or unstructured |
| 477 | - If None, auto-detects based on the function's return type annotation |
| 478 | - If True, creates a structured tool (return type annotation permitting) |
| 479 | - If False, unconditionally creates an unstructured tool |
| 480 | """ |
| 481 | self._tool_manager.add_tool( |
| 482 | fn, |
| 483 | name=name, |
| 484 | title=title, |
| 485 | description=description, |
| 486 | annotations=annotations, |
| 487 | icons=icons, |
| 488 | meta=meta, |
| 489 | structured_output=structured_output, |
| 490 | ) |
| 491 | |
| 492 | def remove_tool(self, name: str) -> None: |
| 493 | """Remove a tool from the server by name. |
no outgoing calls