Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
fix(core): reuse fetched schemas for provider execution (#4103)
Reuse fetched raw tool schemas for provider-wrapped execution while preserving modifier isolation, runtime validation, and unknown-slug fallback behavior. Refresh the Python 3.12.13 mise lock entries required by the Audit freshness gate. Co-authored-by: breezeFur <voidexl@outlook.com>
Alberto Schiabel committed
Aug 10, 2026 at 13:34 UTC
c625edc0f7d63fa543b0819d5b8ec71136fec669
5 files changed
+263
-135
.changeset/reuse-provider-tool-schemas.md
new
+5
@@ -0,0 +1,5 @@
1
+---
2
+'@composio/core': patch
3
+---
4
+
5
+Reuse fetched tool schemas when provider-wrapped tools execute to avoid a redundant retrieval request.
mise.lock
+8
-8
@@ -89,23 +89,23 @@ version = "3.12.13"
89
backend = "core:python"
90
91
[tools.python."platforms.linux-arm64"]
92
-checksum = "sha256:f3510827b61e7a2aa89a1bb7bac73d45521939c489cf43f4699618efaead0611"
93
-url = "https://github.com/astral-sh/python-build-standalone/releases/download/20260805/cpython-3.12.13+20260805-aarch64-unknown-linux-gnu-install_only_stripped.tar.gz"
92
+checksum = "sha256:11e713ae1f969385907a76533cc554f6b2e3f1a84896009f91c3fc871034a170"
93
+url = "https://github.com/astral-sh/python-build-standalone/releases/download/20260807/cpython-3.12.13+20260807-aarch64-unknown-linux-gnu-install_only_stripped.tar.gz"
94
provenance = "github-attestations"
95
96
[tools.python."platforms.linux-x64"]
97
-checksum = "sha256:f04a55ae95e8bd352cdff8da11c344fe609ec84795d106fa91b6620366d786fe"
98
-url = "https://github.com/astral-sh/python-build-standalone/releases/download/20260805/cpython-3.12.13+20260805-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz"
97
+checksum = "sha256:506191be3ee7bd190a8834dcdc1b3bc70aab50608deccc711935aa007239cabd"
98
+url = "https://github.com/astral-sh/python-build-standalone/releases/download/20260807/cpython-3.12.13+20260807-x86_64-unknown-linux-gnu-install_only_stripped.tar.gz"
99
provenance = "github-attestations"
100
101
[tools.python."platforms.macos-arm64"]
102
-checksum = "sha256:a4b36035915038104aabee94d6f02827161da444296881fe4493cb98f70304b2"
103
-url = "https://github.com/astral-sh/python-build-standalone/releases/download/20260805/cpython-3.12.13+20260805-aarch64-apple-darwin-install_only_stripped.tar.gz"
102
+checksum = "sha256:25baa97c65b3f0aa90e21131b4f9e80aef8899e8144006db8a9d2c1ab9e807e3"
103
+url = "https://github.com/astral-sh/python-build-standalone/releases/download/20260807/cpython-3.12.13+20260807-aarch64-apple-darwin-install_only_stripped.tar.gz"
104
provenance = "github-attestations"
105
106
[tools.python."platforms.macos-x64"]
107
-checksum = "sha256:0d232711501680a619ea6113046603567d93be3218e326e4357557e771d1aec7"
108
-url = "https://github.com/astral-sh/python-build-standalone/releases/download/20260805/cpython-3.12.13+20260805-x86_64-apple-darwin-install_only_stripped.tar.gz"
107
+checksum = "sha256:127053f1736f721e391ddb46f07585d05756e15bb8d757d3bbc0519738998ba1"
108
+url = "https://github.com/astral-sh/python-build-standalone/releases/download/20260807/cpython-3.12.13+20260807-x86_64-apple-darwin-install_only_stripped.tar.gz"
109
provenance = "github-attestations"
110
111
[[tools.uv]]
ts/packages/core/src/models/Tools.ts
+108
-77
@@ -470,14 +470,12 @@ export class Tools<
470
'important' in queryParams.data ? queryParams.data.important : shouldAutoApplyImportant;
471
472
// check if the query params contains atleast one of the following: tools, toolkits, search, authConfigIds
473
- if (
474
- !(
475
- 'tools' in queryParams.data ||
476
- 'toolkits' in queryParams.data ||
477
- 'search' in queryParams.data ||
478
- 'authConfigIds' in queryParams.data
479
- )
480
- ) {
473
+ if (!(
474
+ 'tools' in queryParams.data ||
475
+ 'toolkits' in queryParams.data ||
476
+ 'search' in queryParams.data ||
477
+ 'authConfigIds' in queryParams.data
478
+ )) {
479
throw new ValidationError(
480
'Invalid tool list parameters, atleast one of the following parameters is required: tools, toolkits, search, authConfigIds'
481
);
@@ -766,33 +764,44 @@ export class Tools<
764
const { signal: _, ...modifiers } = options ?? {};
765
766
if (typeof arg2 === 'string') {
769
- const tool = await this.getRawComposioToolBySlug(
770
- arg2,
771
- {
772
- modifySchema: options?.modifySchema as TransformToolSchemaModifier,
773
- },
774
- requestOptions
775
- );
776
- return this.wrapToolsForProvider(
777
- userId,
778
- [tool],
779
- modifiers as ExecuteToolModifiers
780
- ) as TToolCollection;
767
+ const rawTool = await this.getRawComposioToolBySlug(arg2, undefined, requestOptions);
768
+ const [tool] = await this.applySchemaModifiers([rawTool], options?.modifySchema);
769
+ return this.wrapToolsForProvider(userId, [tool], modifiers as ExecuteToolModifiers, [
770
+ rawTool,
771
+ ]) as TToolCollection;
772
} else {
782
- const tools = await this.getRawComposioTools(
783
- arg2,
784
- {
785
- modifySchema: options?.modifySchema as TransformToolSchemaModifier,
786
- },
787
- requestOptions
788
- );
773
+ const rawTools = await this.getRawComposioTools(arg2, undefined, requestOptions);
774
+ const tools = await this.applySchemaModifiers(rawTools, options?.modifySchema);
775
return this.wrapToolsForProvider(
776
userId,
777
tools,
792
- modifiers as ExecuteToolModifiers
778
+ modifiers as ExecuteToolModifiers,
779
+ rawTools
780
) as TToolCollection;
781
}
782
}
783
+
784
+ private async applySchemaModifiers(
785
+ tools: Tool[],
786
+ modifier?: TransformToolSchemaModifier
787
+ ): Promise<Tool[]> {
788
+ if (modifier && typeof modifier !== 'function') {
789
+ throw new ComposioInvalidModifierError('Invalid schema modifier. Not a function.');
790
+ }
791
+ return Promise.all(
792
+ tools.map(tool => {
793
+ const schema = ToolSchema.parse(tool);
794
+ return modifier
795
+ ? modifier({
796
+ toolSlug: tool.slug,
797
+ toolkitSlug: tool.toolkit?.slug ?? 'unknown',
798
+ schema,
799
+ })
800
+ : schema;
801
+ })
802
+ );
803
+ }
804
+
805
/**
806
* @internal
807
* Creates a global execute tool function.
@@ -817,14 +826,16 @@ export class Tools<
826
* @param userId - The user id to get the tools for
827
* @param tools - The tools to wrap
828
* @param modifiers - The modifiers to be applied to the tools
829
+ * @param rawTools - The fetched schemas used during execution
830
* @returns The wrapped tools
831
*/
832
wrapToolsForProvider<T extends TProvider>(
833
userId: string,
834
tools: Tool[],
825
- modifiers?: ExecuteToolModifiers
835
+ modifiers?: ExecuteToolModifiers,
836
+ rawTools: Tool[] = tools.map(tool => ToolSchema.parse(tool))
837
): ReturnType<T['wrapTools']> {
827
- const executeToolFn = this.createExecuteToolFn(userId, modifiers);
838
+ const executeToolFn = this.createExecuteToolFn(userId, modifiers, rawTools);
839
return this.provider.wrapTools(tools, executeToolFn) as ReturnType<T['wrapTools']>;
840
}
841
@@ -854,21 +865,27 @@ export class Tools<
865
*
866
* @param {string} userId - The user id
867
* @param {ExecuteToolModifiers} modifiers - The modifiers to be applied to the tool
868
+ * @param {Tool[]} tools - The fetched tools available to the provider
869
* @returns {ExecuteToolFn} The execute tool function
870
*/
859
- private createExecuteToolFn(userId: string, modifiers?: ExecuteToolModifiers): ExecuteToolFn {
871
+ private createExecuteToolFn(
872
+ userId: string,
873
+ modifiers: ExecuteToolModifiers | undefined,
874
+ tools: Tool[]
875
+ ): ExecuteToolFn {
876
+ const toolBySlug = new Map(tools.map(tool => [tool.slug.toUpperCase(), tool]));
877
const executeToolFn = async (toolSlug: string, input: Record<string, unknown>) => {
861
- return await this.execute(
862
- toolSlug,
863
- {
864
- userId,
865
- arguments: input,
866
- // dangerously skip version check for agentic tool execution via providers
867
- // this can be safe because most agentic flows users fetch latest version and then execute the tool
868
- dangerouslySkipVersionCheck: true,
869
- },
870
- modifiers
871
- );
878
+ const body: ToolExecuteParams = {
879
+ userId,
880
+ arguments: input,
881
+ // dangerously skip version check for agentic tool execution via providers
882
+ // this can be safe because most agentic flows users fetch latest version and then execute the tool
883
+ dangerouslySkipVersionCheck: true,
884
+ };
885
+ const tool = toolBySlug.get(toolSlug.toUpperCase());
886
+ return tool
887
+ ? this.executeWithTool(toolSlug, this.parseToolExecuteParams(body), modifiers, tool)
888
+ : this.execute(toolSlug, body, modifiers);
889
};
890
return executeToolFn;
891
}
@@ -961,6 +978,52 @@ export class Tools<
978
}
979
}
980
981
+ private async executeWithTool(
982
+ slug: string,
983
+ body: ToolExecuteParams,
984
+ options: (ExecuteToolModifiers & ComposioRequestOptions) | undefined,
985
+ tool: Tool
986
+ ): Promise<ToolExecuteResponse> {
987
+ const requestOptions: ComposioRequestOptions | undefined =
988
+ options?.signal != null ? { signal: options.signal } : undefined;
989
+ const { signal: _, ...modifiers } = options ?? {};
990
+ const toolkitSlug = tool.toolkit?.slug ?? 'unknown';
991
+
992
+ const params = await this.applyBeforeExecuteModifiers(
993
+ tool,
994
+ {
995
+ toolSlug: slug,
996
+ toolkitSlug,
997
+ params: body,
998
+ },
999
+ modifiers as ExecuteToolModifiers,
1000
+ requestOptions
1001
+ );
1002
+
1003
+ let result = await this.executeComposioTool(tool, params, requestOptions);
1004
+
1005
+ result = await this.applyAfterExecuteModifiers(
1006
+ tool,
1007
+ {
1008
+ toolSlug: slug,
1009
+ toolkitSlug,
1010
+ result,
1011
+ },
1012
+ (modifiers as ExecuteToolModifiers).afterExecute,
1013
+ requestOptions
1014
+ );
1015
+
1016
+ return result;
1017
+ }
1018
+
1019
+ private parseToolExecuteParams(body: ToolExecuteParams): ToolExecuteParams {
1020
+ const executeParams = ToolExecuteParamsSchema.safeParse(body);
1021
+ if (!executeParams.success) {
1022
+ throw new ValidationError('Invalid tool execute parameters', { cause: executeParams.error });
1023
+ }
1024
+ return executeParams.data;
1025
+ }
1026
+
1027
/**
1028
* Executes a given tool with the provided parameters.
1029
*
@@ -1046,51 +1109,19 @@ export class Tools<
1109
body: ToolExecuteParams,
1110
options?: ExecuteToolModifiers & ComposioRequestOptions
1111
): Promise<ToolExecuteResponse> {
1049
- const executeParams = ToolExecuteParamsSchema.safeParse(body);
1050
- if (!executeParams.success) {
1051
- throw new ValidationError('Invalid tool execute parameters', { cause: executeParams.error });
1052
- }
1112
+ const executeParams = this.parseToolExecuteParams(body);
1113
1114
const requestOptions: ComposioRequestOptions | undefined =
1115
options?.signal != null ? { signal: options.signal } : undefined;
1056
- const { signal: _, ...modifiers } = options ?? {};
1116
1117
const tool = await this.getRawComposioToolBySlug(
1118
slug,
1119
{
1061
- version: body.version,
1062
- },
1063
- requestOptions
1064
- );
1065
- const toolkitSlug = tool.toolkit?.slug ?? 'unknown';
1066
-
1067
- // Apply before execute modifiers
1068
- const params = await this.applyBeforeExecuteModifiers(
1069
- tool,
1070
- {
1071
- toolSlug: slug,
1072
- toolkitSlug,
1073
- params: executeParams.data,
1120
+ version: executeParams.version,
1121
},
1075
- modifiers as ExecuteToolModifiers,
1122
requestOptions
1123
);
1078
-
1079
- let result = await this.executeComposioTool(tool, params, requestOptions);
1080
-
1081
- // Apply after execute modifiers
1082
- result = await this.applyAfterExecuteModifiers(
1083
- tool,
1084
- {
1085
- toolSlug: slug,
1086
- toolkitSlug,
1087
- result,
1088
- },
1089
- (modifiers as ExecuteToolModifiers).afterExecute,
1090
- requestOptions
1091
- );
1092
-
1093
- return result;
1124
+ return this.executeWithTool(slug, executeParams, options, tool);
1125
}
1126
1127
/**
ts/packages/core/test/tools/modifiers.test.ts
+4
-12
@@ -241,22 +241,14 @@ describe('Tools Modifiers', () => {
241
});
242
243
// Verify schema modification
244
- expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(
245
- slug,
246
- {
247
- modifySchema: schemaModifier,
248
- },
249
- undefined
250
- );
251
- expect(mockTool.description).toBe('Enhanced GITHUB_GET_REPOS for better context');
252
- expect(mockTool.tags).toContain('enhanced');
253
- expect(mockTool.tags).toContain('modified');
254
- expect(mockTool.inputParameters).toHaveProperty(['properties', 'tracking']);
244
+ expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(slug, undefined, undefined);
245
+ expect(schemaModifier).toHaveBeenCalledOnce();
246
247
// Verify execution function creation
248
expect(createExecuteToolFnSpy).toHaveBeenCalledWith(
249
userId,
259
- expect.objectContaining(executionModifiers)
250
+ expect.objectContaining(executionModifiers),
251
+ expect.any(Array)
252
);
253
254
// Mock a tool execution to verify the full flow
ts/packages/core/test/tools/tools.test.ts
+138
-38
@@ -739,13 +739,7 @@ describe('Tools', () => {
739
740
const result = await context.tools.get(userId, slug);
741
742
- expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(
743
- slug,
744
- {
745
- modifySchema: undefined,
746
- },
747
- undefined
748
- );
742
+ expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(slug, undefined, undefined);
743
expect(context.mockProvider.wrapTools).toHaveBeenCalledWith(
744
[toolMocks.transformedTool],
745
expect.any(Function)
@@ -764,16 +758,12 @@ describe('Tools', () => {
758
759
const result = await context.tools.get(userId, filters);
760
767
- expect(getRawComposioToolsSpy).toHaveBeenCalledWith(
768
- filters,
769
- { modifySchema: undefined },
770
- undefined
771
- );
761
+ expect(getRawComposioToolsSpy).toHaveBeenCalledWith(filters, undefined, undefined);
762
expect(context.mockProvider.wrapTools).toHaveBeenCalled();
763
expect(result).toEqual('wrapped-tools-collection');
764
});
765
776
- it('should pass modifiers to the underlying methods', async () => {
766
+ it('should apply schema modifiers before wrapping tools for the provider', async () => {
767
const userId = 'test-user';
768
const slug = 'TOOL_SLUG';
769
const schemaModifier = createSchemaModifier({
@@ -787,14 +777,22 @@ describe('Tools', () => {
777
778
await context.tools.get(userId, slug, { modifySchema: schemaModifier });
779
790
- expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(
791
- slug,
792
- {
793
- modifySchema: schemaModifier,
794
- },
795
- undefined
780
+ expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(slug, undefined, undefined);
781
+ expect(schemaModifier).toHaveBeenCalledOnce();
782
+ expect(context.mockProvider.wrapTools).toHaveBeenCalledWith(
783
+ [expect.objectContaining({ description: 'Modified description' })],
784
+ expect.any(Function)
785
);
786
});
787
+
788
+ it('should reject an invalid schema modifier when no tools are returned', async () => {
789
+ const invalidModifier = 'not a function' as unknown;
790
+ vi.spyOn(context.tools, 'getRawComposioTools').mockResolvedValueOnce([]);
791
+
792
+ await expect(
793
+ context.tools.get('test-user', { toolkits: ['github'] }, { modifySchema: invalidModifier })
794
+ ).rejects.toThrow('Invalid schema modifier. Not a function.');
795
+ });
796
});
797
798
describe('execute', () => {
@@ -2374,38 +2372,33 @@ describe('Tools', () => {
2372
}
2373
});
2374
2377
- it('should allow agentic provider execution with dangerouslySkipVersionCheck in createExecuteToolFn', async () => {
2375
+ it('should reuse the fetched schema during agentic provider execution', async () => {
2376
const context = createTestContext();
2377
const userId = 'test-user';
2380
-
2381
- // Mock tool retrieval for the get method
2378
+ const toolSlug = 'GITHUB_CREATE_ISSUE';
2379
+ const fetchedTool = {
2380
+ ...toolMocks.transformedTool,
2381
+ slug: toolSlug,
2382
+ toolkit: { slug: 'github', name: 'GitHub' },
2383
+ } as unknown as Tool;
2384
const getRawComposioToolBySlugSpy = vi.spyOn(context.tools, 'getRawComposioToolBySlug');
2383
- getRawComposioToolBySlugSpy.mockResolvedValueOnce(
2384
- toolMocks.transformedTool as unknown as Tool
2385
- );
2385
+ getRawComposioToolBySlugSpy.mockResolvedValue(fetchedTool);
2386
2387
- // Mock provider wrapping
2387
let storedExecuteToolFn: ExecuteToolFn | undefined;
2388
context.mockProvider.wrapTools.mockImplementation((_tools, executeToolFn) => {
2389
storedExecuteToolFn = executeToolFn;
2390
return 'wrapped-tools-collection';
2391
});
2392
2394
- // Get the tool (this will internally create the execute tool function)
2395
- await context.tools.get(userId, 'GITHUB_CREATE_ISSUE');
2396
-
2397
- expect(storedExecuteToolFn).toBeDefined();
2398
-
2399
- // Setup mocks for the actual execution
2400
- const spies = await mockToolExecution(context.tools);
2401
-
2402
- // Call the execute function that was passed to the provider
2403
- // This should succeed because createExecuteToolFn sets dangerouslySkipVersionCheck: true
2404
- const result = await storedExecuteToolFn!('GITHUB_CREATE_ISSUE', { title: 'Test Issue' });
2393
+ await context.tools.get(userId, toolSlug);
2394
+ mockClient.tools.execute.mockResolvedValueOnce(toolMocks.rawToolExecuteResponse);
2395
+ const result = await storedExecuteToolFn!(toolSlug, { title: 'Test Issue' });
2396
2397
expect(result).toEqual(toolMocks.toolExecuteResponse);
2398
+ expect(getRawComposioToolBySlugSpy).toHaveBeenCalledTimes(1);
2399
+ expect(mockClient.tools.retrieve).not.toHaveBeenCalled();
2400
expect(mockClient.tools.execute).toHaveBeenCalledWith(
2408
- 'COMPOSIO_TOOL',
2401
+ toolSlug,
2402
{
2403
allow_tracing: undefined,
2404
connected_account_id: undefined,
@@ -2419,6 +2412,113 @@ describe('Tools', () => {
2412
undefined
2413
);
2414
});
2415
+
2416
+ it('should reject invalid agentic provider input before execution', async () => {
2417
+ const context = createTestContext();
2418
+ const toolSlug = 'GITHUB_CREATE_ISSUE';
2419
+ const fetchedTool = {
2420
+ ...toolMocks.transformedTool,
2421
+ slug: toolSlug,
2422
+ toolkit: { slug: 'github', name: 'GitHub' },
2423
+ } as unknown as Tool;
2424
+ const getRawComposioToolBySlugSpy = vi.spyOn(context.tools, 'getRawComposioToolBySlug');
2425
+ getRawComposioToolBySlugSpy.mockResolvedValue(fetchedTool);
2426
+ let storedExecuteToolFn: ExecuteToolFn | undefined;
2427
+
2428
+ context.mockProvider.wrapTools.mockImplementation((_tools, executeToolFn) => {
2429
+ storedExecuteToolFn = executeToolFn;
2430
+ return 'wrapped-tools-collection';
2431
+ });
2432
+
2433
+ await context.tools.get('test-user', toolSlug);
2434
+
2435
+ await expect(
2436
+ storedExecuteToolFn!(toolSlug, 42 as unknown as Record<string, unknown>)
2437
+ ).rejects.toThrow(ValidationError);
2438
+ expect(getRawComposioToolBySlugSpy).toHaveBeenCalledTimes(1);
2439
+ expect(mockClient.tools.execute).not.toHaveBeenCalled();
2440
+ });
2441
+
2442
+ it('should retrieve an unknown provider tool before execution', async () => {
2443
+ const context = createTestContext();
2444
+ const userId = 'test-user';
2445
+ const fetchedToolSlug = 'GITHUB_CREATE_ISSUE';
2446
+ const unknownToolSlug = 'GITHUB_GET_ISSUE';
2447
+ const fetchedTool = {
2448
+ ...toolMocks.transformedTool,
2449
+ slug: fetchedToolSlug,
2450
+ toolkit: { slug: 'github', name: 'GitHub' },
2451
+ } as unknown as Tool;
2452
+ const unknownTool = { ...fetchedTool, slug: unknownToolSlug };
2453
+ const getRawComposioToolBySlugSpy = vi.spyOn(context.tools, 'getRawComposioToolBySlug');
2454
+ getRawComposioToolBySlugSpy
2455
+ .mockResolvedValueOnce(fetchedTool)
2456
+ .mockResolvedValueOnce(unknownTool);
2457
+ let storedExecuteToolFn: ExecuteToolFn | undefined;
2458
+
2459
+ context.mockProvider.wrapTools.mockImplementation((_tools, executeToolFn) => {
2460
+ storedExecuteToolFn = executeToolFn;
2461
+ return 'wrapped-tools-collection';
2462
+ });
2463
+
2464
+ await context.tools.get(userId, fetchedToolSlug);
2465
+ mockClient.tools.execute.mockResolvedValueOnce(toolMocks.rawToolExecuteResponse);
2466
+ await storedExecuteToolFn!(unknownToolSlug, {});
2467
+
2468
+ expect(getRawComposioToolBySlugSpy).toHaveBeenCalledTimes(2);
2469
+ expect(getRawComposioToolBySlugSpy).toHaveBeenNthCalledWith(
2470
+ 2,
2471
+ unknownToolSlug,
2472
+ { version: undefined },
2473
+ undefined
2474
+ );
2475
+ expect(mockClient.tools.execute).toHaveBeenCalledWith(
2476
+ unknownToolSlug,
2477
+ expect.objectContaining({ user_id: userId, version: 'latest' }),
2478
+ undefined
2479
+ );
2480
+ });
2481
+
2482
+ it('should preserve execution metadata when modifySchema mutates the fetched tool', async () => {
2483
+ const mockProvider = new MockProvider();
2484
+ const tools = new Tools(mockClient, {
2485
+ provider: mockProvider,
2486
+ toolkitVersions: { 'test-toolkit': '20250101_00' },
2487
+ });
2488
+ const userId = 'test-user';
2489
+ const toolSlug = 'GITHUB_CREATE_ISSUE';
2490
+ const rawTool = {
2491
+ ...toolMocks.rawTool,
2492
+ slug: toolSlug,
2493
+ toolkit: { slug: 'test-toolkit', name: 'Test Toolkit' },
2494
+ };
2495
+ let wrappedTools: Tool[] | undefined;
2496
+ let storedExecuteToolFn: ExecuteToolFn | undefined;
2497
+
2498
+ mockClient.tools.retrieve.mockReset().mockResolvedValueOnce(rawTool);
2499
+ mockProvider.wrapTools.mockImplementation((toolsToWrap, executeToolFn) => {
2500
+ wrappedTools = toolsToWrap;
2501
+ storedExecuteToolFn = executeToolFn;
2502
+ return 'wrapped-tools';
2503
+ });
2504
+
2505
+ await tools.get(userId, toolSlug, {
2506
+ modifySchema: ({ schema }) => {
2507
+ schema.toolkit = { slug: 'renamed-toolkit', name: 'Renamed Toolkit' };
2508
+ return schema;
2509
+ },
2510
+ });
2511
+ mockClient.tools.execute.mockResolvedValueOnce(toolMocks.rawToolExecuteResponse);
2512
+ await storedExecuteToolFn!(toolSlug, {});
2513
+
2514
+ expect(wrappedTools?.[0].toolkit?.slug).toBe('renamed-toolkit');
2515
+ expect(mockClient.tools.retrieve).toHaveBeenCalledTimes(1);
2516
+ expect(mockClient.tools.execute).toHaveBeenCalledWith(
2517
+ toolSlug,
2518
+ expect.objectContaining({ version: '20250101_00' }),
2519
+ undefined
2520
+ );
2521
+ });
2522
});
2523
});
2524
});