claudestream v0.14.2 /claudestream._tools
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

python
def _type_to_schema(annotation: Any) -> dict

Convert a single type annotation to a JSON Schema fragment.

#_parse_param_descriptions

python
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

python
def _generate_schema(fn: Callable, *, inject: list[str] | None=None) -> dict

Generate a JSON Schema from a function's type hints and defaults.

#_get_type_hints_safe

python
def _get_type_hints_safe(fn: Callable) -> dict[str, Any]

Get type hints, falling back to __annotations__ on failure.

#tool

python
def tool(server: str, *, name: str | None=None, description: str | None=None, inject: list[str] | None=None) -> Callable

Decorator 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

python
def collect_tools(module: ModuleType) -> list[Tool]

Gather all @tool-decorated functions from a module.

Search