Skip to main content
A Tool is a live view over a Capsule. The Capsule is the durable executable payload.

1. What a Toolkit Is

A Toolkit groups Capsules under tool names and serving metadata. Use it when you want a set of functions to behave like a local API, an MCP server, or an export target for model tool calling. The durable model is intentionally small:
  • Capsule: stores the executable function manifest
  • Tool: names one Capsule (plus an optional serializer Capsule) and exposes run(...) and run_to_str(...)
  • Toolkit: orders tools, saves references, and exports servers
  • sys-toolkit: persistent entity row storing the Toolkit manifest and Capsule references
Each persisted tool keeps two Capsule references: a main execution Capsule and a serializer Capsule. By default, HeavenBase uses the shared jstr_serializer Capsule, which applies compact JSON serialization for dict and list results.

2. Build and Register a Toolkit

toolkit.register(...) saves each tool’s main Capsule and serializer Capsule, then stores the Toolkit manifest as ordered Capsule references. Loading a Toolkit restores the referenced Capsules lazily. Toolkit.register(...) defaults to overwrite=True. Use on_conflict="raise" or on_conflict="skip" when you need explicit conflict handling. For compact construction, pass a list, pairs, or a mapping:

3. Load and Run From Another Path

The consumer does not need to import the file that created the Toolkit. It loads the Toolkit manifest from the registry, then restores each Capsule from its manifest. Use run_to_str(...) when you need the serialized string boundary that MCP and agent clients expect:
Tests and applications can pass registry_config=... to isolate registry storage while keeping the same public API.

4. Architecture Data Flow

Toolkit execution is a thin layer over Capsules:
  1. Toolkit.add(callable) captures the callable as a main Capsule and resolves a serializer Capsule (default jstr_serializer).
  2. toolkit.register() persists both Capsules for each tool and then stores a sys-toolkit row containing ordered Capsule references.
  3. Toolkit.load(...) resolves the manifest and restores each referenced Capsule into a Tool.
  4. Toolkit.run(name, **kwargs) calls the selected main Capsule locally and returns the raw Python value.
  5. Toolkit.run_to_str(name, **kwargs) runs the tool and passes the result through its serializer Capsule.
  6. Toolkit.to_fastmcp() wraps each Tool with a signature-compatible FastMCP function that returns serialized strings.
  7. Toolkit.to_anthropic_tools(...) exports a separate Anthropic programmatic tool schema with allowed_callers.

5. Serve Through MCP

You can also print client configuration:
Block and serve with toolkit.serve(...). Defaults live under heavenbase.mcp in CM_HVNB (transport, host, port, wait).

6. Import an MCP Server

FastMCP client proxies are runtime-only. They cannot be persisted with register() because they close over a live server handle.

7. Workspace Toolkits

Every workspace can still become a Toolkit:
Workspace Toolkits assemble registered toolkit families: the core workspace family exposes entity definition, Catalog discovery, CRUD, count, query, and explain tools. Family specs and aliases mirror into sys-metaschema as toolkit_family rows; runtime workspace Toolkits still cannot be registered because they close over a live workspace object.

8. Demo

The demo creates a persisted math Toolkit, loads it back through Toolkit.load(...), shows Capsule docstring and format conversion, and checks that FastMCP can list and call the tools.

Further Exploration

Related resources: