Skip to main content

Schema Quick Reference

Compact reference for CTP schemas, designed for quick AI lookups.

Tool Definition

interface ToolDefinition {
  // Required
  id: string;                    // lowercase-hyphen-separated
  name: string;                  // Display name (max 50)
  description: string;           // What it does (max 500)
  category: Category;            // See categories below
  tags: string[];                // Search tags (min 1)
  method: 'GET' | 'POST';        // HTTP method
  parameters: Parameter[];       // Input params
  outputDescription: string;     // Output description
  example: { input: object; output: object };

  // Optional
  version?: string;              // Semver "1.0.0"
  icon?: string;                 // Emoji or icon ID
  aiInstructions?: string;       // AI guidance
  executionMode?: 'client' | 'server' | 'hybrid';
  requiresAuth?: boolean;
  rateLimit?: { requests: number; window: number };
}

Parameter Types

TypeInputUse Case
textSingle lineShort strings
textareaMulti-lineLong text, code
numberNumericCounts, sizes
booleanToggleFlags, options
selectDropdownFixed choices
jsonJSON editorStructured data
fileFile pickerUploads
colorColor pickerColors
dateDate pickerDates
datetimeDateTimeTimestamps
urlURL inputLinks
emailEmail inputAddresses

Parameter Schema

interface Parameter {
  name: string;              // camelCase
  type: ParameterType;       // See types above
  label: string;             // Display label
  description: string;       // Help text
  required: boolean;

  // Optional
  defaultValue?: any;
  placeholder?: string;
  options?: Option[];        // For select
  validation?: Validation;
  dependsOn?: Dependency[];
  aiHint?: string;
  group?: string;
  order?: number;
  hidden?: boolean;
}

Categories

CategoryPurpose
formattersFormat data (JSON, SQL, XML)
encodersEncode/decode (Base64, URL)
generatorsGenerate (UUID, hash, password)
convertersConvert formats (units, colors)
validatorsValidate (JSON, email, URL)
analyzersAnalyze (diff, regex)
editorsTransform (case, replace)
utilitiesGeneral utilities

Error Codes

CodeHTTPCause
INVALID_INPUT400Bad input format
MISSING_REQUIRED400Required param missing
TYPE_ERROR400Wrong type
CONSTRAINT_VIOLATION400Out of range
EXECUTION_ERROR500Runtime error
TIMEOUT504Too slow
RATE_LIMITED429Too many requests
UNAUTHORIZED401Auth required

Result Format

// Success
{
  success: true,
  data: { /* result */ },
  metadata?: { executionTime?: number; warnings?: string[] }
}

// Error
{
  success: false,
  error: "Message",
  errorCode: "ERROR_CODE",
  suggestion?: "How to fix"
}

Validation Constraints

interface Validation {
  minLength?: number;     // String min
  maxLength?: number;     // String max
  pattern?: string;       // Regex pattern
  min?: number;           // Number min
  max?: number;           // Number max
  step?: number;          // Number step
  accept?: string[];      // File types
  maxSize?: number;       // File bytes
}

Conditional Display

dependsOn: [
  { field: 'mode', condition: 'equals', value: 'advanced' }
]
Conditions: equals, notEquals, contains, exists

Select Options

options: [
  { value: 'opt1', label: 'Option 1' },
  { value: 'opt2', label: 'Option 2', description: 'With description' },
  { value: 'opt3', label: 'Option 3', disabled: true }
]

Execution Modes

ModeWhereUse Case
clientBrowserMost tools, privacy
serverNode.jsFile system, DB
hybridBothFlexible deployment

Common Patterns

Sync Tool

const fn: ToolFunction = (params) => {
  return { success: true, data: result };
};

Async Tool

const fn: ToolFunction = async (params) => {
  const result = await asyncOp();
  return { success: true, data: result };
};

With Validation

if (!params.input) {
  return { success: false, error: 'Required', errorCode: 'MISSING_REQUIRED' };
}

With Metadata

return {
  success: true,
  data: result,
  metadata: { executionTime: Date.now() - start }
};