thulp-core
Core types, traits, and error definitions for the thulp execution context platform.
This crate provides the foundational abstractions for defining, validating, and executing tools in AI agent environments. It includes type-safe parameter definitions, tool metadata, and extensible traits for implementing custom tool providers and transports.
Core Types
- [
ToolDefinition]: Describes an available tool with its parameters and metadata - [
ToolCall]: Represents a request to execute a specific tool with arguments - [
ToolResult]: The result of a tool execution (success or failure) - [
Parameter]: Defines a tool parameter with type information and validation rules - [
ParameterType]: Strongly-typed parameter types (String, Integer, Number, Boolean, Array, Object)
Traits
- [
Tool]: Trait for implementing executable tools - [
Transport]: Trait for implementing tool transport layers (e.g., MCP, HTTP, gRPC)
Features
- Type Safety: Compile-time and runtime validation of tool parameters
- Builder Pattern: Ergonomic API for constructing tool definitions
- JSON Serialization: Full serde support for all types
- MCP Integration: Parse MCP JSON Schema to Thulp parameter definitions
- Async Support: Built on tokio for efficient async execution
Quick Start
Defining a Tool
use ;
let tool = builder
.description
.parameter
.parameter
.build;
assert_eq!;
assert_eq!;
Validating Tool Arguments
use ;
use json;
let tool = builder
.description
.parameter
.parameter
.build;
// Valid arguments
let args = json!;
assert!;
// Invalid - missing required parameter
let args = json!;
assert!;
// Invalid - wrong type
let args = json!;
assert!;
Creating Tool Calls
use ToolCall;
use json;
let call = builder
.arg
.arg
.build;
assert_eq!;
Parsing MCP JSON Schema
use ToolDefinition;
use json;
let schema = json!;
let params = parse_mcp_input_schema.unwrap;
assert_eq!;
assert!;
assert!;
Error Handling
All fallible operations return Result<T, Error>, where [Error] provides
detailed error information:
use ;
use json;
let tool = builder
.parameter
.build;
match tool.validate_args