Skip to main content
This example demonstrates how to create custom tools with Composio, including both standalone tools and toolkit-integrated tools that can access authentication credentials.

Overview

In this example, you’ll learn how to:
  • Create custom tools with Zod schemas
  • Integrate custom tools with existing toolkits
  • Access authentication credentials in custom tools
  • Execute HTTP requests within custom tool logic
  • Use custom tools in your applications

Prerequisites

1

Install dependencies

2

Set up environment variables

Create a .env file with your API key:

Complete Example

How It Works

1

Define Tool Schema

Use Zod to define the input parameters for your tool. Each parameter should have a description for better AI understanding.
2

Specify Toolkit Integration

By setting toolkitSlug: 'github', the custom tool inherits GitHub’s authentication and can make authenticated API calls.
3

Implement Execute Function

The execute function receives three parameters:
  • input: The validated input parameters
  • connectionConfig: Authentication credentials for the toolkit
  • executeToolRequest: Helper function to make authenticated HTTP requests
4

Make API Requests

Use executeToolRequest to make authenticated requests to the toolkit’s API. It automatically handles authentication headers.
5

Execute the Tool

Call composio.tools.execute() with the tool slug and arguments to run your custom tool.

Execute Function Parameters

object
The validated input parameters matching your Zod schema
object
Authentication credentials and configuration for the associated toolkit
function
Helper function to make authenticated HTTP requests

Expected Output

Creating Standalone Custom Tools

You can also create custom tools without toolkit integration:

Use Cases

Custom Business Logic

Wrap your internal APIs and business logic as tools for AI agents

API Extensions

Extend existing toolkit capabilities with custom endpoints

Data Transformations

Create tools that transform or aggregate data from multiple sources

Validation & Processing

Add custom validation or preprocessing before calling external APIs

Best Practices

Always add clear descriptions to your Zod schema fields. These descriptions help AI models understand how to use your tool correctly.
Always return a consistent result format with successful, data, and error fields to make error handling predictable.
Use toolkitSlug when your tool needs to authenticate with an existing service. This provides automatic credential management.

Next Steps

File Handling

Learn how to handle file uploads in tools

OpenAI Example

Use custom tools with OpenAI