On this page
Tool registration API providing the Tool struct and a decorator for defining user tools that are served via MCP to Claude Code.
#claudestream._tools
#claudestream._tools
Tool registration API providing the Tool struct and a decorator for defining user tools that are served via MCP to Claude Code.
#Tool
A user-defined tool that can be served via MCP to Claude Code.
#_type_to_schema
def _type_to_schema(annotation: Any) -> dictConvert a single type annotation to a JSON Schema fragment.
#_parse_param_descriptions
def _parse_param_descriptions(fn: Callable) -> dict[str, str]Extract per-parameter descriptions from a function's docstring.
Supports Google-style (Args: section) and reST-style (:param name:).
#_generate_schema
def _generate_schema(fn: Callable, *, inject: list[str] | None=None) -> dictGenerate a JSON Schema from a function's type hints and defaults.
#_get_type_hints_safe
def _get_type_hints_safe(fn: Callable) -> dict[str, Any]Get type hints, falling back to __annotations__ on failure.
#tool
def tool(server: str, *, name: str | None=None, description: str | None=None, inject: list[str] | None=None) -> CallableDecorator factory that creates a Tool from a function's type hints and docstring.
Usage::
@tool("my_server") async def create_child(name: str, age: int) -> str: """Create a child record.""" ...
@tool("my_server", name="custom_name") def greet(message: str) -> str: ...
@tool("my_server", inject=["ctx"]) def search(query: str, ctx: Any = None) -> str: ...
#collect_tools
def collect_tools(module: ModuleType) -> list[Tool]Gather all @tool-decorated functions from a module.