辅助类¶
支持 ToolRegistry 库核心功能的实用类和辅助函数。
参数模型¶
工具函数的参数验证和 Schema 生成。ArgModelBase 根据函数签名动态创建 Pydantic 模型,用于运行时参数验证。
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. |
实用工具¶
库中通用的实用函数,包括工具名称标准化和用于 OpenAPI 集成的 HTTP 客户端配置。
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
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
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 |