Functions
function_to_schema
1
dict[str, Any]
▼
Generate MCP-compatible JSON Schema from function type annotations.
Parameters…
function_to_schema
1
dict[str, Any]
▼
def function_to_schema(func: Callable[..., Any]) -> dict[str, Any]
Generate MCP-compatible JSON Schema from function type annotations.
Parameters with defaults are optional (not in required). X | None unions unwrapped to base type. Supports: str, int, float, bool, list[X], dict[str, X], X | None, Enum, Literal, dataclass, TypedDict, Union.
Parameter descriptions are extracted from the function's docstring
(Google, NumPy, or Sphinx style) and included as"description"
fields in the schema properties.
Parameters
| Name | Type | Description |
|---|---|---|
func |
Callable[..., Any] |
Returns
dict[str, Any]
_type_to_schema
2
dict[str, Any]
▼
Convert Python type annotation to JSON Schema fragment.
_type_to_schema
2
dict[str, Any]
▼
def _type_to_schema(annotation: Any, _seen: set[int] | None = None) -> dict[str, Any]
Parameters
| Name | Type | Description |
|---|---|---|
annotation |
Any |
|
_seen |
set[int] | None |
Default:None
|
Returns
dict[str, Any]
_is_typed_dict
1
bool
▼
Check if annotation is a TypedDict subclass.
_is_typed_dict
1
bool
▼
def _is_typed_dict(annotation: Any) -> bool
Parameters
| Name | Type | Description |
|---|---|---|
annotation |
Any |
Returns
bool
_is_optional
1
bool
▼
Check if annotation is X | None.
_is_optional
1
bool
▼
def _is_optional(annotation: Any) -> bool
Parameters
| Name | Type | Description |
|---|---|---|
annotation |
Any |
Returns
bool
_unwrap_optional
1
Any
▼
Extract non-None type from X | None.
_unwrap_optional
1
Any
▼
def _unwrap_optional(annotation: Any) -> Any
Parameters
| Name | Type | Description |
|---|---|---|
annotation |
Any |
Returns
Any
return_to_schema
1
dict[str, Any] | None
▼
Generate JSON Schema from function return type annotation.
Returns None if the…
return_to_schema
1
dict[str, Any] | None
▼
def return_to_schema(func: Callable[..., Any]) -> dict[str, Any] | None
Generate JSON Schema from function return type annotation.
Returns None if the function has no return annotation or returns None.
Parameters
| Name | Type | Description |
|---|---|---|
func |
Callable[..., Any] |
Returns
dict[str, Any] | None
_is_context_type
2
bool
▼
Check if an annotation refers to milo's Context type.
_is_context_type
2
bool
▼
def _is_context_type(annotation: Any, name: str) -> bool
Parameters
| Name | Type | Description |
|---|---|---|
annotation |
Any |
|
name |
str |
Returns
bool
_parse_param_docs
1
dict[str, str]
▼
Extract parameter descriptions from a docstring.
Supports Google, Sphinx, and …
_parse_param_docs
1
dict[str, str]
▼
def _parse_param_docs(docstring: str) -> dict[str, str]
Extract parameter descriptions from a docstring.
Supports Google, Sphinx, and NumPy docstring styles::
# Google style
Parameters
| Name | Type | Description |
|---|---|---|
docstring |
str |
Returns
dict[str, str]