JSON-able ``[{name, description, input_schema}]`` for ``system/init``. Mirrors the canonical API tool-schema build at ``query.py:637`` — the description comes from ``tool.prompt()`` (a string), NOT the raw ``tool.description`` field, which may be a callable for dynamic tools.
(registry: Any)
| 1704 | |
| 1705 | |
| 1706 | def _tool_schemas(registry: Any) -> list[dict[str, Any]]: |
| 1707 | """JSON-able ``[{name, description, input_schema}]`` for ``system/init``. |
| 1708 | |
| 1709 | Mirrors the canonical API tool-schema build at ``query.py:637`` — the |
| 1710 | description comes from ``tool.prompt()`` (a string), NOT the raw |
| 1711 | ``tool.description`` field, which may be a callable for dynamic tools. |
| 1712 | """ |
| 1713 | out: list[dict[str, Any]] = [] |
| 1714 | if registry is None: |
| 1715 | return out |
| 1716 | try: |
| 1717 | tools = list(registry.list_tools()) |
| 1718 | except Exception: # noqa: BLE001 - init must never crash the session |
| 1719 | logger.debug("[agent-server] tool enumeration failed", exc_info=True) |
| 1720 | return out |
| 1721 | for tool in tools: |
| 1722 | is_enabled = getattr(tool, "is_enabled", None) |
| 1723 | if callable(is_enabled) and not is_enabled(): |
| 1724 | continue |
| 1725 | try: |
| 1726 | prompt = getattr(tool, "prompt", None) |
| 1727 | desc = prompt() if callable(prompt) else getattr(tool, "description", "") |
| 1728 | except Exception: # noqa: BLE001 |
| 1729 | desc = "" |
| 1730 | schema = getattr(tool, "input_schema", None) |
| 1731 | out.append({ |
| 1732 | "name": getattr(tool, "name", ""), |
| 1733 | "description": desc if isinstance(desc, str) else "", |
| 1734 | "input_schema": dict(schema) if isinstance(schema, Mapping) else None, |
| 1735 | }) |
| 1736 | return out |
| 1737 | |
| 1738 | |
| 1739 | def _json_safe(obj: Any) -> Any: |
no test coverage detected