RouteTable 和 RouteEntry¶
toolregistry_server.RouteTable
dataclass
¶
Central router table that bridges ToolRegistry and protocol adapters.
The RouteTable provides a unified view of all registered tools and their routing information. It supports:
- Querying routes by name or listing all routes
- Enabling/disabling tools dynamically
- Observer pattern for change notifications
- ETag generation for cache validation
Example
etag
property
¶
Get ETag for cache validation.
Returns:
| Type | Description |
|---|---|
str
|
An ETag string based on the current version. |
version
property
¶
Get the current version number.
Returns:
| Type | Description |
|---|---|
int
|
The version number, incremented on each change. |
__post_init__ ¶
add_listener ¶
Add a listener for route changes.
The callback will be invoked with (tool_name, event) whenever a route changes. Events include: "enable", "disable", "refresh", "refresh_all".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[str, str], None]
|
Function to call on changes. |
required |
Source code in src/toolregistry_server/route_table.py
disable ¶
Disable a tool.
The route table is automatically refreshed via the registry change callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str
|
The name of the tool to disable. |
required |
reason
|
str
|
Optional reason for disabling. |
''
|
Raises:
| Type | Description |
|---|---|
KeyError
|
If the tool is not found. |
Source code in src/toolregistry_server/route_table.py
enable ¶
Enable a tool.
The route table is automatically refreshed via the registry change callback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str
|
The name of the tool to enable. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the tool is not found. |
Source code in src/toolregistry_server/route_table.py
get_route ¶
Get a specific route by tool name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str
|
The name of the tool. |
required |
Returns:
| Type | Description |
|---|---|
RouteEntry | None
|
The RouteEntry if found, None otherwise. |
Source code in src/toolregistry_server/route_table.py
list_routes ¶
List all routes, optionally filtering by enabled state or defer flag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enabled_only
|
bool
|
If True, only return enabled routes. |
True
|
include_deferred
|
bool
|
If False, exclude routes whose tool has
|
True
|
Returns:
| Type | Description |
|---|---|
list[RouteEntry]
|
List of RouteEntry objects. |
Source code in src/toolregistry_server/route_table.py
refresh ¶
Refresh a single route's state from registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str
|
The name of the tool to refresh. |
required |
Source code in src/toolregistry_server/route_table.py
refresh_all ¶
remove_listener ¶
Remove a listener.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
callback
|
Callable[[str, str], None]
|
The callback to remove. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the callback is not found. |
Source code in src/toolregistry_server/route_table.py
toolregistry_server.RouteEntry
dataclass
¶
RouteEntry(tool_name: str, namespace: str, method_name: str, path: str, description: str, parameters_schema: dict[str, Any], handler: Callable[..., Any], is_async: bool, parameters_model: Any | None = None, handler_factory: Callable[..., Callable[..., Any]] | None = None, enabled: bool = True, disable_reason: str | None = None, deferred: bool = False)
A single route entry in the central router table.
Attributes:
| Name | Type | Description |
|---|---|---|
tool_name |
str
|
Full tool name (e.g., "calculator-evaluate") |
namespace |
str
|
Tool namespace (e.g., "calculator") |
method_name |
str
|
Method name within namespace (e.g., "evaluate") |
path |
str
|
HTTP path for the route (e.g., "/tools/calculator/evaluate") |
description |
str
|
Tool description |
parameters_schema |
dict[str, Any]
|
JSON Schema for tool parameters |
handler |
Callable[..., Any]
|
The actual tool callable |
is_async |
bool
|
Whether the handler is async |
enabled |
bool
|
Whether the tool is currently enabled |
disable_reason |
str | None
|
Reason for disabling, if disabled |