Skip to main content

Custom Tools

Custom tools allow you to extend the Composio SDK with your own implementations while maintaining a consistent interface with built-in tools. Create custom logic, wrap external APIs, or build specialized functionality tailored to your use case.

Overview

The CustomTools class manages user-created tools that can be registered, retrieved, and executed alongside Composio’s built-in tools. Custom tools are stored in an in-memory registry and support the same execution patterns as native tools. Source: ts/packages/core/src/models/CustomTools.ts

Creating Custom Tools

Basic Custom Tool

Create a simple custom tool without external dependencies:

Custom Tool with Optional Parameters

Custom Tools with Toolkit Integration

Create custom tools that leverage existing toolkit credentials:
When a toolkitSlug is provided, the custom tool can access authentication credentials from connected accounts and use executeToolRequest to make authenticated API calls.

Execute Function Parameters

The execute function receives three parameters:

1. Input (parsed and validated)

The input parameters after Zod schema validation:

2. Connection Config (nullable)

Authentication credentials when using a toolkit:

3. Execute Tool Request (function)

Make authenticated API calls to the toolkit:
executeToolRequest is only available when toolkitSlug is specified and is not ‘custom’. It provides a proxy to make authenticated requests using the connected account’s credentials.

Retrieving Custom Tools

Get All Custom Tools

Get Specific Custom Tools

Get a Single Custom Tool

Executing Custom Tools

Custom tools can be executed using the same API as built-in tools:

Integration with Provider Tools

Custom tools work seamlessly with Composio providers:

Custom Tool Schema Generation

The SDK automatically generates JSON Schema from Zod schemas:
Zod provides excellent TypeScript inference, so your custom tool execute functions are fully type-safe without additional type annotations.

Error Handling in Custom Tools

Complete Example: Custom Slack Tool

Custom Tool Properties

Registered custom tools have the same properties as built-in tools:
  • slug - Unique identifier
  • name - Human-readable name
  • description - Tool description
  • inputParameters - JSON Schema for input (auto-generated from Zod)
  • outputParameters - JSON Schema for output
  • toolkit - Always set to { name: 'custom', slug: 'custom' } unless toolkitSlug is specified
  • tags - Empty array (can be customized in future versions)

Limitations and Considerations

In-Memory Registry: Custom tools are stored in memory and are not persisted. You need to re-register them when creating a new Composio instance.
  • Custom tools are scoped to the Composio instance
  • The toolkitSlug in custom tools is used for authentication, not for categorization
  • When using executeToolRequest, the toolkit must not be ‘custom’
  • Input validation is automatic via Zod schemas
  • Output schema is currently a placeholder (future enhancement)

Error Handling

Common errors when working with custom tools:
  • ComposioToolNotFoundError - Custom tool not found in registry
  • ComposioInvalidExecuteFunctionError - Invalid or missing execute function
  • ComposioConnectedAccountNotFoundError - No connected account for specified toolkit
  • ValidationError - Input parameters don’t match Zod schema

Best Practices

  1. Use descriptive slugs: Make tool slugs clear and unique (e.g., COMPANY_ACTION_OBJECT)
  2. Provide detailed descriptions: Help AI models understand when to use your tool
  3. Validate inputs thoroughly: Use Zod’s rich validation features
  4. Handle errors gracefully: Return structured errors in the response
  5. Document parameters: Use .describe() on all Zod fields
  6. Keep tools focused: Each tool should do one thing well
  7. Reuse toolkit credentials: Leverage existing connections when possible