Module

tools.schema

Function signature to JSON Schema conversion.

Inspects a function's type annotations and produces an MCP-compatible JSON Schema for theinputSchema field of tools/listresponses.

Adapted fromchirp.ai._structured.dataclass_to_schemabut operates on function parameters instead of dataclass fields.

Functions

function_to_schema 1 dict[str, Any]
Generate MCP-compatible JSON Schema from a function's type annotations. Parame…
def function_to_schema(func: Callable[..., Any]) -> dict[str, Any]

Generate MCP-compatible JSON Schema from a function's type annotations.

Parameters namedrequest or annotated as Requestare excluded (same convention as chirp route handlers).

Parameters with defaults are optional (not inrequired). X | Noneunions are unwrapped to the base type.

Supports:str, int, float, bool, list[str], list[int], list[float], X | None.

Parameters
Name Type Description
func Callable[..., Any]
Returns
dict[str, Any]
_type_to_schema 1 dict[str, Any]
Convert a Python type annotation to a JSON Schema fragment.
def _type_to_schema(annotation: Any) -> dict[str, Any]
Parameters
Name Type Description
annotation Any
Returns
dict[str, Any]
_is_optional 1 bool
Check if an annotation is X | None.
def _is_optional(annotation: Any) -> bool
Parameters
Name Type Description
annotation Any
Returns
bool
_unwrap_optional 1 Any
Extract the non-None type from X | None.
def _unwrap_optional(annotation: Any) -> Any
Parameters
Name Type Description
annotation Any
Returns
Any