Tools

@composio/core


@composio/core / models/Tools / Tools

Class: Tools<TToolCollection, TTool, TProvider>

Defined in: ts/packages/core/src/models/Tools.ts:47

This class is used to manage tools in the Composio SDK. It provides methods to list, get, and execute tools.

Type Parameters

TToolCollection

TToolCollection

TTool

TTool

TProvider

TProvider extends BaseComposioProvider<TToolCollection, TTool, unknown>

Constructors

Constructor

new Tools<TToolCollection, TTool, TProvider>(client, provider): Tools<TToolCollection, TTool, TProvider>

Defined in: ts/packages/core/src/models/Tools.ts:56

Parameters

client

Composio

provider

TProvider

Returns

Tools<TToolCollection, TTool, TProvider>

Methods

createCustomTool()

createCustomTool<T>(body): Promise<{ }>

Defined in: ts/packages/core/src/models/Tools.ts:780

Creates a custom tool that can be used within the Composio SDK.

Custom tools allow you to extend the functionality of Composio with your own implementations while keeping a consistent interface for both built-in and custom tools.

Type Parameters

T

T extends CustomToolInputParameter

Parameters

body

CustomToolOptions<T>

The configuration for the custom tool

Returns

Promise<{ }>

The created custom tool

Examples

1// creating a custom tool with a toolkit
2await composio.tools.createCustomTool({
3 name: 'My Custom Tool',
4 description: 'A custom tool that does something specific',
5 slug: 'MY_CUSTOM_TOOL',
6 userId: 'default',
7 connectedAccountId: '123',
8 toolkitSlug: 'github',
9 inputParameters: z.object({
10 param1: z.string().describe('First parameter'),
11 }),
12 execute: async (input, connectionConfig, executeToolRequest) => {
13 // Custom logic here
14 return { data: { result: 'Success!' } };
15 }
16});
1// creating a custom tool without a toolkit
2await composio.tools.createCustomTool({
3 name: 'My Custom Tool',
4 description: 'A custom tool that does something specific',
5 slug: 'MY_CUSTOM_TOOL',
6 inputParameters: z.object({
7 param1: z.string().describe('First parameter'),
8 }),
9 execute: async (input) => {
10 // Custom logic here
11 return { data: { result: 'Success!' } };
12 }
13});
14
15***
16
17### execute()
18
19> **execute**(`slug`, `body`, `modifiers?`): `Promise`\<\{ \}\>
20
21Defined in: ts/packages/core/src/models/Tools.ts:605
22
23Executes a given tool with the provided parameters.
24
25This method calls the Composio API or a custom tool handler to execute the tool and returns the response.
26It automatically determines whether to use a custom tool or a Composio API tool based on the slug.
27
28#### Parameters
29
30##### slug
31
32`string`
33
34The slug/ID of the tool to be executed
35
36##### body
37
38The parameters to be passed to the tool
39
40##### modifiers?
41
42`ExecuteToolModifiers`
43
44Optional modifiers to transform the request or response
45
46#### Returns
47
48`Promise`\<\{ \}\>
49
50- The response from the tool execution
51
52#### Throws
53
54If the CustomTools instance is not initialized
55
56#### Throws
57
58If the tool with the given slug is not found
59
60#### Throws
61
62If there is an error during tool execution
63
64#### Example
65
66```typescript
67// Execute a Composio API tool
68const result = await composio.tools.execute('HACKERNEWS_GET_USER', {
69 userId: 'default',
70 arguments: { userId: 'pg' }
71});
72
73// Execute with modifiers
74const result = await composio.tools.execute('GITHUB_GET_ISSUES', {
75 userId: 'default',
76 arguments: { owner: 'composio', repo: 'sdk' }
77}, {
78 beforeExecute: (toolSlug, toolkitSlug, params) => {
79 // Modify params before execution
80 return params;
81 },
82 afterExecute: (toolSlug, toolkitSlug, result) => {
83 // Transform result after execution
84 return result;
85 }
86});

get()

Get a tool or list of tools based on the provided arguments. This is an implementation method that handles both overloads.

Param

The user id to get the tool(s) for

Param

Either a slug string or filters object

Param

Optional provider options

Call Signature

get<T>(userId, filters, options?): Promise<ReturnType<T["wrapTools"]>>

Defined in: ts/packages/core/src/models/Tools.ts:396

Get a list of tools from Composio based on filters. This method fetches the tools from the Composio API and wraps them using the provider.

Type Parameters
T

T extends BaseComposioProvider<TToolCollection, TTool, unknown>

Parameters
userId

string

The user id to get the tools for

filters

ToolListParams

The filters to apply when fetching tools

options?

ProviderOptions<TProvider>

Optional provider options including modifiers

Returns

Promise<ReturnType<T["wrapTools"]>>

The tool collection

Param

The user id to get the tool(s) for

Param

Either a slug string or filters object

Param

Optional provider options

Example
1// Get tools from the GitHub toolkit
2const tools = await composio.tools.get('default', {
3 toolkits: ['github'],
4 limit: 10
5});
6
7// Get tools with search
8const tools = await composio.tools.get('default', {
9 search: 'user',
10 important: true
11});

Call Signature

get<T>(userId, slug, options?): Promise<ReturnType<T["wrapTools"]>>

Defined in: ts/packages/core/src/models/Tools.ts:425

Get a specific tool by its slug. This method fetches the tool from the Composio API and wraps it using the provider.

Type Parameters
T

T extends BaseComposioProvider<TToolCollection, TTool, unknown>

Parameters
userId

string

The user id to get the tool for

slug

string

The slug of the tool to fetch

options?

ProviderOptions<TProvider>

Optional provider options including modifiers

Returns

Promise<ReturnType<T["wrapTools"]>>

The tool collection

Param

The user id to get the tool(s) for

Param

Either a slug string or filters object

Param

Optional provider options

Example
1// Get a specific tool by slug
2const hackerNewsUserTool = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
3
4// Get a tool with schema modifications
5const tool = await composio.tools.get('default', 'GITHUB_GET_REPOS', {
6 modifySchema: (toolSlug, toolkitSlug, schema) => {
7 // Customize the tool schema
8 return {...schema, description: 'Custom description'};
9 }
10});

getInput()

getInput(slug, body): Promise<ToolGetInputResponse>

Defined in: ts/packages/core/src/models/Tools.ts:676

Fetches the input parameters for a given tool.

This method is used to get the input parameters for a tool before executing it.

Parameters

slug

string

The ID of the tool to find input for

body

ToolGetInputParams

The parameters to be passed to the tool

Returns

Promise<ToolGetInputResponse>

The input parameters schema for the specified tool

Example

1// Get input parameters for a specific tool
2const inputParams = await composio.tools.getInput('GITHUB_CREATE_ISSUE', {
3 userId: 'default'
4});
5console.log(inputParams.schema);

getRawComposioToolBySlug()

getRawComposioToolBySlug(slug, modifier?): Promise<{ }>

Defined in: ts/packages/core/src/models/Tools.ts:337

Retrieves a tool by its Slug. This method is used to get the raw tools from the composio API.

Parameters

slug

string

The ID of the tool to be retrieved

modifier?

TransformToolSchemaModifier

Returns

Promise<{ }>

The tool

Example

1const tool = await composio.tools.getRawComposioToolBySlug('github');

getRawComposioTools()

getRawComposioTools(query?, modifier?): Promise<ToolList>

Defined in: ts/packages/core/src/models/Tools.ts:250

Lists all tools available in the Composio SDK including custom tools.

This method fetches tools from the Composio API in raw format and combines them with any registered custom tools. The response can be filtered and modified as needed.

Parameters

query?

ToolListParams

Optional query parameters to filter the tools

modifier?

TransformToolSchemaModifier

Optional function to transform tool schemas

Returns

Promise<ToolList>

List of tools matching the query criteria

Example

1// Get all tools
2const tools = await composio.tools.getRawComposioTools();
3
4// Get tools with filters
5const githubTools = await composio.tools.getRawComposioTools({
6 toolkits: ['github'],
7 important: true
8});
9
10// Get tools with schema transformation
11const tools = await composio.tools.getRawComposioTools({},
12 (toolSlug, toolkitSlug, tool) => {
13 // Add custom properties to tool schema
14 return {...tool, customProperty: 'value'};
15 }
16);

getToolsEnum()

getToolsEnum(): Promise<string>

Defined in: ts/packages/core/src/models/Tools.ts:654

Fetches the list of all available tools in the Composio SDK.

This method is mostly used by the CLI to get the list of tools. No filtering is done on the tools, the list is cached in the backend, no further optimization is required.

Returns

Promise<string>

The complete list of all available tools with their metadata

Example

1// Get all available tools as an enum
2const toolsEnum = await composio.tools.getToolsEnum();
3console.log(toolsEnum.items);

proxyExecute()

proxyExecute(body): Promise<ToolProxyResponse>

Defined in: ts/packages/core/src/models/Tools.ts:703

Proxies a custom request to a toolkit/integration.

This method allows sending custom requests to a specific toolkit or integration when you need more flexibility than the standard tool execution methods provide.

Parameters

body

The parameters for the proxy request including toolkit slug and custom data

Returns

Promise<ToolProxyResponse>

The response from the proxied request

Example

1// Send a custom request to a toolkit
2const response = await composio.tools.proxyExecute({
3 toolkitSlug: 'github',
4 userId: 'default',
5 data: {
6 endpoint: '/repos/owner/repo/issues',
7 method: 'GET'
8 }
9});
10console.log(response.data);