MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / _tool_schemas

Function _tool_schemas

src/server/agent_server.py:1706–1736  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1704
1705
1706def _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
1739def _json_safe(obj: Any) -> Any:

Callers 2

emit_initMethod · 0.85
_context_usageMethod · 0.85

Calls 2

list_toolsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected