thulp-core
Core types, traits, and error definitions for the Thulp execution context platform.
Overview
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.
Features
- Type-Safe Parameters: 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
Installation
Add to your Cargo.toml:
[]
= "0.2"
Core Types
ToolDefinition: Describes an available tool with its parameters and metadataToolCall: Represents a request to execute a specific tool with argumentsToolResult: The result of a tool execution (success or failure)Parameter: Defines a tool parameter with type information and validation rulesParameterType: Strongly-typed parameter types (String, Integer, Number, Boolean, Array, Object)
MCP Types
Resource: MCP resource definition with URI, name, and metadataResourceContents: Content of a read resource (text or blob)Prompt: MCP prompt definition with argumentsPromptMessage: Message in a rendered prompt
Traits
Tool: Trait for implementing executable toolsTransport: Trait for implementing tool transport layers (MCP, HTTP, gRPC)
Usage
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!;
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!;
Working with MCP Resources
use ;
let resource = builder
.title
.mime_type
.description
.build;
let contents = text;
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
Testing
Benchmarking
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.