Skip to content

Commit 60f5d67

Browse files
committed
fix: disable strict mode for MCP tools to preserve optional parameters
MCP tools (like Linear's MCP server) have optional parameters that were broken by OpenAI's strict mode which requires ALL properties to be in the required array. This change: - Checks if tool name starts with 'mcp--' prefix - Sets strict: false for MCP tools - Preserves original schema without forcing all properties to required Fixes ROO-241
1 parent f7adc4b commit 60f5d67

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

src/api/providers/base-provider.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,26 @@ export abstract class BaseProvider implements ApiHandler {
2828
return undefined
2929
}
3030

31-
return tools.map((tool) =>
32-
tool.type === "function"
33-
? {
34-
...tool,
35-
function: {
36-
...tool.function,
37-
strict: true,
38-
parameters: this.convertToolSchemaForOpenAI(tool.function.parameters),
39-
},
40-
}
41-
: tool,
42-
)
31+
return tools.map((tool) => {
32+
if (tool.type !== "function") {
33+
return tool
34+
}
35+
36+
// MCP tools use the 'mcp--' prefix - disable strict mode for them
37+
// to preserve optional parameters from the MCP server schema
38+
const isMcpTool = tool.function.name.startsWith("mcp--")
39+
40+
return {
41+
...tool,
42+
function: {
43+
...tool.function,
44+
strict: !isMcpTool,
45+
parameters: isMcpTool
46+
? tool.function.parameters
47+
: this.convertToolSchemaForOpenAI(tool.function.parameters),
48+
},
49+
}
50+
})
4351
}
4452

4553
/**

src/api/providers/openai-native.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,20 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
291291
...(metadata?.tools && {
292292
tools: metadata.tools
293293
.filter((tool) => tool.type === "function")
294-
.map((tool) => ({
295-
type: "function",
296-
name: tool.function.name,
297-
description: tool.function.description,
298-
parameters: ensureAllRequired(tool.function.parameters),
299-
strict: true,
300-
})),
294+
.map((tool) => {
295+
// MCP tools use the 'mcp--' prefix - disable strict mode for them
296+
// to preserve optional parameters from the MCP server schema
297+
const isMcpTool = tool.function.name.startsWith("mcp--")
298+
return {
299+
type: "function",
300+
name: tool.function.name,
301+
description: tool.function.description,
302+
parameters: isMcpTool
303+
? tool.function.parameters
304+
: ensureAllRequired(tool.function.parameters),
305+
strict: !isMcpTool,
306+
}
307+
}),
301308
}),
302309
...(metadata?.tool_choice && { tool_choice: metadata.tool_choice }),
303310
}

0 commit comments

Comments
 (0)