Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Update custom tools

haxzie9a45854f96c1
diff --git a/examples/custom-tools/README.md b/examples/custom-tools/README.md
index fa4fcb65c..92e26467b 100644
--- a/examples/custom-tools/README.md
+++ b/examples/custom-tools/README.md
@@ -85,7 +85,7 @@ const tool = await composio.tools.createCustomTool({
{
method: 'PUT',
headers: {
- Authorization: `Bearer ${authCredentials?.access_token}`,
+ Authorization: `Bearer ${authCredentials.val?.access_token}`,
},
}
);
diff --git a/packages/core/src/models/CustomTools.ts b/packages/core/src/models/CustomTools.ts
index 2c91bf7e5..d5aa1c3ca 100644
--- a/packages/core/src/models/CustomTools.ts
+++ b/packages/core/src/models/CustomTools.ts
@@ -28,12 +28,10 @@ import {
import { ComposioConnectedAccountNotFoundError } from '../errors/ConnectedAccountsErrors';
import { ComposioError } from '../errors/ComposioError';
import { telemetry } from '../telemetry/Telemetry';
-import {
- ConnectedAccountRetrieveResponse,
- ConnectedAccountRetrieveResponseSchema,
-} from '../types/connectedAccounts.types';
+import { ConnectedAccountRetrieveResponse } from '../types/connectedAccounts.types';
import { ValidationError } from '../errors';
import { transformConnectedAccountResponse } from '../utils/transformers/connectedAccounts';
+import { ConnectionData } from '../types/connectedAccountAuthStates.types';
export class CustomTools {
private readonly client: ComposioClient;
@@ -241,7 +239,7 @@ export class CustomTools {
throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
}
- let authCredentials: Record<string, unknown> = {};
+ let authCredentials: ConnectionData | null = null;
const { toolkitSlug, execute, inputParams } = tool.options;
// if a toolkit is used, get the connected account, and auth credentials
let connectedAccountId: string | undefined = body.connectedAccountId;
@@ -267,7 +265,7 @@ export class CustomTools {
}
);
}
- authCredentials = connectedAccount.data as Record<string, unknown>;
+ authCredentials = connectedAccount.state ?? null;
connectedAccountId = connectedAccount.id;
}
diff --git a/packages/core/src/types/customTool.types.ts b/packages/core/src/types/customTool.types.ts
index 787686597..92b847a9f 100644
--- a/packages/core/src/types/customTool.types.ts
+++ b/packages/core/src/types/customTool.types.ts
@@ -1,6 +1,7 @@
import { z } from 'zod';
import { Tool, ToolProxyParams } from './tool.types';
import { ToolExecuteResponse } from '@composio/client/resources/tools';
+import { ConnectionData } from './connectedAccountAuthStates.types';
type BaseCustomToolOptions<T extends z.ZodType> = {
name: string;
@@ -12,7 +13,7 @@ type BaseCustomToolOptions<T extends z.ZodType> = {
type ToolkitBasedExecute<T extends z.ZodType> = {
execute: (
input: z.infer<T>,
- authCredentials: Record<string, unknown>,
+ authCredentials: ConnectionData | null,
executeToolRequest: (data: ToolProxyParams) => Promise<ToolExecuteResponse>
) => Promise<ToolExecuteResponse>;
toolkitSlug: string;
diff --git a/packages/json-schema-to-zod/package.json b/packages/json-schema-to-zod/package.json
index 2073d71ed..f604e316b 100644
--- a/packages/json-schema-to-zod/package.json
+++ b/packages/json-schema-to-zod/package.json
@@ -35,6 +35,7 @@
"vitest": "^3.1.4"
},
"dependencies": {
+ "@types/json-schema": "^7.0.15",
"zod": "^3.24.2"
}
}
diff --git a/packages/json-schema-to-zod/src/types.ts b/packages/json-schema-to-zod/src/types.ts
index ec0c4f311..63a467bed 100644
--- a/packages/json-schema-to-zod/src/types.ts
+++ b/packages/json-schema-to-zod/src/types.ts
@@ -1,4 +1,5 @@
import type { ZodTypeAny } from 'zod';
+import type { JSONSchema7 } from 'json-schema';
export type Serializable =
| { [key: string]: Serializable }
@@ -9,64 +10,7 @@ export type Serializable =
| null;
export type JsonSchema = JsonSchemaObject | boolean;
-export type JsonSchemaObject = {
- // left permissive by design
- type?: string | string[];
-
- // object
- properties?: { [key: string]: JsonSchema };
- additionalProperties?: JsonSchema;
- unevaluatedProperties?: JsonSchema;
- patternProperties?: { [key: string]: JsonSchema };
- minProperties?: number;
- maxProperties?: number;
- required?: string[] | boolean;
- propertyNames?: JsonSchema;
-
- // array
- items?: JsonSchema | JsonSchema[];
- additionalItems?: JsonSchema;
- minItems?: number;
- maxItems?: number;
- uniqueItems?: boolean;
-
- // string
- minLength?: number;
- maxLength?: number;
- pattern?: string;
- format?: string;
-
- // number
- minimum?: number;
- maximum?: number;
- exclusiveMinimum?: number | boolean;
- exclusiveMaximum?: number | boolean;
- multipleOf?: number;
-
- // unions
- anyOf?: JsonSchema[];
- allOf?: JsonSchema[];
- oneOf?: JsonSchema[];
-
- if?: JsonSchema;
- then?: JsonSchema;
- else?: JsonSchema;
-
- // shared
- const?: Serializable;
- enum?: Serializable[];
-
- errorMessage?: { [key: string]: string | undefined };
-
- description?: string;
- title?: string;
- default?: Serializable;
- readOnly?: boolean;
- not?: JsonSchema;
- contentEncoding?: string;
- nullable?: boolean;
-};
-
+export type JsonSchemaObject = JSONSchema7;
export type ParserSelector = (schema: JsonSchemaObject, refs: Refs) => ZodTypeAny;
export type ParserOverride = (schema: JsonSchemaObject, refs: Refs) => ZodTypeAny | undefined;
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 85c06a542..64372f5fb 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -452,6 +452,9 @@ importers:
packages/json-schema-to-zod:
dependencies:
+ '@types/json-schema':
+ specifier: ^7.0.15
+ version: 7.0.15
zod:
specifier: ^3.24.2
version: 3.25.62
@@ -9748,6 +9751,14 @@ snapshots:
chai: 5.2.0
tinyrainbow: 2.0.0
+ dependencies:
+ '@vitest/spy': 3.2.3
+ estree-walker: 3.0.3
+ magic-string: 0.30.17
+ optionalDependencies:
+
dependencies:
'@vitest/spy': 3.2.3
@@ -9756,6 +9767,14 @@ snapshots:
optionalDependencies:
+ dependencies:
+ '@vitest/spy': 3.2.3
+ estree-walker: 3.0.3
+ magic-string: 0.30.17
+ optionalDependencies:
+
'@vitest/[email protected]':
dependencies:
tinyrainbow: 2.0.0
@@ -9785,7 +9804,7 @@ snapshots:
sirv: 3.0.1
tinyglobby: 0.2.14
tinyrainbow: 2.0.0
'@vitest/[email protected]':
dependencies:
@@ -12141,7 +12160,7 @@ snapshots:
dependencies:
'@types/chai': 5.2.2
'@vitest/expect': 3.2.3
'@vitest/pretty-format': 3.2.3
'@vitest/runner': 3.2.3
'@vitest/snapshot': 3.2.3
@@ -12225,7 +12244,7 @@ snapshots:
dependencies:
'@types/chai': 5.2.2
'@vitest/expect': 3.2.3
'@vitest/pretty-format': 3.2.3
'@vitest/runner': 3.2.3
'@vitest/snapshot': 3.2.3
diff --git a/ts/docs/api/custom-tools.md b/ts/docs/api/custom-tools.md
index 54161b9ec..5ed1b1dd8 100644
--- a/ts/docs/api/custom-tools.md
+++ b/ts/docs/api/custom-tools.md
@@ -90,7 +90,7 @@ const tool = await composio.tools.createCustomTool({
// Use authCredentials for direct API calls
const result = await fetch(`https://api.github.com/repos/${input.repo}`, {
headers: {
- Authorization: `Bearer ${authCredentials.access_token}`,
+ Authorization: `Bearer ${authCredentials.val?.access_token}`,
},
});