Expand description
§Tokitai Core
Core types and traits for the Tokitai AI tool integration library. All
tool information is generated at compile time, so the core has zero
runtime dependencies and is no_std-compatible (with the serde
feature disabled).
See ToolDefinition, ToolProvider, and the tokitai
crate for the high-level overview.
§Example
use tokitai_core::{ToolDefinition, ParamType};
let tool = ToolDefinition::new(
"add",
"Add two numbers together",
r#"{"type":"object","properties":{"a":{"type":"integer"},"b":{"type":"integer"}},"required":["a","b"]}"#
);
assert_eq!(tool.name, "add");
assert_eq!(ParamType::from_rust_type("i32"), Some(ParamType::Integer));
assert_eq!(ParamType::from_rust_type("Vec<i32>"), Some(ParamType::Array));§Features
| Feature | Description |
|---|---|
serde (default) | Enable serde/serde_json integration |
For no_std usage, depend on the crate with default-features = false.
§License
Dual-licensed under either of:
- Apache License, Version 2.0
- MIT License
at your option.
Re-exports§
pub use config::ToolConfig;pub use config::ToolConfigRegistry;pub use config::GLOBAL_CONFIG_REGISTRY;pub use dynamic::is_tenant_denied;pub use dynamic::DynamicHandler;pub use dynamic::DynamicToolProvider;pub use dynamic::DynamicToolRegistry;pub use dynamic::TENANT_DENIED_KIND_HINT;pub use serde_types::*;
Modules§
- config
- Runtime configuration types used to override compile-time tool metadata. Tool configuration system for runtime tool definition customization.
- dynamic
- T-010: Dynamic / runtime-mutable tool registry.
- serde_
types - Re-exports of
serde_jsonandalloc::stringtypes under a stable path. Available when theserdefeature is enabled.
Macros§
- assert_
no_ config_ deadlock - Macro for compile-time deadlock detection.
- json_
schema - Compile-time helper for emitting JSON Schema strings without runtime overhead.
Structs§
- Async
Sleep - Runtime-agnostic async sleep future returned by
async_sleep. - Tool
Definition - A tool that an AI system can invoke.
- Tool
Error - Error returned by tool invocations.
- Tool
Parameter - A single parameter definition for a tool.
Enums§
- Param
Type - JSON Schema type for a tool parameter.
- Tool
Error Kind - Classification of a
ToolErrorfor structured error handling.
Constants§
- CONFIG_
PRIORITY_ DOC - Single source of truth for the priority order of configuration sources that can supply a tool’s description.
- CORE_
VERSION - T-024: exact version string of
tokitai-corethat was compiled in (sourced fromCARGO_PKG_VERSION). The mcp-server build script writes a generated source file with this constant so the running binary can compare against the version that was baked at compile time.
Traits§
- Async
Executor - Runtime-Agnostic Async Executor
- Async
Executor Ext - Typed convenience wrapper around
AsyncExecutor::block_on_dyn. Implemented for everyT: AsyncExecutor; re-introduces the naturalblock_on<F: Future>(&self, F) -> F::Outputsignature on top of the type-erased entry point. - Capability
Manifest Provider - T-023: trait the
#[tool]macro auto-implements for anyimplblock it processes. Exposes the aggregatedCAPABILITIESslice (per-method name + per-method required capability tokens) so thetokitai-mcp-serverbuilder can walk it at start time without depending on a per-impl generated type. - From
Json Value - From Json Value Trait
- Tool
Caller - Runtime tool invocation trait. Auto-implemented by the
#[tool]macro. - Tool
Provider - Compile-time tool registry trait.
Functions§
- assert_
compatible_ with - T-024: assert at compile time that the compiled-against
tokitai-corematches the expected SemVer string under the standard prefix-match rule (x.ymatchesx.y.z;x.y.zmatches exactly). A mismatch raises acompile_error!naming both versions and the docs.rs migration link. - assert_
compatible_ with_ runtime - T-028: non-const runtime companion to
assert_compatible_with. - async_
sleep - Sleep for
durwithout blocking the current thread. - block_
on_ async - Try to drive
futureto completion using the registered executor, the current Tokio runtime (when available), or a clear English error. - block_
on_ async_ error_ message - Canonical English error message returned by the
#[tool]macro when it cannot find any executor to drive a sync-from-async call. The macro embeds the return value of this function as the error string, so the message is centralised here for consistency and future i18n. - block_
on_ for_ executor - T-003 per-call override probe. Returns an executor that should be
preferred over the global slot. The macro’s sync-from-async wrapper
calls this first; only on
Nonedoes it fall back tocurrent_async_executorand the active Tokio runtime. - capability_
in_ allowlist - T-023: returns
truewhendeclaredis covered by some entry inallowlist. The allowlist supports one wildcard form: a trailing*(e.g.db:read:*) is treated as a prefix match (sodb:read:*coversdb:read:sales,db:read:any_resource, and any otherdb:read:<X>). Exact entries (no*) must match the declared capability verbatim. The matcher is case-sensitive: capability tokens are typically lowercase-with-colons in the documented category set, and allowing case folding would weaken the allowlist contract without a clear use case. - clear_
current_ version - T-013: clear any previously-registered current version. After
this call the macro stops gating
remove_inuntilset_current_versionis called again. Useful in tests that need to exercise the “no gating” path mid-suite. - current_
async_ executor - Return the currently registered
AsyncExecutor, orNoneif no executor has been installed viaset_async_executor. The returned reference is&'staticbecause the registeredBox<dyn AsyncExecutor>is held inside aOnceLockfor the program’s lifetime. - current_
version - T-013: return the currently registered program version, or
Nonewhenset_current_versionwas never called. - from_
json_ value_ generic - Parse a
DeserializeOwnedvalue forkey. Useful for custom types not covered by theFromJsonValueblanket impls. - from_
json_ value_ str - Borrow a string parameter without copying.
- set_
async_ executor - Install a global
AsyncExecutorused by every#[tool]-generated sync wrapper. Call once at program startup, before any synccall_toolis invoked on anasynctool. The box is leaked: the executor lives for the lifetime of the program. The first call wins; subsequent calls are silently ignored (best-effort registration). - set_
current_ version - T-013: install a process-wide current version. The
#[tool]macro’s sync wrapper compares this value against each tool’sremove_infield; whenremove_in <= currentthe call returnsToolError::Removedand the user is directed toreplaced_by.
Type Aliases§
- Capability
Manifest - T-023: per-tool capability manifest. Each tuple is
(tool_name, required_capabilities). The macro emits an aggregatedCAPABILITIESslice per impl block; the server folds those slices into a singleCapabilityManifestat startup before walking the allowlist.