Helper Classes¶
Utility classes and helper functions that support the core functionality of the ToolRegistry library.
Parameter Models¶
Parameter validation and schema generation for tool functions. ArgModelBase dynamically creates Pydantic models from function signatures for runtime argument validation.
toolregistry.parameter_models ¶
ArgModelBase ¶
Bases: BaseModel
Base model for function argument validation with Pydantic.
Features
- Supports arbitrary types in fields
- Provides method to dump fields one level deep
- Configures Pydantic model behavior
model_dump_one_level ¶
Dump model fields one level deep, keeping sub-models as-is.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict[str, Any]: Dictionary of field names to values. |
Source code in src/toolregistry/parameter_models.py
InvalidSignature ¶
Bases: Exception
Exception raised when a function signature cannot be processed for FastMCP.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
str
|
Explanation of the error. |
Utilities¶
Common utility functions used across the library, including tool name normalization and HTTP client configuration for OpenAPI integrations.
toolregistry.utils ¶
HttpClientConfig ¶
HttpClientConfig(base_url: str, headers: dict[str, str] | None = None, timeout: float = 10.0, auth: tuple[str, str] | None = None, **extra_options: Any)
Container for HTTP client configuration.
Creates zero-dependency HTTP clients with base URL support, connection pooling, and both sync/async interfaces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
The base URL for the API. This is required. |
required |
headers
|
dict[str, str] | None
|
Custom request headers. Default is None. |
None
|
timeout
|
float
|
Request timeout in seconds. Default is 10.0. |
10.0
|
auth
|
tuple[str, str] | None
|
Basic authentication credentials (username, password). Default is None. |
None
|
**extra_options
|
Any
|
Additional client parameters (e.g. verify, proxy, pool_size). |
{}
|
Source code in src/toolregistry/utils.py
__getstate__ ¶
Drop live HTTP clients before pickling.
The config (base_url, headers, timeout, auth, extra_options)
is preserved. Live _sync_client / _async_client
(holding thread locks and connection pools) are dropped.
The worker process will recreate them lazily via
get_persistent_client().
Source code in src/toolregistry/utils.py
__setstate__ ¶
Restore config; clients will be created lazily on first use.
Source code in src/toolregistry/utils.py
close ¶
Close persistent clients (sync).
Only closes the sync client. Use close_async() to properly
close the async client.
close_async
async
¶
Close all persistent clients.
get_persistent_client ¶
Get or create a persistent client instance.
Unlike to_client(), this method reuses the same client across
multiple calls, enabling HTTP connection pooling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_async
|
bool
|
Whether to return an async client. |
False
|
Returns:
| Type | Description |
|---|---|
|
A persistent _BaseUrlClient or _BaseUrlAsyncClient instance. |
Source code in src/toolregistry/utils.py
to_client ¶
Create a new HTTP client instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
use_async
|
bool
|
Whether to create an asynchronous client. Default is False. |
False
|
Returns:
| Type | Description |
|---|---|
|
A _BaseUrlClient or _BaseUrlAsyncClient wrapping the underlying |
|
|
zero-dependency client with base URL support. |
Source code in src/toolregistry/utils.py
HttpxClientConfig ¶
Deprecated alias for HttpClientConfig.
.. deprecated::
Use HttpClientConfig instead. HttpxClientConfig will be
removed in a future release.
Source code in src/toolregistry/utils.py
generate_invocation_id ¶
Generate a unique invocation ID for grouping related tool calls.
Prefixes
tr_bat_— batch execution viaexecute_tool_calls()tr_ptc_— PTC code execution viaPtcTooltr_sig_— single invocation viaregistry.invoke()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
Literal['bat', 'ptc', 'sig']
|
One of |
'sig'
|
Returns:
| Type | Description |
|---|---|
str
|
A unique ID like |
Source code in src/toolregistry/utils.py
normalize_tool_name ¶
Normalize tool name to snake_case format and remove dots and spaces. Also handles OpenAPI-style duplicate names like 'add_add_get' by converting to 'add_get'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Original tool name in various formats (including CamelCase, UpperCamelCase, or containing spaces) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Normalized name in snake_case without dots or spaces |