Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
Fix tool fetching issues when executing tools with specific version (#2518)
Musthaq Ahamade9e8db0147c3
diff --git a/ts/packages/core/src/models/Tools.ts b/ts/packages/core/src/models/Tools.tsindex 87edf55ab..b5c2b0ecb 100644--- a/ts/packages/core/src/models/Tools.ts+++ b/ts/packages/core/src/models/Tools.ts@@ -14,6 +14,7 @@ import {ToolExecuteParamsSchema,ToolkitVersionParam,SchemaModifierOptions,+ ToolRetrievalOptions,ToolExecuteMetaParamsSchema,} from '../types/tool.types';import {@@ -501,7 +502,7 @@ export class Tools<* });* ```*/- async getRawComposioToolBySlug(slug: string, options?: SchemaModifierOptions): Promise<Tool> {+ async getRawComposioToolBySlug(slug: string, options?: ToolRetrievalOptions): Promise<Tool> {// check if the tool is a custom toolconst customTool = await this.customTools.getCustomToolBySlug(slug);if (customTool) {@@ -513,9 +514,12 @@ export class Tools<// if not, fetch the tool from the Composio APIlet tool: ToolRetrieveResponse;try {- tool = await this.client.tools.retrieve(slug, {- toolkit_versions: this.toolkitVersions,- });+ // Build API call parameters based on version source+ const retrieveParams = options?.version+ ? { version: options.version } // Explicit version → use 'version' param+ : { toolkit_versions: this.toolkitVersions }; // SDK config → use 'toolkit_versions' param++ tool = await this.client.tools.retrieve(slug, retrieveParams);} catch (error) {throw new ComposioToolNotFoundError(`Unable to retrieve tool with slug ${slug}`, {cause: error,@@ -892,7 +896,11 @@ export class Tools<// Determine if it's a custom tool or composio toolconst customTool = await this.customTools.getCustomToolBySlug(slug);- const tool = customTool ?? (await this.getRawComposioToolBySlug(slug));+ const tool =+ customTool ??+ (await this.getRawComposioToolBySlug(slug, {+ version: body.version,+ }));const toolkitSlug = tool.toolkit?.slug ?? 'unknown';// Apply before execute modifiersdiff --git a/ts/packages/core/src/types/tool.types.ts b/ts/packages/core/src/types/tool.types.tsindex e245aedf0..54762d690 100644--- a/ts/packages/core/src/types/tool.types.ts+++ b/ts/packages/core/src/types/tool.types.ts@@ -364,3 +364,27 @@ export type ToolProxyParams = z.infer<typeof ToolProxyParamsSchema>;export type SchemaModifierOptions = {modifySchema: TransformToolSchemaModifier;};++/**+ * Options for retrieving tools from Composio API+ */+export type ToolRetrievalOptions = {+ /**+ * Optional function to transform the tool schema after retrieval+ */+ modifySchema?: TransformToolSchemaModifier;++ /**+ * Override the toolkit version for tool retrieval.+ * Takes precedence over SDK-level toolkitVersions.+ *+ * @example Override with specific version+ * ```typescript+ * const tool = await tools.getRawComposioToolBySlug('GITHUB_CREATE_ISSUE', {+ * version: '20250909_00'+ * });+ * ```+ * ```+ */+ version?: ToolkitVersion;+};diff --git a/ts/packages/core/test/tools/tools.test.ts b/ts/packages/core/test/tools/tools.test.tsindex 9c2844ad6..cc60f8d30 100644--- a/ts/packages/core/test/tools/tools.test.ts+++ b/ts/packages/core/test/tools/tools.test.ts@@ -368,6 +368,116 @@ describe('Tools', () => {expect(schemaModifier).toHaveBeenCalled();expect(result.description).toEqual('Modified description');});++ it('should use version parameter when provided (explicit version string)', async () => {+ const slug = 'GITHUB_CREATE_ISSUE';+ const explicitVersion = '20250909_00';++ mockClient.tools.retrieve.mockResolvedValueOnce(toolMocks.rawTool);++ await context.tools.getRawComposioToolBySlug(slug, {+ version: explicitVersion,+ });++ // Should use 'version' param, not 'toolkit_versions'+ expect(mockClient.tools.retrieve).toHaveBeenCalledWith(slug, {+ version: explicitVersion,+ });+ });++ it('should use version parameter when provided (latest string)', async () => {+ const slug = 'GITHUB_CREATE_ISSUE';++ mockClient.tools.retrieve.mockResolvedValueOnce(toolMocks.rawTool);++ await context.tools.getRawComposioToolBySlug(slug, {+ version: 'latest',+ });++ // Should use 'version' param with 'latest'+ expect(mockClient.tools.retrieve).toHaveBeenCalledWith(slug, {+ version: 'latest',+ });+ });++ it('should use version parameter when provided (version mapping object)', async () => {+ const slug = 'GITHUB_CREATE_ISSUE';+ const versionMapping = { github: '20250909_00', slack: 'latest' };++ mockClient.tools.retrieve.mockResolvedValueOnce(toolMocks.rawTool);++ // Create a Tools instance with SDK-level toolkitVersions as mapping object+ const toolsWithVersions = new Tools(mockClient as any, {+ provider: context.mockProvider,+ toolkitVersions: versionMapping,+ });++ await toolsWithVersions.getRawComposioToolBySlug(slug);++ // Should use 'toolkit_versions' param with mapping object (not 'version')+ expect(mockClient.tools.retrieve).toHaveBeenCalledWith(slug, {+ toolkit_versions: versionMapping,+ });+ });++ it('should fallback to SDK toolkitVersions when version not provided', async () => {+ const slug = 'GITHUB_CREATE_ISSUE';++ mockClient.tools.retrieve.mockResolvedValueOnce(toolMocks.rawTool);++ // Call without version option+ await context.tools.getRawComposioToolBySlug(slug);++ // Should use 'toolkit_versions' param with SDK-level config+ expect(mockClient.tools.retrieve).toHaveBeenCalledWith(slug, {+ toolkit_versions: 'latest',+ });+ });++ it('should prioritize explicit version over SDK toolkitVersions', async () => {+ const slug = 'GITHUB_CREATE_ISSUE';+ const explicitVersion = '20250909_00';++ // Create a Tools instance with SDK-level toolkitVersions+ const toolsWithVersions = new Tools(mockClient as any, {+ provider: context.mockProvider,+ toolkitVersions: { github: explicitVersion },+ });++ mockClient.tools.retrieve.mockResolvedValueOnce(toolMocks.rawTool);++ await toolsWithVersions.getRawComposioToolBySlug(slug, {+ version: explicitVersion,+ });++ // Explicit version should take precedence, using 'version' param+ expect(mockClient.tools.retrieve).toHaveBeenCalledWith(slug, {+ version: explicitVersion,+ });+ });++ it('should support combining version and modifySchema options', async () => {+ const slug = 'GITHUB_CREATE_ISSUE';+ const explicitVersion = '20250909_00';+ const schemaModifier = createSchemaModifier({+ description: 'Modified description',+ });++ mockClient.tools.retrieve.mockResolvedValueOnce(toolMocks.rawTool);++ const result = await context.tools.getRawComposioToolBySlug(slug, {+ version: explicitVersion,+ modifySchema: schemaModifier,+ });++ // Should use version param+ expect(mockClient.tools.retrieve).toHaveBeenCalledWith(slug, {+ version: explicitVersion,+ });+ // Should also apply schema modifier+ expect(schemaModifier).toHaveBeenCalled();+ expect(result.description).toEqual('Modified description');+ });});describe('get', () => {@@ -500,6 +610,70 @@ describe('Tools', () => {});expect(result).toEqual(toolMocks.toolExecuteResponse);});++ it('should pass version parameter from execute() to getRawComposioToolBySlug()', async () => {+ const slug = 'COMPOSIO_TOOL';+ const explicitVersion = '20250909_00';+ const body = {+ userId: 'test-user',+ version: explicitVersion,+ arguments: { title: 'Test Issue' },+ };++ const { getRawComposioToolBySlugSpy } = await mockToolExecution(context.tools);++ await context.tools.execute(slug, body);++ // Verify getRawComposioToolBySlug was called with version+ expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(slug, {+ version: explicitVersion,+ });++ // Verify the API execute call received the version+ expect(mockClient.tools.execute).toHaveBeenCalledWith(+ slug,+ expect.objectContaining({+ version: explicitVersion,+ })+ );+ });++ it('should pass version: latest from execute() to getRawComposioToolBySlug()', async () => {+ const slug = 'COMPOSIO_TOOL';+ const body = {+ userId: 'test-user',+ version: 'latest' as const,+ dangerouslySkipVersionCheck: true,+ arguments: { title: 'Test Issue' },+ };++ const { getRawComposioToolBySlugSpy } = await mockToolExecution(context.tools);++ await context.tools.execute(slug, body);++ // Verify getRawComposioToolBySlug was called with version: 'latest'+ expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(slug, {+ version: 'latest',+ });+ });++ it('should not pass version to getRawComposioToolBySlug() when not provided in execute()', async () => {+ const slug = 'COMPOSIO_TOOL';+ const body = {+ userId: 'test-user',+ arguments: { title: 'Test Issue' },+ dangerouslySkipVersionCheck: true,+ };++ const { getRawComposioToolBySlugSpy } = await mockToolExecution(context.tools);++ await context.tools.execute(slug, body);++ // Verify getRawComposioToolBySlug was called without version (should fallback to SDK config)+ expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(slug, {+ version: undefined,+ });+ });});describe('proxyExecute', () => {