@devries-cameron20 / composio-1 / commits / 71255765a
Fork 0

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(schema): normalize duplicate required entries (#3812)

## Summary - Normalize duplicate JSON Schema `required` entries at the shared `ToolSchema` ingress boundary. - Reapply normalization immediately before direct providers emit vendor schemas (Anthropic, OpenAI, OpenAI Responses, Google, Cloudflare, and OpenAI Agents). - Preserve literal `const`/`default`/`enum`/`examples` values, tolerate aliasing safely, and fail predictably on pathological nesting. - Document the provider-boundary rule in `ts/packages/providers/AGENTS.md`. Co-authored-by: @MatinGathani ## Verification - `pnpm changeset status` - `pnpm --filter @composio/core build` - Focused core and affected-provider Vitest suites (1,151 tests) - `pnpm typecheck` - `pnpm lint` (passes with 71 pre-existing warnings) --------- Co-authored-by: MatinGathani <70268627+matingathani@users.noreply.github.com>

Alberto Schiabel committed Jul 13, 2026 at 15:03 UTC 71255765a5ca2bdfb75c828c51e3fe102309bbee
19 files changed +375 -47
.changeset/bright-ants-wink.md new
+10
@@ -0,0 +1,10 @@
1 +---
2 +'@composio/anthropic': patch
3 +'@composio/core': patch
4 +'@composio/openai': patch
5 +'@composio/google': patch
6 +'@composio/cloudflare': patch
7 +'@composio/openai-agents': patch
8 +---
9 +
10 +Normalize duplicate JSON Schema `required` entries before provider tool schemas are emitted.
ts/packages/core/src/index.ts
+1
@@ -6,6 +6,7 @@ export { BaseNonAgenticProvider, BaseAgenticProvider } from './provider/BaseProv
6 export type { BaseComposioProvider } from './provider/BaseProvider';
7 export {
8 dereferenceJsonSchema,
9 + deduplicateJsonSchemaRequiredArrays,
10 jsonSchemaToZodSchema,
11 removeNonRequiredProperties,
12 } from './utils/jsonSchema';
ts/packages/core/src/provider/OpenAIProvider.ts
+2 -1
@@ -16,6 +16,7 @@ import { ExecuteToolModifiers } from '../types/modifiers.types';
16 import { ExecuteToolFnOptions } from '../types/provider.types';
17 import { McpUrlResponse, McpServerGetResponse } from '../types/mcp.types';
18 import { normalizeToolArguments } from '../utils/toolArguments';
19 +import { deduplicateJsonSchemaRequiredArrays } from '../utils/jsonSchema';
20
21 export type OpenAiTool = OpenAI.ChatCompletionTool;
22 export type OpenAiToolCollection = Array<OpenAiTool>;
@@ -96,7 +97,7 @@ export class OpenAIProvider extends BaseNonAgenticProvider<
97 const formattedSchema: OpenAI.FunctionDefinition = {
98 name: tool.slug,
99 description: tool.description,
99 - parameters: tool.inputParameters,
100 + parameters: deduplicateJsonSchemaRequiredArrays(tool.inputParameters),
101 };
102 return {
103 type: 'function',
ts/packages/core/src/types/tool.types.ts
+36 -32
@@ -1,6 +1,7 @@
1 import { z } from 'zod/v3';
2 import { CustomConnectionDataSchema } from './connectedAccountAuthStates.types';
3 import { TransformToolSchemaModifier } from './modifiers.types';
4 +import { deduplicateJsonSchemaRequiredArrays } from '../utils/jsonSchema';
5
6 /**
7 * Toolkit is the collection of tools,
@@ -86,38 +87,41 @@ export const JSONSchemaPropertySchema: z.ZodType<any> = z.object({
87 export type JSONSchemaProperty = z.infer<typeof JSONSchemaPropertySchema>;
88
89 // Schema for parameters (input/output)
89 -const ParametersSchema = z.object({
90 - type: z.literal('object'),
91 - anyOf: z.array(JSONSchemaPropertySchema).optional(),
92 - oneOf: z.array(JSONSchemaPropertySchema).optional(),
93 - allOf: z.array(JSONSchemaPropertySchema).optional(),
94 - not: JSONSchemaPropertySchema.optional(),
95 - properties: z.record(z.string(), JSONSchemaPropertySchema),
96 - required: z.array(z.string()).optional(),
97 - title: z.string().optional(),
98 - default: z.any().optional(),
99 - nullable: z.boolean().optional(),
100 - description: z.string().optional(),
101 - additionalProperties: z.boolean().default(false).optional(),
102 - // Definition blocks targeted by `$ref` pointers. The Composio API ships
103 - // these at the parameters root (e.g. `data` → `$ref` → `#/$defs/...`), but
104 - // because `z.object` strips unknown keys they were being dropped on parse —
105 - // leaving every nested `$ref` dangling and unresolvable downstream
106 - // (providers, file modifiers). `JSONSchemaPropertySchema` already accepts
107 - // both keywords; the parameters root must too.
108 - $defs: z
109 - .record(
110 - z.string(),
111 - z.lazy(() => JSONSchemaPropertySchema)
112 - )
113 - .optional(),
114 - definitions: z
115 - .record(
116 - z.string(),
117 - z.lazy(() => JSONSchemaPropertySchema)
118 - )
119 - .optional(),
120 -});
90 +const ParametersSchema = z.preprocess(
91 + deduplicateJsonSchemaRequiredArrays,
92 + z.object({
93 + type: z.literal('object'),
94 + anyOf: z.array(JSONSchemaPropertySchema).optional(),
95 + oneOf: z.array(JSONSchemaPropertySchema).optional(),
96 + allOf: z.array(JSONSchemaPropertySchema).optional(),
97 + not: JSONSchemaPropertySchema.optional(),
98 + properties: z.record(z.string(), JSONSchemaPropertySchema),
99 + required: z.array(z.string()).optional(),
100 + title: z.string().optional(),
101 + default: z.any().optional(),
102 + nullable: z.boolean().optional(),
103 + description: z.string().optional(),
104 + additionalProperties: z.boolean().default(false).optional(),
105 + // Definition blocks targeted by `$ref` pointers. The Composio API ships
106 + // these at the parameters root (e.g. `data` → `$ref` → `#/$defs/...`), but
107 + // because `z.object` strips unknown keys they were being dropped on parse —
108 + // leaving every nested `$ref` dangling and unresolvable downstream
109 + // (providers, file modifiers). `JSONSchemaPropertySchema` already accepts
110 + // both keywords; the parameters root must too.
111 + $defs: z
112 + .record(
113 + z.string(),
114 + z.lazy(() => JSONSchemaPropertySchema)
115 + )
116 + .optional(),
117 + definitions: z
118 + .record(
119 + z.string(),
120 + z.lazy(() => JSONSchemaPropertySchema)
121 + )
122 + .optional(),
123 + })
124 +);
125
126 /**
127 * Tool is a single action that can be performed by a toolkit.
ts/packages/core/src/utils/jsonSchema.ts
+58
@@ -258,6 +258,64 @@ export function dereferenceJsonSchema<T = unknown>(
258 return out as T;
259 }
260
261 +/**
262 + * Returns a deep-cloned JSON Schema whose `required` arrays contain each entry
263 + * at most once. Duplicate entries are invalid in JSON Schema 2020-12 but do
264 + * not change the schema's meaning, so preserving the first occurrence is safe.
265 + *
266 + * Tool schemas originate both from the Composio API and direct provider calls.
267 + * Keeping this normalization provider-agnostic lets every SDK provider receive
268 + * canonical API schemas, while providers that further transform a schema can
269 + * reapply it at their own emission boundary.
270 + */
271 +export function deduplicateJsonSchemaRequiredArrays<T = unknown>(schema: T): T {
272 + const seenSchemaValues = new WeakMap<object, unknown>();
273 + const seenInstanceValues = new WeakMap<object, unknown>();
274 + const instanceValueKeywords = new Set(['const', 'default', 'enum', 'examples']);
275 +
276 + function walk(value: unknown, isSchema: boolean, depth = 0): unknown {
277 + if (depth > MAX_NODE_DEPTH) {
278 + throw new RangeError(`JSON Schema exceeds maximum nesting depth of ${MAX_NODE_DEPTH}`);
279 + }
280 +
281 + const seen = isSchema ? seenSchemaValues : seenInstanceValues;
282 +
283 + if (Array.isArray(value)) {
284 + const existing = seen.get(value);
285 + if (existing) return existing;
286 +
287 + const clone: unknown[] = [];
288 + seen.set(value, clone);
289 + for (const item of value) {
290 + clone.push(walk(item, isSchema, depth + 1));
291 + }
292 + return clone;
293 + }
294 +
295 + if (!isPlainObject(value)) return value;
296 +
297 + const existing = seen.get(value);
298 + if (existing) return existing;
299 +
300 + const clone: Record<string, unknown> = {};
301 + seen.set(value, clone);
302 + for (const [key, child] of Object.entries(value)) {
303 + Object.defineProperty(clone, key, {
304 + configurable: true,
305 + enumerable: true,
306 + value:
307 + isSchema && key === 'required' && Array.isArray(child)
308 + ? [...new Set(walk(child, false, depth + 1) as unknown[])]
309 + : walk(child, isSchema && !instanceValueKeywords.has(key), depth + 1),
310 + writable: true,
311 + });
312 + }
313 + return clone;
314 + }
315 +
316 + return walk(schema, true) as T;
317 +}
318 +
319 /**
320 * Removes all non-required properties from the schema
321 *
ts/packages/core/test/provider/openai-provider.test.ts
+29
@@ -64,6 +64,35 @@ describe('OpenAIProvider', () => {
64 },
65 });
66 });
67 +
68 + it('deduplicates required entries without mutating the input schema', () => {
69 + const tool = {
70 + ...mockTool,
71 + inputParameters: {
72 + type: 'object',
73 + properties: {
74 + query: { type: 'string' },
75 + filters: {
76 + type: 'object',
77 + properties: { status: { type: 'string' } },
78 + required: ['status', 'status'],
79 + },
80 + },
81 + required: ['query', 'query'],
82 + },
83 + } as Tool;
84 +
85 + const wrapped = provider.wrapTool(tool);
86 +
87 + expect(wrapped.function.parameters).toMatchObject({
88 + required: ['query'],
89 + properties: { filters: { required: ['status'] } },
90 + });
91 + expect(tool.inputParameters).toMatchObject({
92 + required: ['query', 'query'],
93 + properties: { filters: { required: ['status', 'status'] } },
94 + });
95 + });
96 });
97
98 describe('wrapTools', () => {
ts/packages/core/test/utils/jsonSchema.test.ts
+112 -1
@@ -1,7 +1,11 @@
1 import { describe, it, expect, vi } from 'vitest';
2 -import { dereferenceJsonSchema } from '../../src/utils/jsonSchema';
2 +import {
3 + deduplicateJsonSchemaRequiredArrays,
4 + dereferenceJsonSchema,
5 +} from '../../src/utils/jsonSchema';
6 import { JsonSchemaRefResolutionError } from '../../src/errors/ValidationErrors';
7 import logger from '../../src/utils/logger';
8 +import { ToolSchema } from '../../src/types/tool.types';
9
10 const containsRef = (value: unknown): boolean => {
11 if (value === null || typeof value !== 'object') return false;
@@ -484,3 +488,110 @@ describe('dereferenceJsonSchema', () => {
488 });
489 });
490 });
491 +
492 +describe('deduplicateJsonSchemaRequiredArrays', () => {
493 + it('deduplicates every required array without mutating the input schema', () => {
494 + const schema = {
495 + type: 'object',
496 + required: ['owner', 'name', 'owner'],
497 + properties: {
498 + options: {
499 + type: 'object',
500 + required: ['enabled', 'enabled'],
501 + properties: { enabled: { type: 'boolean' } },
502 + },
503 + },
504 + };
505 +
506 + const normalized = deduplicateJsonSchemaRequiredArrays(schema);
507 +
508 + expect(normalized).toEqual({
509 + type: 'object',
510 + required: ['owner', 'name'],
511 + properties: {
512 + options: {
513 + type: 'object',
514 + required: ['enabled'],
515 + properties: { enabled: { type: 'boolean' } },
516 + },
517 + },
518 + });
519 + expect(schema.required).toEqual(['owner', 'name', 'owner']);
520 + expect(schema.properties.options.required).toEqual(['enabled', 'enabled']);
521 + });
522 +
523 + it('does not normalize literal instance values', () => {
524 + const sharedValue = {
525 + type: 'object',
526 + required: ['preserve', 'preserve'],
527 + properties: { preserve: { type: 'string' } },
528 + };
529 + const schema = {
530 + type: 'object',
531 + required: ['value', 'value'],
532 + properties: {
533 + schemaValue: sharedValue,
534 + value: {
535 + const: sharedValue,
536 + default: { required: ['preserve', 'preserve'] },
537 + enum: [{ required: ['preserve', 'preserve'] }],
538 + examples: [{ required: ['preserve', 'preserve'] }],
539 + },
540 + },
541 + };
542 +
543 + const normalized = deduplicateJsonSchemaRequiredArrays(schema);
544 +
545 + expect(normalized).toMatchObject({
546 + required: ['value'],
547 + properties: {
548 + schemaValue: { required: ['preserve'] },
549 + value: {
550 + const: { required: ['preserve', 'preserve'] },
551 + default: { required: ['preserve', 'preserve'] },
552 + enum: [{ required: ['preserve', 'preserve'] }],
553 + examples: [{ required: ['preserve', 'preserve'] }],
554 + },
555 + },
556 + });
557 + expect(normalized.properties.value.const).not.toBe(schema.properties.value.const);
558 + });
559 +
560 + it('fails predictably for schemas nested beyond the supported depth', () => {
561 + const defaultValue: Record<string, unknown> = {};
562 + let cursor = defaultValue;
563 + for (let i = 0; i <= 512; i++) {
564 + cursor.child = {};
565 + cursor = cursor.child as Record<string, unknown>;
566 + }
567 +
568 + expect(() =>
569 + deduplicateJsonSchemaRequiredArrays({
570 + type: 'object',
571 + properties: { value: { default: defaultValue } },
572 + })
573 + ).toThrow('JSON Schema exceeds maximum nesting depth of 512');
574 + });
575 +
576 + it('normalizes schemas at the shared ToolSchema API boundary', () => {
577 + const tool = ToolSchema.parse({
578 + slug: 'TEST_TOOL',
579 + name: 'Test tool',
580 + inputParameters: {
581 + type: 'object',
582 + required: ['name', 'name'],
583 + properties: {
584 + name: { type: 'string' },
585 + options: {
586 + type: 'object',
587 + required: ['enabled', 'enabled'],
588 + properties: { enabled: { type: 'boolean' } },
589 + },
590 + },
591 + },
592 + });
593 +
594 + expect(tool.inputParameters?.required).toEqual(['name']);
595 + expect(tool.inputParameters?.properties.options.required).toEqual(['enabled']);
596 + });
597 +});
ts/packages/providers/AGENTS.md
+1
@@ -25,5 +25,6 @@ pnpm build:packages
25
26 - Keep provider-specific behavior inside the provider package.
27 - Preserve framework-native tool shapes and naming conventions.
28 +- Tool schemas obtained through `ToolSchema` are normalized by core. Every provider that accepts a raw `Tool` must call `deduplicateJsonSchemaRequiredArrays` from `@composio/core` immediately before emitting a vendor JSON Schema, after any provider-specific schema transformations. A ToolSchema-normalized API tool needs no additional call unless it is transformed afterward.
29 - Add tests that cover wrapping, execution handling, and version-specific compatibility.
30 - Update examples or docs when provider setup or public usage changes.
ts/packages/providers/anthropic/src/index.ts
+8 -6
@@ -17,6 +17,7 @@ import {
17 McpUrlResponse,
18 normalizeToolArguments,
19 dereferenceJsonSchema,
20 + deduplicateJsonSchemaRequiredArrays,
21 } from '@composio/core';
22 import Anthropic from '@anthropic-ai/sdk';
23 import { AnthropicTool, InputSchema } from './types';
@@ -65,7 +66,7 @@ export class AnthropicProvider extends BaseNonAgenticProvider<
66 AnthropicMcpServerGetResponse
67 > {
68 readonly name = 'anthropic';
68 - private chacheTools: boolean = false;
69 + private cacheTools: boolean = false;
70
71 /**
72 * Per-tool reverse key mappings (`sanitized -> original`, shaped like the
@@ -117,8 +118,8 @@ export class AnthropicProvider extends BaseNonAgenticProvider<
118 */
119 constructor(options?: { cacheTools?: boolean }) {
120 super();
120 - this.chacheTools = options?.cacheTools ?? false;
121 - logger.debug(`AnthropicProvider initialized [cacheTools: ${this.chacheTools}]`);
121 + this.cacheTools = options?.cacheTools ?? false;
122 + logger.debug(`AnthropicProvider initialized [cacheTools: ${this.cacheTools}]`);
123 }
124
125 /**
@@ -171,7 +172,8 @@ export class AnthropicProvider extends BaseNonAgenticProvider<
172 // Anthropic rejects the whole `tools` array if any property key falls outside
173 // `^[a-zA-Z0-9_.-]{1,64}$` (e.g. OData params like `$top`, `@odata.type`, or
174 // over-long flattened keys). Rewrite offending keys and remember how to undo it.
174 - const { schema, mapping } = sanitizeSchemaPropertyKeys(dereferenced);
175 + const { schema: sanitizedSchema, mapping } = sanitizeSchemaPropertyKeys(dereferenced);
176 + const schema = deduplicateJsonSchemaRequiredArrays(sanitizedSchema) as InputSchema;
177
178 if (mappingHasRenames(mapping)) {
179 this.toolKeyMappings.set(tool.slug, mapping);
@@ -189,7 +191,7 @@ export class AnthropicProvider extends BaseNonAgenticProvider<
191 name: tool.slug,
192 description: tool.description || '',
193 input_schema: schema,
192 - cache_control: this.chacheTools ? { type: 'ephemeral' } : undefined,
194 + cache_control: this.cacheTools ? { type: 'ephemeral' } : undefined,
195 };
196 }
197
@@ -377,7 +379,7 @@ export class AnthropicProvider extends BaseNonAgenticProvider<
379 type: 'tool_result',
380 tool_use_id: toolUse.id,
381 content: toolResult,
380 - cache_control: this.chacheTools ? { type: 'ephemeral' } : undefined,
382 + cache_control: this.cacheTools ? { type: 'ephemeral' } : undefined,
383 });
384 }
385
ts/packages/providers/anthropic/test/anthropic.test.ts
+31
@@ -105,6 +105,37 @@ describe('AnthropicProvider', () => {
105 },
106 });
107 });
108 +
109 + it('deduplicates required entries at every object-schema level', () => {
110 + const toolWithDuplicateRequired: Tool = {
111 + ...mockTool,
112 + inputParameters: {
113 + type: 'object',
114 + properties: {
115 + owner: { type: 'string' },
116 + options: {
117 + type: 'object',
118 + properties: {
119 + name: { type: 'string' },
120 + },
121 + required: ['name', 'name'],
122 + },
123 + },
124 + required: ['owner', 'options', 'owner'],
125 + },
126 + };
127 +
128 + const wrapped = provider.wrapTool(toolWithDuplicateRequired) as AnthropicTool;
129 + const properties = wrapped.input_schema.properties as Record<
130 + string,
131 + {
132 + required?: string[];
133 + }
134 + >;
135 +
136 + expect(wrapped.input_schema.required).toEqual(['owner', 'options']);
137 + expect(properties.options?.required).toEqual(['name']);
138 + });
139 });
140
141 describe('wrapTools', () => {
ts/packages/providers/cloudflare/src/index.ts
+3 -1
@@ -19,6 +19,7 @@ import {
19 McpUrlResponse,
20 McpServerGetResponse,
21 normalizeToolArguments,
22 + deduplicateJsonSchemaRequiredArrays,
23 } from '@composio/core';
24
25 type AiToolCollection = Record<string, AiTextGenerationToolInput>;
@@ -97,10 +98,11 @@ export class CloudflareProvider extends BaseNonAgenticProvider<
98 * ```
99 */
100 wrapTool(tool: Tool): AiTextGenerationToolInput {
101 + const inputParameters = deduplicateJsonSchemaRequiredArrays(tool.inputParameters);
102 const formattedSchema: AiTextGenerationToolInput['function'] = {
103 name: tool.slug!,
104 description: tool.description!,
103 - parameters: tool.inputParameters as unknown as {
105 + parameters: inputParameters as unknown as {
106 type: 'object';
107 properties: {
108 [key: string]: {
ts/packages/providers/cloudflare/test/cloudflare.test.ts
+12
@@ -124,6 +124,18 @@ describe('CloudflareProvider', () => {
124 },
125 });
126 });
127 +
128 + it('deduplicates required entries for directly wrapped tools', () => {
129 + const wrapped = provider.wrapTool({
130 + ...mockTool,
131 + inputParameters: {
132 + ...mockTool.inputParameters!,
133 + required: ['input', 'input'],
134 + },
135 + }) as MockedCloudflareToolInput;
136 +
137 + expect(wrapped.function.parameters.required).toEqual(['input']);
138 + });
139 });
140
141 describe('wrapTools', () => {
ts/packages/providers/google/src/index.ts
+5 -2
@@ -16,6 +16,7 @@ import {
16 McpUrlResponse,
17 McpServerGetResponse,
18 normalizeToolArguments,
19 + deduplicateJsonSchemaRequiredArrays,
20 } from '@composio/core';
21 import { FunctionDeclaration, Schema } from '@google/genai';
22
@@ -127,14 +128,16 @@ export class GoogleProvider extends BaseNonAgenticProvider<
128 * ```
129 */
130 wrapTool(tool: Tool): GoogleTool {
131 + const inputParameters = deduplicateJsonSchemaRequiredArrays(tool.inputParameters);
132 +
133 return {
134 name: tool.slug,
135 description: tool.description || '',
136 parameters: {
137 type: 'object',
138 description: tool.description || '',
136 - properties: tool.inputParameters?.properties || {},
137 - required: tool.inputParameters?.required || [],
139 + properties: inputParameters?.properties || {},
140 + required: inputParameters?.required || [],
141 } as unknown as Schema,
142 };
143 }
ts/packages/providers/google/test/google.test.ts
+12
@@ -84,6 +84,18 @@ describe('GoogleProvider', () => {
84 },
85 });
86 });
87 +
88 + it('deduplicates required entries for directly wrapped tools', () => {
89 + const wrapped = provider.wrapTool({
90 + ...mockTool,
91 + inputParameters: {
92 + ...mockTool.inputParameters!,
93 + required: ['input', 'input'],
94 + },
95 + });
96 +
97 + expect(wrapped.parameters?.required).toEqual(['input']);
98 + });
99 });
100
101 describe('wrapTools', () => {
ts/packages/providers/openai-agents/src/index.ts
+5 -2
@@ -17,6 +17,7 @@ import {
17 McpUrlResponse,
18 McpServerGetResponse,
19 normalizeToolArguments,
20 + deduplicateJsonSchemaRequiredArrays,
21 } from '@composio/core';
22 import type { Tool as OpenAIAgentTool } from '@openai/agents';
23 import { tool as createOpenAIAgentTool } from '@openai/agents';
@@ -122,13 +123,15 @@ export class OpenAIAgentsProvider extends BaseAgenticProvider<
123 * ```
124 */
125 wrapTool(composioTool: ComposioTool, executeTool: ExecuteToolFn): OpenAIAgentTool {
126 + const inputParameters = deduplicateJsonSchemaRequiredArrays(composioTool.inputParameters);
127 +
128 return createOpenAIAgentTool({
129 name: composioTool.slug,
130 description: composioTool.description ?? '',
131 parameters: {
132 type: 'object',
130 - properties: composioTool.inputParameters?.properties || {},
131 - required: composioTool.inputParameters?.required || [],
133 + properties: inputParameters?.properties || {},
134 + required: inputParameters?.required || [],
135 additionalProperties: true,
136 },
137 strict: false,
ts/packages/providers/openai-agents/test/openai-agents.test.ts
+19
@@ -113,6 +113,25 @@ describe('OpenAIAgentsProvider', () => {
113 expect(wrapped._isMockedOpenAIAgentTool).toBe(true);
114 });
115
116 + it('deduplicates required entries for directly wrapped tools', () => {
117 + provider.wrapTool(
118 + {
119 + ...mockTool,
120 + inputParameters: {
121 + ...mockTool.inputParameters!,
122 + required: ['input', 'input'],
123 + },
124 + },
125 + mockExecuteToolFn
126 + );
127 +
128 + expect(createOpenAIAgentTool).toHaveBeenCalledWith(
129 + expect.objectContaining({
130 + parameters: expect.objectContaining({ required: ['input'] }),
131 + })
132 + );
133 + });
134 +
135 it('should normalize a stringified-JSON input to an object before executing (issue #2406)', async () => {
136 const wrapped = provider.wrapTool(
137 mockTool,
ts/packages/providers/openai/src/OpenAIResponsesProvider.ts
+2 -1
@@ -19,6 +19,7 @@ import {
19 removeNonRequiredProperties,
20 McpUrlResponse,
21 normalizeToolArguments,
22 + deduplicateJsonSchemaRequiredArrays,
23 } from '@composio/core';
24
25 export type OpenAiTool = OpenAI.Responses.FunctionTool;
@@ -119,7 +120,7 @@ export class OpenAIResponsesProvider extends BaseNonAgenticProvider<
120 * ```
121 */
122 override wrapTool(tool: Tool): OpenAiTool {
122 - const inputParams = tool.inputParameters;
123 + const inputParams = deduplicateJsonSchemaRequiredArrays(tool.inputParameters);
124
125 const parameters =
126 this.strict && inputParams?.type === 'object'
ts/packages/providers/openai/test/opeanai-responses.test.ts
+17 -1
@@ -111,7 +111,23 @@ describe('OpenAIResponsesProvider', () => {
111 const wrapped = strictProvider.wrapTool(mockTool) as MockedOpenAITool;
112
113 expect(wrapped.strict).toBe(true);
114 - expect(wrapped.parameters).toEqual(mockTool.inputParameters);
114 + expect(wrapped.parameters).toEqual({
115 + ...mockTool.inputParameters,
116 + additionalProperties: false,
117 + });
118 + expect(mockTool.inputParameters).not.toHaveProperty('additionalProperties');
119 + });
120 +
121 + it('deduplicates required entries for directly wrapped tools', () => {
122 + const wrapped = provider.wrapTool({
123 + ...mockTool,
124 + inputParameters: {
125 + ...mockTool.inputParameters!,
126 + required: ['input', 'input'],
127 + },
128 + }) as MockedOpenAITool;
129 +
130 + expect(wrapped.parameters.required).toEqual(['input']);
131 });
132 });
133
ts/packages/providers/openai/test/openai.test.ts
+12
@@ -122,6 +122,18 @@ describe('OpenAIProvider', () => {
122 },
123 });
124 });
125 +
126 + it('deduplicates required entries for directly wrapped tools', () => {
127 + const wrapped = provider.wrapTool({
128 + ...mockTool,
129 + inputParameters: {
130 + ...mockTool.inputParameters!,
131 + required: ['input', 'input'],
132 + },
133 + }) as MockedOpenAIChatCompletionTool;
134 +
135 + expect(wrapped.function.parameters.required).toEqual(['input']);
136 + });
137 });
138
139 describe('wrapTools', () => {