Declarative Configuration¶
The toolregistry.config module lets you define tool sources in a JSONC or YAML file and parse them into typed Python objects. This decouples what tools to load from how they are registered.
Quick Start¶
from toolregistry.config import load_config
config = load_config("tools.yaml")
for source in config.tools:
print(source)
Config File Format¶
Both JSONC (.json, .jsonc) and YAML (.yaml, .yml) are supported. The format is auto-detected from the file extension.
YAML Example¶
mode: denylist
disabled:
- filesystem
tools:
# Python class
- type: python
class: toolregistry_hub.calculator.Calculator
namespace: calculator
# Python module (all public functions)
- type: python
module: my_package.tools
namespace: custom
# OpenAPI endpoint
- type: openapi
url: https://api.example.com/openapi.json
namespace: external_api
auth:
type: bearer
token_env: EXTERNAL_API_TOKEN
# MCP server (stdio)
- type: mcp
transport: stdio
command: ["python", "-m", "mcp_server"]
namespace: mcp_tools
env:
DEBUG: "1"
# MCP server (SSE)
- type: mcp
transport: sse
url: http://localhost:8080/sse
namespace: remote_mcp
# MCP server (streamable-http, alias "http")
- type: mcp
transport: http
url: http://localhost:8080/mcp
namespace: remote_mcp2
skills:
- paths: [skills]
expose: catalog
namespace: skills
JSONC Example¶
{
"mode": "denylist",
"disabled": ["filesystem"],
"tools": [
{
"type": "python",
"class": "toolregistry_hub.calculator.Calculator",
"namespace": "calculator"
},
{
// MCP server via SSE
"type": "mcp",
"transport": "sse",
"url": "http://localhost:8080/sse",
"namespace": "remote_mcp"
}
]
}
Tool Source Types¶
python — Python Class or Module¶
| Field | Type | Required | Description |
|---|---|---|---|
type |
"python" |
Yes | Source type identifier |
class |
string | One of class/module |
Fully-qualified class path (e.g. "pkg.Calculator") |
module |
string | One of class/module |
Fully-qualified module path (e.g. "pkg.tools") |
namespace |
string | No | Namespace for registered tools |
kwargs |
dict | No | Keyword arguments passed to the class constructor (default: {}) |
enabled |
bool | No | Per-source enable/disable (default: true) |
When class is specified, the consumer calls register(cls, source="class"). When module is specified, the consumer registers all public callables from the module.
Passing Constructor Arguments with kwargs¶
Use kwargs to supply keyword arguments to the class constructor when loading a class entry:
tools:
- type: python
class: mypackage.tools.SearchTool
namespace: search
kwargs:
api_key: "${SEARCH_API_KEY}"
base_url: "https://api.example.com"
- type: python
class: mypackage.tools.DatabaseTool
namespace: db
kwargs:
host: "localhost"
port: 5432
db_name: "mydb"
Environment variable interpolation (e.g. "${VAR}") is supported in kwargs values, consistent with other config fields. If kwargs is omitted, the class constructor is called with no arguments (equivalent to {}).
Note
kwargs applies only to class entries. It is ignored when module is specified.
Legacy Format
The legacy format {"module": "pkg", "class": "Cls"} (without type field) is still supported. The type is inferred as "python" and class_path is combined as "pkg.Cls".
mcp — MCP Server¶
| Field | Type | Required | Description |
|---|---|---|---|
type |
"mcp" |
Yes | Source type identifier |
transport |
string | Yes | "stdio", "sse", "streamable-http", or "http" |
command |
string or list | stdio only | Command to start the server |
url |
string | sse/http only | Server URL |
env |
dict | No | Environment variables for stdio subprocess |
headers |
dict | No | HTTP headers for network transports |
namespace |
string | No | Namespace for registered tools |
persistent |
bool | No | Keep connection alive (default: true) |
include |
string or list | No | Names or glob patterns to keep; mutually exclusive with exclude |
exclude |
string or list | No | Names or glob patterns to drop; mutually exclusive with include |
enabled |
bool | No | Per-source enable/disable (default: true) |
http Alias
transport: "http" is a shorthand for "streamable-http" and is normalized internally.
openapi — OpenAPI Endpoint¶
| Field | Type | Required | Description |
|---|---|---|---|
type |
"openapi" |
Yes | Source type identifier |
url |
string | Yes | URL to the OpenAPI spec |
namespace |
string | No | Namespace for registered tools |
auth |
object | No | Authentication configuration |
base_url |
string | No | Override servers[0].url from spec |
include |
string or list | No | Names or glob patterns to keep; mutually exclusive with exclude |
exclude |
string or list | No | Names or glob patterns to drop; mutually exclusive with include |
enabled |
bool | No | Per-source enable/disable (default: true) |
Auth Configuration¶
| Field | Type | Default | Description |
|---|---|---|---|
type |
string | "bearer" |
"bearer" or "header" |
token |
string | — | Literal token value |
token_env |
string | — | Environment variable name (resolved at parse time) |
header_name |
string | "Authorization" |
Custom header name (for type: "header") |
If both token_env and token are specified, token_env takes precedence.
skills — Agent Skill Roots¶
The top-level skills block is separate from tools because skills are prompt-level packages, not callable endpoints. A single mapping is accepted as a one-item list.
skills:
- paths: [skills, ../shared-skills]
recursive: true
override: true
exclude: ["*-draft"]
expose: catalog
namespace: skills
- path: vendor/skills
expose: per-skill
limit: 20
| Field | Type | Default | Description |
|---|---|---|---|
path / paths |
string or list | standard roots | Roots, skill directories, or SKILL.md files; relative paths resolve against the config file |
recursive |
bool | true |
Walk nested directories |
override |
bool | true |
Let a later source replace an earlier skill with the same name |
include |
string or list | — | Name globs to keep; mutually exclusive with exclude |
exclude |
string or list | — | Name globs to drop |
enabled |
bool | true |
Skip the source when false |
expose |
string | "catalog" |
"catalog", "per-skill", "both", or "none" |
namespace |
string or null | "skills" |
Namespace for generated tools |
limit |
int | — | Per-skill mode: maximum number of tools |
load_config() parses and validates this block but does not apply it. Pass the result to ToolRegistry.apply_skill_config() after constructing the registry. See Agent Skills for the generated tool names and usage modes.
Filtering Modes¶
Denylist (Default)¶
All sources are loaded except those whose namespace matches a pattern in disabled:
Allowlist¶
Only sources whose namespace matches a pattern in enabled are loaded:
Namespace matching is hierarchical: pattern "web" matches "web/brave_search".
Per-Source Enable/Disable¶
Individual sources can be temporarily disabled with enabled: false, regardless of the filtering mode:
tools:
- type: python
class: toolregistry_hub.calculator.Calculator
namespace: calculator
- type: mcp
transport: sse
url: http://localhost:8080/sse
namespace: remote_mcp
enabled: false # temporarily disabled
- type: openapi
url: https://api.example.com/openapi.json
namespace: external_api
enabled: false # skip until API key is configured
Per-Source Tool Filters¶
mcp and openapi sources accept include or exclude, forwarded to the
registration-time filter. They are mutually exclusive.
tools:
- type: mcp
transport: sse
url: http://localhost:8080/sse
namespace: gh
include: ["gh.*"] # list of patterns
- type: openapi
url: https://api.example.com/openapi.json
namespace: api
exclude: admin_* # a bare string is a single pattern
Patterns are fnmatch globs matched against the raw source name, the
post-namespace registered name, and the snake_case form of each. An
omitted or null filter means no filtering; an empty list (include: [])
is an explicit empty filter and matches nothing, so the source registers
no tools. Filters are applied before a tool wrapper is constructed, so an
excluded malformed operation cannot abort the whole source, and they are
re-applied on refresh.
Unknown keys on a source entry (or under auth) are rejected at load time
with a ConfigError naming the entry and the offending keys, instead of
being silently ignored.
Per-Route Parameter Overrides¶
tool_parameters replaces the published parameter schema for individual
registered tools. It is a top-level block keyed by the exact registered tool
name, the same keying as tool_metadata:
tool_parameters:
calculator-evaluate:
type: object
properties:
expression:
type: string
precision:
type: integer
required: [expression]
Each value must describe a JSON object. type may be omitted, be "object",
or be a list that contains "object" (for example ["object", "null"]); a
scalar or array schema raises ConfigError, because the request path only
produces an object and a narrower schema would reject every call. When
properties is present it must be a mapping.
load_config() parses and stores the block but does not apply it: an override
needs the tool to be registered, so the consumer applies it after registration,
and a name with no registered tool is kept as written rather than rejected.
Whether an override is compatible with the tool's own schema is the consumer's
decision. The block is written back only when it is non-empty, so existing
config files round-trip unchanged.
Note
Core owns the config schema, so the block is defined here. Applying it to routes — and refusing an override the tool cannot accept — is the consumer's job, for example the ToolRegistry server's route table.
Parsed Types¶
load_config() returns a ToolConfig frozen dataclass:
@dataclass(frozen=True)
class ToolConfig:
mode: Literal["denylist", "allowlist"]
disabled: tuple[str, ...]
enabled: tuple[str, ...]
tools: tuple[ToolSource, ...] # PythonSource | MCPSource | OpenAPISource
skills: tuple[SkillSource, ...] # parsed from the top-level skills block
source: str # config file path
All config objects are immutable after parsing.
Error Handling¶
FileNotFoundError— config file does not existConfigError— semantic validation errors (invalid mode, missing required fields, unknown type, unrecognised source orauthkeys, mutually exclusiveinclude/exclude, unset env var)- Parser-native errors (
JSONCDecodeError,YAMLError) propagate for syntax issues