tools.schema

Page actions AI-ready formats and sharing
Open LLM text
Share with AI
Ask Claude Ask ChatGPT Ask Gemini Ask Copilot

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…

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.

tools.schema

Name Type Default Description
type
qualified_name
element_type
description
source_file
line_number
is_autodoc
autodoc_element
_autodoc_template
_autodoc_url_path
_autodoc_page_type
title
doc_content_hash

Symbols on this page

function_to_schema
function
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 Default Description
func Callable[..., Any]
_type_to_schema
function
def _type_to_schema(annotation: Any) -> dict[str, Any]

Convert a Python type annotation to a JSON Schema fragment.

Parameters

Name Type Default Description
annotation Any
_is_optional
function
def _is_optional(annotation: Any) -> bool

Check if an annotation is X | None.

Parameters

Name Type Default Description
annotation Any
_unwrap_optional
function
def _unwrap_optional(annotation: Any) -> Any

Extract the non-None type from X | None.

Parameters

Name Type Default Description
annotation Any

View source · /home/runner/work/chirp/chirp/site/../src/chirp/tools/schema.py:1